> constraints = new LinkedHashSet<>();
/**
- * Creates an empty {@link AutocompleteDataSet}.
+ * Creates an empty {@link AutocompleteItemSet}.
*/
- public AutocompleteDataSet() {
+ public AutocompleteItemSet() {
super();
}
/**
- * Creates a {@link AutocompleteDataSet} with the given elements and constraints.
+ * Creates a {@link AutocompleteItemSet} with the given elements and constraints.
*
*
* This is mainly useful if your rules are complex. Otherwise, the convenience factory
@@ -56,7 +56,7 @@ public AutocompleteDataSet() {
* @see #oneAmongAllOf
* @see #anyNumberOf
*/
- private AutocompleteDataSet(
+ private AutocompleteItemSet(
Collection extends T> collection,
Collection> constraints
) {
@@ -65,47 +65,48 @@ private AutocompleteDataSet(
}
/**
- * Creates an {@link AutocompleteDataSet} with the given elements,
+ * Creates an {@link AutocompleteItemSet} with the given elements,
* and the constraint that each given element may exist at most once in a command.
*/
@SafeVarargs
- public static AutocompleteDataSet onceForEachOf(T... items) {
- return new AutocompleteDataSet(
+ public static AutocompleteItemSet onceForEachOf(T... items) {
+ return new AutocompleteItemSet(
List.of(items),
List.of(AutocompleteConstraint.onceForEachOf(items))
);
}
/**
- * Creates an {@link AutocompleteDataSet} with the given elements,
+ * Creates an {@link AutocompleteItemSet} with the given elements,
* and the constraint that only one of the given elements may exist in a command.
*/
@SafeVarargs
- public static AutocompleteDataSet oneAmongAllOf(T... items) {
- return new AutocompleteDataSet(
+ public static AutocompleteItemSet oneAmongAllOf(T... items) {
+ return new AutocompleteItemSet(
List.of(items),
List.of(AutocompleteConstraint.oneAmongAllOf(items))
);
}
/**
- * Creates an {@link AutocompleteDataSet} with the given elements,
+ * Creates an {@link AutocompleteItemSet} with the given elements,
* and the constraint that all given elements may exist any number of times in a command.
*/
@SafeVarargs
- public static AutocompleteDataSet anyNumberOf(T... items) {
- return new AutocompleteDataSet(
+ public static AutocompleteItemSet anyNumberOf(T... items) {
+ return new AutocompleteItemSet(
List.of(items),
List.of()
);
}
/**
- * Concatenates all provided {@link AutocompleteDataSet}s.
+ * Concatenates all provided {@link AutocompleteItemSet}s. This includes merging all information between them,
+ * i.e., all items and constraints.
*/
@SafeVarargs
- public static AutocompleteDataSet concat(AutocompleteDataSet... sets) {
- return new AutocompleteDataSet(
+ public static AutocompleteItemSet concat(AutocompleteItemSet... sets) {
+ return new AutocompleteItemSet(
Arrays.stream(sets).flatMap(Collection::stream).collect(Collectors.toList()),
Arrays.stream(sets).flatMap(s -> s.constraints.stream()).collect(Collectors.toList())
);
@@ -114,8 +115,8 @@ public static AutocompleteDataSet concat(AutocompleteDataSet... sets)
/**
* Returns a copy of the current instance.
*/
- public AutocompleteDataSet copy() {
- return new AutocompleteDataSet(this, constraints);
+ public AutocompleteItemSet copy() {
+ return new AutocompleteItemSet(this, constraints);
}
@@ -126,9 +127,9 @@ public AutocompleteDataSet copy() {
* elements in {@code dependencies} to exist in a command.
*/
@SafeVarargs
- public final AutocompleteDataSet addDependents(AutocompleteDataSet... dependencies) {
+ public final AutocompleteItemSet addDependents(AutocompleteItemSet... dependencies) {
- AutocompleteDataSet mergedDependencies = AutocompleteDataSet.concat(dependencies);
+ AutocompleteItemSet mergedDependencies = AutocompleteItemSet.concat(dependencies);
// Create a dependency array
// - The unchecked cast is required for generics since generic arrays cannot be made.
@@ -155,7 +156,7 @@ public final AutocompleteDataSet addDependents(AutocompleteDataSet... depe
* @param constraint The constraint to add.
* @return A reference to {@code this} instance, useful for chaining.
*/
- public AutocompleteDataSet addConstraint(AutocompleteConstraint super T> constraint) {
+ public AutocompleteItemSet addConstraint(AutocompleteConstraint super T> constraint) {
this.constraints.add(constraint);
return this;
}
@@ -166,7 +167,7 @@ public AutocompleteDataSet addConstraint(AutocompleteConstraint super T> co
* @param constraint The constraint to remove.
* @return A reference to {@code this} instance, useful for chaining.
*/
- public AutocompleteDataSet removeConstraint(AutocompleteConstraint super T> constraint) {
+ public AutocompleteItemSet removeConstraint(AutocompleteConstraint super T> constraint) {
this.constraints.remove(constraint);
return this;
}
@@ -177,7 +178,7 @@ public AutocompleteDataSet removeConstraint(AutocompleteConstraint super T>
* @param constraints The constraints to add.
* @return A reference to {@code this} instance, useful for chaining.
*/
- public AutocompleteDataSet addConstraints(Collection> constraints) {
+ public AutocompleteItemSet addConstraints(Collection> constraints) {
this.constraints.addAll(constraints);
return this;
}
@@ -188,7 +189,7 @@ public AutocompleteDataSet addConstraints(Collection removeConstraints(Collection> constraints) {
+ public AutocompleteItemSet removeConstraints(Collection> constraints) {
this.constraints.removeAll(constraints);
return this;
}
@@ -206,7 +207,7 @@ public Set> getConstraints() {
* Adds the item to the set.
* Equivalent to {@link #add}, but returns {@code this}, so is useful for chaining.
*/
- public AutocompleteDataSet addElement(T e) {
+ public AutocompleteItemSet addElement(T e) {
this.add(e);
return this;
}
@@ -215,7 +216,7 @@ public AutocompleteDataSet addElement(T e) {
* Removes the item from the set.
* Equivalent to {@link #remove}, but returns {@code this}, so is useful for chaining.
*/
- public AutocompleteDataSet removeElement(T e) {
+ public AutocompleteItemSet removeElement(T e) {
this.remove(e);
return this;
}
@@ -224,7 +225,7 @@ public AutocompleteDataSet removeElement(T e) {
* Adds the items to the set.
* Equivalent to {@link #addAll}, but returns {@code this}, so is useful for chaining.
*/
- public AutocompleteDataSet addElements(Collection extends T> e) {
+ public AutocompleteItemSet addElements(Collection extends T> e) {
this.addAll(e);
return this;
}
@@ -233,14 +234,14 @@ public AutocompleteDataSet addElements(Collection extends T> e) {
* Removes the items from the set.
* Equivalent to {@link #removeAll}, but returns {@code this}, so is useful for chaining.
*/
- public AutocompleteDataSet removeElements(Collection extends T> e) {
+ public AutocompleteItemSet removeElements(Collection extends T> e) {
this.removeAll(e);
return this;
}
/**
* Returns the elements in this instance in a new {@link Set} instance.
- * Properties like iteration order are preserved.
+ * Iteration order is preserved.
*/
public Set getElements() {
return new LinkedHashSet<>(this);
@@ -266,11 +267,11 @@ public Set getElementsAfterConsuming(Set extends T> existingElements) {
public boolean equals(Object o) {
// instanceof checks null implicitly.
- if (!(o instanceof AutocompleteDataSet)) {
+ if (!(o instanceof AutocompleteItemSet)) {
return false;
}
- AutocompleteDataSet> otherSet = (AutocompleteDataSet>) o;
+ AutocompleteItemSet> otherSet = (AutocompleteItemSet>) o;
return super.equals(o) && this.constraints.equals(otherSet.constraints);
}
diff --git a/src/main/java/seedu/address/logic/autocomplete/FlagValueSupplier.java b/src/main/java/seedu/address/logic/autocomplete/components/FlagValueSupplier.java
similarity index 97%
rename from src/main/java/seedu/address/logic/autocomplete/FlagValueSupplier.java
rename to src/main/java/seedu/address/logic/autocomplete/components/FlagValueSupplier.java
index 6307c613b69..31a8bcf4f2d 100644
--- a/src/main/java/seedu/address/logic/autocomplete/FlagValueSupplier.java
+++ b/src/main/java/seedu/address/logic/autocomplete/components/FlagValueSupplier.java
@@ -1,4 +1,4 @@
-package seedu.address.logic.autocomplete;
+package seedu.address.logic.autocomplete.components;
import java.util.function.BiFunction;
import java.util.stream.Stream;
diff --git a/src/main/java/seedu/address/logic/autocomplete/PartitionedCommand.java b/src/main/java/seedu/address/logic/autocomplete/components/PartitionedCommand.java
similarity index 96%
rename from src/main/java/seedu/address/logic/autocomplete/PartitionedCommand.java
rename to src/main/java/seedu/address/logic/autocomplete/components/PartitionedCommand.java
index c8293b5b762..76bda07dde4 100644
--- a/src/main/java/seedu/address/logic/autocomplete/PartitionedCommand.java
+++ b/src/main/java/seedu/address/logic/autocomplete/components/PartitionedCommand.java
@@ -1,4 +1,4 @@
-package seedu.address.logic.autocomplete;
+package seedu.address.logic.autocomplete.components;
import java.util.List;
import java.util.Objects;
@@ -22,7 +22,7 @@ public class PartitionedCommand {
/**
* Initializes and prepares the given command as distinct partitions.
*/
- PartitionedCommand(String partialCommand) {
+ public PartitionedCommand(String partialCommand) {
List words = List.of(partialCommand.split(" ", -1)); // -1 stops stripping adjacent spaces.
if (words.size() <= 1) {
@@ -170,8 +170,8 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
- seedu.address.logic.autocomplete.PartitionedCommand
- other = (seedu.address.logic.autocomplete.PartitionedCommand) o;
+ PartitionedCommand
+ other = (PartitionedCommand) o;
return Objects.equals(name, other.name)
&& Objects.equals(middleText, other.middleText)
&& Objects.equals(trailingText, other.trailingText);
diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java
index 9455de4f6d1..641d17054fe 100644
--- a/src/main/java/seedu/address/logic/commands/AddCommand.java
+++ b/src/main/java/seedu/address/logic/commands/AddCommand.java
@@ -22,8 +22,8 @@
import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.autocomplete.AutocompleteSupplier;
-import seedu.address.logic.autocomplete.data.AutocompleteConstraint;
-import seedu.address.logic.autocomplete.data.AutocompleteDataSet;
+import seedu.address.logic.autocomplete.components.AutocompleteConstraint;
+import seedu.address.logic.autocomplete.components.AutocompleteItemSet;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.contact.Address;
@@ -44,15 +44,15 @@ public abstract class AddCommand extends Command {
public static final String COMMAND_WORD = "add";
public static final AutocompleteSupplier AUTOCOMPLETE_SUPPLIER = AutocompleteSupplier.from(
- AutocompleteDataSet.oneAmongAllOf(
+ AutocompleteItemSet.oneAmongAllOf(
FLAG_ORGANIZATION, FLAG_RECRUITER
).addDependents(
- AutocompleteDataSet.onceForEachOf(
+ AutocompleteItemSet.onceForEachOf(
FLAG_NAME, FLAG_ID,
FLAG_PHONE, FLAG_EMAIL, FLAG_ADDRESS, FLAG_URL,
FLAG_ORGANIZATION_ID
),
- AutocompleteDataSet.anyNumberOf(FLAG_TAG)
+ AutocompleteItemSet.anyNumberOf(FLAG_TAG)
).addConstraints(List.of(
AutocompleteConstraint.where(FLAG_RECRUITER)
.isPrerequisiteFor(FLAG_ORGANIZATION_ID)
diff --git a/src/main/java/seedu/address/logic/commands/ApplyCommand.java b/src/main/java/seedu/address/logic/commands/ApplyCommand.java
index afd57a98829..cc5ec68aa90 100644
--- a/src/main/java/seedu/address/logic/commands/ApplyCommand.java
+++ b/src/main/java/seedu/address/logic/commands/ApplyCommand.java
@@ -15,7 +15,7 @@
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.autocomplete.AutocompleteSupplier;
-import seedu.address.logic.autocomplete.data.AutocompleteDataSet;
+import seedu.address.logic.autocomplete.components.AutocompleteItemSet;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.contact.Contact;
@@ -37,7 +37,7 @@ public class ApplyCommand extends Command {
public static final String COMMAND_WORD = "apply";
public static final AutocompleteSupplier AUTOCOMPLETE_SUPPLIER = AutocompleteSupplier.from(
- AutocompleteDataSet.onceForEachOf(
+ AutocompleteItemSet.onceForEachOf(
FLAG_TITLE, FLAG_DESCRIPTION,
FLAG_DEADLINE, FLAG_STAGE, FLAG_STATUS
)
diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java
index 06db50c9c62..ef615852c40 100644
--- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java
+++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java
@@ -13,7 +13,7 @@
import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.autocomplete.AutocompleteSupplier;
-import seedu.address.logic.autocomplete.data.AutocompleteDataSet;
+import seedu.address.logic.autocomplete.components.AutocompleteItemSet;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.contact.Contact;
@@ -29,7 +29,7 @@ public class DeleteCommand extends Command {
public static final String COMMAND_WORD = "delete";
public static final AutocompleteSupplier AUTOCOMPLETE_SUPPLIER = AutocompleteSupplier.from(
- AutocompleteDataSet.oneAmongAllOf(
+ AutocompleteItemSet.oneAmongAllOf(
FLAG_RECURSIVE, FLAG_APPLICATION
)
).configureValueMap(map -> {
diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java
index 998d01b1322..56c2efc9772 100644
--- a/src/main/java/seedu/address/logic/commands/EditCommand.java
+++ b/src/main/java/seedu/address/logic/commands/EditCommand.java
@@ -32,8 +32,8 @@
import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.autocomplete.AutocompleteSupplier;
-import seedu.address.logic.autocomplete.data.AutocompleteConstraint;
-import seedu.address.logic.autocomplete.data.AutocompleteDataSet;
+import seedu.address.logic.autocomplete.components.AutocompleteConstraint;
+import seedu.address.logic.autocomplete.components.AutocompleteItemSet;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.Flag;
import seedu.address.model.Model;
@@ -59,19 +59,19 @@ public class EditCommand extends Command {
public static final String COMMAND_WORD = "edit";
- public static final AutocompleteDataSet AUTOCOMPLETE_SET_STANDARD = AutocompleteDataSet.concat(
- AutocompleteDataSet.onceForEachOf(
+ public static final AutocompleteItemSet AUTOCOMPLETE_SET_STANDARD = AutocompleteItemSet.concat(
+ AutocompleteItemSet.onceForEachOf(
FLAG_NAME, FLAG_ID,
FLAG_PHONE, FLAG_EMAIL, FLAG_ADDRESS, FLAG_URL,
FLAG_ORGANIZATION_ID
),
- AutocompleteDataSet.anyNumberOf(FLAG_TAG)
+ AutocompleteItemSet.anyNumberOf(FLAG_TAG)
);
- public static final AutocompleteDataSet AUTOCOMPLETE_SET_APPLICATION = AutocompleteDataSet
+ public static final AutocompleteItemSet AUTOCOMPLETE_SET_APPLICATION = AutocompleteItemSet
.onceForEachOf(FLAG_APPLICATION)
.addDependents(
- AutocompleteDataSet.onceForEachOf(
+ AutocompleteItemSet.onceForEachOf(
FLAG_TITLE, FLAG_DESCRIPTION, FLAG_DEADLINE, FLAG_STAGE, FLAG_STATUS
))
.addConstraint(
diff --git a/src/main/java/seedu/address/logic/commands/ReminderCommand.java b/src/main/java/seedu/address/logic/commands/ReminderCommand.java
index ba49fe11e6b..d3cd072ee5e 100644
--- a/src/main/java/seedu/address/logic/commands/ReminderCommand.java
+++ b/src/main/java/seedu/address/logic/commands/ReminderCommand.java
@@ -5,7 +5,7 @@
import static seedu.address.logic.parser.CliSyntax.FLAG_LATEST;
import seedu.address.logic.autocomplete.AutocompleteSupplier;
-import seedu.address.logic.autocomplete.data.AutocompleteDataSet;
+import seedu.address.logic.autocomplete.components.AutocompleteItemSet;
import seedu.address.model.Model;
import seedu.address.model.jobapplication.JobApplication;
@@ -16,7 +16,7 @@ public class ReminderCommand extends Command {
public static final String COMMAND_WORD = "remind";
public static final AutocompleteSupplier AUTOCOMPLETE_SUPPLIER = AutocompleteSupplier.from(
- AutocompleteDataSet.oneAmongAllOf(
+ AutocompleteItemSet.oneAmongAllOf(
FLAG_EARLIEST, FLAG_LATEST
)
).configureValueMap(map -> {
diff --git a/src/main/java/seedu/address/logic/commands/SortCommand.java b/src/main/java/seedu/address/logic/commands/SortCommand.java
index b6f1c959acb..de6de129df8 100644
--- a/src/main/java/seedu/address/logic/commands/SortCommand.java
+++ b/src/main/java/seedu/address/logic/commands/SortCommand.java
@@ -20,8 +20,8 @@
import java.util.Objects;
import seedu.address.logic.autocomplete.AutocompleteSupplier;
-import seedu.address.logic.autocomplete.data.AutocompleteConstraint;
-import seedu.address.logic.autocomplete.data.AutocompleteDataSet;
+import seedu.address.logic.autocomplete.components.AutocompleteConstraint;
+import seedu.address.logic.autocomplete.components.AutocompleteItemSet;
import seedu.address.model.Model;
import seedu.address.model.contact.Contact;
import seedu.address.model.jobapplication.JobApplication;
@@ -33,12 +33,12 @@ public class SortCommand extends Command {
public static final String COMMAND_WORD = "sort";
public static final AutocompleteSupplier AUTOCOMPLETE_SUPPLIER = AutocompleteSupplier.from(
- AutocompleteDataSet.concat(
- AutocompleteDataSet.oneAmongAllOf(
+ AutocompleteItemSet.concat(
+ AutocompleteItemSet.oneAmongAllOf(
FLAG_NAME, FLAG_ID, FLAG_PHONE, FLAG_EMAIL, FLAG_ADDRESS, FLAG_URL,
FLAG_STALE, FLAG_STAGE, FLAG_STATUS, FLAG_DEADLINE, FLAG_TITLE,
FLAG_NONE
- ), AutocompleteDataSet.oneAmongAllOf(
+ ), AutocompleteItemSet.oneAmongAllOf(
FLAG_ASCENDING, FLAG_DESCENDING
)
).addConstraint(
diff --git a/src/test/java/seedu/address/logic/autocomplete/AutocompleteGeneratorTest.java b/src/test/java/seedu/address/logic/autocomplete/AutocompleteGeneratorTest.java
index 27565b5239c..391148d6cb8 100644
--- a/src/test/java/seedu/address/logic/autocomplete/AutocompleteGeneratorTest.java
+++ b/src/test/java/seedu/address/logic/autocomplete/AutocompleteGeneratorTest.java
@@ -9,8 +9,8 @@
import org.junit.jupiter.api.Test;
-import seedu.address.logic.autocomplete.data.AutocompleteConstraint;
-import seedu.address.logic.autocomplete.data.AutocompleteDataSet;
+import seedu.address.logic.autocomplete.components.AutocompleteConstraint;
+import seedu.address.logic.autocomplete.components.AutocompleteItemSet;
import seedu.address.logic.parser.Flag;
public class AutocompleteGeneratorTest {
@@ -58,9 +58,9 @@ public void generateCompletions_usingAutocompleteSupplier_correctResult() {
Flag flagC2 = new Flag("code");
AutocompleteSupplier supplier = new AutocompleteSupplier(
- AutocompleteDataSet.concat(
- AutocompleteDataSet.onceForEachOf(flagA1, flagA2, flagA3),
- AutocompleteDataSet.anyNumberOf(flagB, flagC1, flagC2)
+ AutocompleteItemSet.concat(
+ AutocompleteItemSet.onceForEachOf(flagA1, flagA2, flagA3),
+ AutocompleteItemSet.anyNumberOf(flagB, flagC1, flagC2)
).addConstraint(
AutocompleteConstraint.oneAmongAllOf(flagA1, flagA2)
),
diff --git a/src/test/java/seedu/address/logic/autocomplete/AutocompleteSupplierTest.java b/src/test/java/seedu/address/logic/autocomplete/AutocompleteSupplierTest.java
index 43a4366b9c1..c4a41af0b34 100644
--- a/src/test/java/seedu/address/logic/autocomplete/AutocompleteSupplierTest.java
+++ b/src/test/java/seedu/address/logic/autocomplete/AutocompleteSupplierTest.java
@@ -10,8 +10,9 @@
import org.junit.jupiter.api.Test;
-import seedu.address.logic.autocomplete.data.AutocompleteConstraint;
-import seedu.address.logic.autocomplete.data.AutocompleteDataSet;
+import seedu.address.logic.autocomplete.components.AutocompleteConstraint;
+import seedu.address.logic.autocomplete.components.AutocompleteItemSet;
+import seedu.address.logic.autocomplete.components.PartitionedCommand;
import seedu.address.logic.parser.Flag;
public class AutocompleteSupplierTest {
@@ -37,8 +38,8 @@ public void getAllPossibleFlags() {
assertEquals(Set.of(FLAG_A, FLAG_B), supplier.getAllPossibleFlags());
supplier = AutocompleteSupplier.from(
- AutocompleteDataSet.onceForEachOf(FLAG_A, FLAG_B),
- AutocompleteDataSet.anyNumberOf(FLAG_C, FLAG_D)
+ AutocompleteItemSet.onceForEachOf(FLAG_A, FLAG_B),
+ AutocompleteItemSet.anyNumberOf(FLAG_C, FLAG_D)
);
assertEquals(Set.of(FLAG_A, FLAG_B, FLAG_C, FLAG_D), supplier.getAllPossibleFlags());
}
@@ -63,8 +64,8 @@ public void getOtherPossibleFlagsAsideFromFlagsPresent() {
// Mixed flags
supplier = AutocompleteSupplier.from(
- AutocompleteDataSet.onceForEachOf(FLAG_A, FLAG_B),
- AutocompleteDataSet.anyNumberOf(FLAG_C, FLAG_D)
+ AutocompleteItemSet.onceForEachOf(FLAG_A, FLAG_B),
+ AutocompleteItemSet.anyNumberOf(FLAG_C, FLAG_D)
);
assertEquals(
Set.of(FLAG_A, FLAG_B, FLAG_C, FLAG_D),
@@ -77,9 +78,9 @@ public void getOtherPossibleFlagsAsideFromFlagsPresent() {
// Mixed advanced combination.
supplier = AutocompleteSupplier.from(
- AutocompleteDataSet.concat(
- AutocompleteDataSet.onceForEachOf(FLAG_A, FLAG_B),
- AutocompleteDataSet.anyNumberOf(FLAG_C, FLAG_D)
+ AutocompleteItemSet.concat(
+ AutocompleteItemSet.onceForEachOf(FLAG_A, FLAG_B),
+ AutocompleteItemSet.anyNumberOf(FLAG_C, FLAG_D)
).addConstraints(List.of(
AutocompleteConstraint.oneAmongAllOf(FLAG_A, FLAG_B), // A & B cannot coexist
AutocompleteConstraint.oneAmongAllOf(FLAG_B, FLAG_C) // B & C cannot coexist
@@ -111,9 +112,9 @@ public void getOtherPossibleFlagsAsideFromFlagsPresent() {
@Test
public void getValidValues() {
var supplier = new AutocompleteSupplier(
- AutocompleteDataSet.concat(
- AutocompleteDataSet.onceForEachOf(FLAG_A, FLAG_B, FLAG_C),
- AutocompleteDataSet.anyNumberOf(FLAG_D)
+ AutocompleteItemSet.concat(
+ AutocompleteItemSet.onceForEachOf(FLAG_A, FLAG_B, FLAG_C),
+ AutocompleteItemSet.anyNumberOf(FLAG_D)
).addConstraint(
AutocompleteConstraint.oneAmongAllOf(FLAG_A, FLAG_B) // A & B cannot coexist
),
diff --git a/src/test/java/seedu/address/logic/autocomplete/data/AutocompleteConstraintTest.java b/src/test/java/seedu/address/logic/autocomplete/components/AutocompleteConstraintTest.java
similarity index 98%
rename from src/test/java/seedu/address/logic/autocomplete/data/AutocompleteConstraintTest.java
rename to src/test/java/seedu/address/logic/autocomplete/components/AutocompleteConstraintTest.java
index ba3cfef3e5a..8b765be07e5 100644
--- a/src/test/java/seedu/address/logic/autocomplete/data/AutocompleteConstraintTest.java
+++ b/src/test/java/seedu/address/logic/autocomplete/components/AutocompleteConstraintTest.java
@@ -1,4 +1,4 @@
-package seedu.address.logic.autocomplete.data;
+package seedu.address.logic.autocomplete.components;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
From 796320ecd6d2be60ca132caa189a4296e8503a39 Mon Sep 17 00:00:00 2001
From: Wern
Date: Sun, 12 Nov 2023 21:48:37 +0800
Subject: [PATCH 04/10] Improve command retrieval documentation
---
.../seedu/address/logic/commands/Command.java | 6 +---
.../address/logic/parser/ClassMappings.java | 34 ++++++++++++++++---
2 files changed, 30 insertions(+), 10 deletions(-)
diff --git a/src/main/java/seedu/address/logic/commands/Command.java b/src/main/java/seedu/address/logic/commands/Command.java
index dbc8a71413e..b9bcae1b1e1 100644
--- a/src/main/java/seedu/address/logic/commands/Command.java
+++ b/src/main/java/seedu/address/logic/commands/Command.java
@@ -64,11 +64,7 @@ public static Optional getCommandWord(Class extends Command> cls) {
}
} catch (NoSuchFieldException | IllegalAccessException e) {
- // Should not reach here...
-
- assert cls.equals(Command.class)
- : "a public COMMAND_WORD static field should be present for Command subclasses, but missing in "
- + cls.getName();
+ // Leave value as null...
}
return Optional.ofNullable(value);
diff --git a/src/main/java/seedu/address/logic/parser/ClassMappings.java b/src/main/java/seedu/address/logic/parser/ClassMappings.java
index 859f13352ae..0cb2ae2916d 100644
--- a/src/main/java/seedu/address/logic/parser/ClassMappings.java
+++ b/src/main/java/seedu/address/logic/parser/ClassMappings.java
@@ -4,7 +4,9 @@
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
+import java.util.logging.Logger;
+import seedu.address.commons.core.LogsCenter;
import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.ApplyCommand;
import seedu.address.logic.commands.ClearCommand;
@@ -27,8 +29,14 @@ public class ClassMappings {
public static final Map, Optional>>>
COMMAND_TO_PARSER_MAP = getCommandToParserMap();
- private ClassMappings() { } // Should not be initialized.
-
+ /**
+ * Creates and returns an ordered map of command classes as keys, and optionally their corresponding parsers
+ * if they accept arguments.
+ *
+ *
+ * Developer's note: This method may be modified to include support for new commands.
+ *
+ */
private static Map, Optional>>>
getCommandToParserMap() {
@@ -58,16 +66,32 @@ private ClassMappings() { } // Should not be initialized.
return orderedMap;
}
+ /**
+ * This is a helper method to validate whether the given map of commands and parsers meet the expected
+ * specifications.
+ *
+ *
+ * - All commands must have a command word.
+ * - All commands must either have a parser that can initialize with no arguments, or itself be initalized
+ * with no-arguments
+ *
+ *
+ *
+ * This method's purpose for validating the specifications is because we would be retrieving values
+ * directly via Java's Reflection API and initializing the instances that way, which does not have compile time
+ * checks. Adding an assertion to ensure this works helps validate that no programmer error has slipped by.
+ *
+ */
private static boolean isCommandToParserMapOperational(
Map, Optional>>> map
) {
try {
- // Assert that no programmer error slips by,
- // since we're utilizing reflections to obtain values and initialize classes.
for (var entry: map.entrySet()) {
// We must have a command word for every command.
- assert Command.getCommandWord(entry.getKey()).isPresent();
+ assert Command.getCommandWord(entry.getKey()).isPresent()
+ : "All commands must have COMMAND_WORD set, but "
+ + entry.getKey().getSimpleName() + " does not!";
if (entry.getValue().isPresent()) {
// If there's a parser class, we must be able to initialize them with no args without errors.
From bea3d220875c55a73b382efd1cdcde67210352c4 Mon Sep 17 00:00:00 2001
From: Wern
Date: Sun, 12 Nov 2023 21:59:53 +0800
Subject: [PATCH 05/10] Fix tests
---
.../java/seedu/address/storage/JsonAdaptedContact.java | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/src/main/java/seedu/address/storage/JsonAdaptedContact.java b/src/main/java/seedu/address/storage/JsonAdaptedContact.java
index 919a7826e09..63ee0219481 100644
--- a/src/main/java/seedu/address/storage/JsonAdaptedContact.java
+++ b/src/main/java/seedu/address/storage/JsonAdaptedContact.java
@@ -211,6 +211,16 @@ public Contact toModelType(ReadOnlyAddressBook reference) throws IllegalValueExc
@Override
public int compareTo(JsonAdaptedContact o) {
+ boolean isThisTypeValid = Type.isValidType(this.type);
+ boolean isOtherTypeValid = Type.isValidType(o.type);
+
+ if (!isThisTypeValid) {
+ return isOtherTypeValid ? 1 : 0;
+ }
+ if (!isOtherTypeValid) {
+ return -1;
+ }
+
return Type.fromString(this.type).compareTo(Type.fromString(o.type));
}
}
From 85d46521b7ee4bb27f17f957aa5e27a495dcb705 Mon Sep 17 00:00:00 2001
From: Wern
Date: Sun, 12 Nov 2023 22:18:58 +0800
Subject: [PATCH 06/10] Fix checkstyle
---
src/main/java/seedu/address/logic/parser/ClassMappings.java | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/main/java/seedu/address/logic/parser/ClassMappings.java b/src/main/java/seedu/address/logic/parser/ClassMappings.java
index 0cb2ae2916d..dfd1e76f6a5 100644
--- a/src/main/java/seedu/address/logic/parser/ClassMappings.java
+++ b/src/main/java/seedu/address/logic/parser/ClassMappings.java
@@ -4,9 +4,7 @@
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
-import java.util.logging.Logger;
-import seedu.address.commons.core.LogsCenter;
import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.ApplyCommand;
import seedu.address.logic.commands.ClearCommand;
From b630ad8342515c112918c60965feebd215d64a30 Mon Sep 17 00:00:00 2001
From: Wern
Date: Sun, 12 Nov 2023 23:06:10 +0800
Subject: [PATCH 07/10] Fix autocomplete UP, DOWN, ENTER keystroke handling
---
.../address/ui/AutocompleteTextField.java | 90 +++++++++++++++----
.../java/seedu/address/ui/CommandBox.java | 8 +-
2 files changed, 77 insertions(+), 21 deletions(-)
diff --git a/src/main/java/seedu/address/ui/AutocompleteTextField.java b/src/main/java/seedu/address/ui/AutocompleteTextField.java
index 318d9e8c1a1..f208e5446bd 100644
--- a/src/main/java/seedu/address/ui/AutocompleteTextField.java
+++ b/src/main/java/seedu/address/ui/AutocompleteTextField.java
@@ -4,6 +4,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
+import java.util.Set;
import java.util.Stack;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -13,6 +14,7 @@
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Side;
+import javafx.scene.Node;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.CustomMenuItem;
import javafx.scene.control.Label;
@@ -59,6 +61,13 @@ public String toString() {
}
}
+ /**
+ * An enum of execution status.
+ */
+ public enum ActionResult {
+ EXECUTED, NOT_EXECUTED;
+ }
+
/**
* A functional interface that generates a stream of auto-completion results
* based on the given partial input.
@@ -66,14 +75,19 @@ public String toString() {
@FunctionalInterface
public interface CompletionGenerator extends Function> { }
+ // Internal JavaFX ID values
+ private static final String AUTOCOMPLETE_MENU_ITEM_ID_PREFIX = "autocomplete-completion-item-";
+
// GUI elements
private final ContextMenu autocompletePopup;
+
// Configuration variables
private CompletionGenerator completionGenerator = s -> Stream.empty();
private String autocompleteHintString = "[Select to autocomplete]";
private int popupLimit = 10;
+
// History tracking for autocomplete undo operations
private final Stack autocompleteHistory = new Stack<>();
@@ -94,6 +108,37 @@ public AutocompleteTextField() {
// We disallow this by intercepting it before it does.
e.consume();
}
+
+ if (e.getCode() == KeyCode.ENTER) {
+ // The default behaviour of ENTER seems buggy.
+ // We will intercept it and do our own processing.
+ // This uses JavaFX private APIs to locate the focused element, as found here:
+ // https://stackoverflow.com/questions/27332981/contextmenu-and-programmatically-selecting-an-item
+ e.consume();
+
+ int highlightedIndex = 0;
+
+ Set items = autocompletePopup.getSkin().getNode().lookupAll(".menu-item");
+ for (Node item : items) {
+ if (!item.isFocused() && !item.isHover()) {
+ continue;
+ }
+
+ if (!item.getId().startsWith(AUTOCOMPLETE_MENU_ITEM_ID_PREFIX)) {
+ continue;
+ }
+
+ try {
+ String indexPart = item.getId().substring(AUTOCOMPLETE_MENU_ITEM_ID_PREFIX.length());
+ highlightedIndex = Integer.parseInt(indexPart, 10);
+ break;
+ } catch (NumberFormatException exception) {
+ // Ignore...
+ }
+ }
+
+ this.triggerImmediateAutocompletion(highlightedIndex);
+ }
});
// Setup autocompletion popup menu UI updates
@@ -129,18 +174,23 @@ public int getPopupLimit() {
/**
* Triggers autocompletion immediately using the first suggested value, if any.
- *
- * @return true if an autocompleted result has been filled in, false otherwise.
*/
- public boolean triggerImmediateAutocompletion() {
+ public ActionResult triggerImmediateAutocompletion() {
+ return triggerImmediateAutocompletion(0);
+ }
+
+ /**
+ * Triggers autocompletion immediately using the given suggested value index, if any.
+ */
+ public ActionResult triggerImmediateAutocompletion(int index) {
ObservableList