Skip to content

Commit

Permalink
Merge pull request #152 from tituschewxj/wrap-up-v1.3
Browse files Browse the repository at this point in the history
Wrap up v1.3.1
  • Loading branch information
tituschewxj authored Apr 5, 2024
2 parents fc90493 + 2069fc6 commit bf69ba3
Show file tree
Hide file tree
Showing 15 changed files with 495 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# TAPro Developer Guide

<!-- * Table of Contents
<!-- * Table of Contents -->
<page-nav-print />

--------------------------------------------------------------------------------------------------------------------
Expand Down
8 changes: 3 additions & 5 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,11 @@ Autocompletes a word or a set of words, based on the current input.

<box type="warning" seamless>

**Autocomplete only works on the NUSNet ID:**
**Autocomplete doesn't work on week number:**

This is because autocomplete only makes sense when you are trying to retrieve existing data to perform an operation.
This is because week number is short,
and it is much faster just typing out the number.

As the `mark`, `unmark`, and `delstu` commands uses NUSNet ID, for their operations, it makes sense to add autocomplete for NUSNet ID.

On the other hand, as `addstu` and `edit` require new information, autocomplete is not that useful, and is therefore omitted.
</box>

<box type="success" seamless>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
public class MainApp extends Application {

public static final Version VERSION = new Version(1, 3, 0, true);
public static final Version VERSION = new Version(1, 3, 1, true);

Check warning on line 42 in src/main/java/seedu/address/MainApp.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/MainApp.java#L42

Added line #L42 was not covered by tests
public static final String APP_NAME = "TAPro";

private static final Logger logger = LogsCenter.getLogger(MainApp.class);
Expand All @@ -52,7 +52,7 @@ public class MainApp extends Application {

@Override
public void init() throws Exception {
logger.info("=============================[ Initializing TAPro ]===========================");
logger.info("=============================[ Initializing " + APP_NAME + " ]===========================");

Check warning on line 55 in src/main/java/seedu/address/MainApp.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/MainApp.java#L55

Added line #L55 was not covered by tests
super.init();

AppParameters appParameters = AppParameters.parse(getParameters());
Expand Down Expand Up @@ -185,13 +185,13 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) {

@Override
public void start(Stage primaryStage) {
logger.info("Starting AddressBook " + MainApp.VERSION);
logger.info("Starting " + APP_NAME + " " + VERSION);

Check warning on line 188 in src/main/java/seedu/address/MainApp.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/MainApp.java#L188

Added line #L188 was not covered by tests
ui.start(primaryStage);
}

@Override
public void stop() {
logger.info("============================ [ Stopping TAPro ] =============================");
logger.info("============================ [ Stopping " + APP_NAME + " ] =============================");

Check warning on line 194 in src/main/java/seedu/address/MainApp.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/MainApp.java#L194

Added line #L194 was not covered by tests
try {
storage.saveUserPrefs(model.getUserPrefs());
} catch (IOException e) {
Expand Down
85 changes: 85 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
import seedu.address.commons.core.LogsCenter;
import seedu.address.logic.autocomplete.AutoComplete;
import seedu.address.logic.autocomplete.AutoCompleteCommand;
import seedu.address.logic.autocomplete.AutoCompleteEmail;
import seedu.address.logic.autocomplete.AutoCompleteMajor;
import seedu.address.logic.autocomplete.AutoCompleteName;
import seedu.address.logic.autocomplete.AutoCompleteNusNetId;
import seedu.address.logic.autocomplete.AutoCompletePhone;
import seedu.address.logic.autocomplete.AutoCompleteResult;
import seedu.address.logic.autocomplete.AutoCompleteTag;
import seedu.address.logic.commands.AddPersonCommand;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
Expand Down Expand Up @@ -64,12 +69,51 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
|| command instanceof DeletePersonCommand
|| command instanceof EditPersonCommand) {

// TODO: code quality issues
AutoCompleteNusNetId.update(
getAddressBook()
.getPersonList()
.stream()
.map(person -> person.getNusNet().value)
.toArray(String[]::new));

AutoCompleteMajor.update(
getAddressBook()
.getPersonList()
.stream()
.map(person -> person.getMajor().value)
.toArray(String[]::new));

AutoCompleteTag.update(
getAddressBook()
.getPersonList()
.stream()
.flatMap(person -> person
.getTags()
.stream()
.map(tag -> tag.tagName))
.toArray(String[]::new));

AutoCompleteEmail.update(
getAddressBook()
.getPersonList()
.stream()
.map(person -> person.getEmail().value)
.toArray(String[]::new));

AutoCompleteName.update(
getAddressBook()
.getPersonList()
.stream()
.map(person -> person.getName().toString())
.toArray(String[]::new));

AutoCompletePhone.update(
getAddressBook()
.getPersonList()
.stream()
.map(person -> person.getPhone().value)
.toArray(String[]::new));
}

try {
Expand Down Expand Up @@ -98,13 +142,54 @@ private void initialize() {
// Initialize the autocomplete for the commands
AutoCompleteCommand.initialize();

// TODO: code quality issues
// Initialize the autocomplete for the NUSNET IDs
AutoCompleteNusNetId.initialize(
getAddressBook()
.getPersonList()
.stream()
.map(person -> person.getNusNet().value)
.toArray(String[]::new));

// Initialize the autocomplete for the Major
AutoCompleteMajor.initialize(
getAddressBook()
.getPersonList()
.stream()
.map(person -> person.getMajor().value)
.toArray(String[]::new));

// Initialize the autocomplete for the Tag
AutoCompleteTag.initialize(
getAddressBook()
.getPersonList()
.stream()
.flatMap(person -> person
.getTags()
.stream()
.map(tag -> tag.tagName))

Check warning on line 170 in src/main/java/seedu/address/logic/LogicManager.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/LogicManager.java#L168-L170

Added lines #L168 - L170 were not covered by tests
.toArray(String[]::new));

AutoCompletePhone.initialize(
getAddressBook()
.getPersonList()
.stream()
.map(person -> person.getPhone().value)
.toArray(String[]::new));

AutoCompleteEmail.initialize(
getAddressBook()
.getPersonList()
.stream()
.map(person -> person.getEmail().value)
.toArray(String[]::new));

AutoCompleteName.initialize(
getAddressBook()
.getPersonList()
.stream()
.map(person -> person.getName().toString())
.toArray(String[]::new));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class Messages {
public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The student's index provided is invalid";
public static final String MESSAGE_MISSING_NUSNET = "No such student with the NUSNET_ID found in contacts!";
public static final String MESSAGE_MISSING_NUSNET = "No such student with the NUSNet ID found in contacts!";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d students listed!";
public static final String MESSAGE_DUPLICATE_FIELDS =
"Multiple values specified for the following single-valued field(s): ";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package seedu.address.logic.autocomplete;

import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;

import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import seedu.address.commons.util.Trie;

// TODO: code quality issues
/**
* AutoComplete for major.
*/
public class AutoCompleteEmail implements AutoComplete {
private static Trie majorTrie;
private static final Pattern MAJOR_FORMAT = Pattern.compile(PREFIX_EMAIL.getPrefix() + "(.*)");

/**
* Initializes the major trie with the given majors. This method should be called once at
* the start of the initialization of LogicManager.
*
* @param majors the majors to initialize the trie with
*/
public static void initialize(String... majors) {
majorTrie = new Trie(Arrays.stream(majors).toArray(String[]::new));
}

/**
* Update the majors trie with the given majors. This method is just a wrapper for the
* initialize method in Trie to make the intention clearer.
*
* @param majors the majors to update the trie with
*/
public static void update(String... majors) {
initialize(majors);
}

@Override
public AutoCompleteResult getAutoComplete(String input) {
assert majorTrie != null;

Matcher m = MAJOR_FORMAT.matcher(input);
boolean isMajor = m.find();

Check warning on line 46 in src/main/java/seedu/address/logic/autocomplete/AutoCompleteEmail.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/autocomplete/AutoCompleteEmail.java#L45-L46

Added lines #L45 - L46 were not covered by tests
assert isMajor;

String partialMajor = m.group(1);
List<String> fullMajors = majorTrie.findAllWordsWithPrefix(partialMajor);

Check warning on line 50 in src/main/java/seedu/address/logic/autocomplete/AutoCompleteEmail.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/autocomplete/AutoCompleteEmail.java#L49-L50

Added lines #L49 - L50 were not covered by tests

assert fullMajors != null;
if (fullMajors.isEmpty()) {
return new AutoCompleteResult();

Check warning on line 54 in src/main/java/seedu/address/logic/autocomplete/AutoCompleteEmail.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/autocomplete/AutoCompleteEmail.java#L54

Added line #L54 was not covered by tests
}

// Strip the input from the full commands and sort the list
return new AutoCompleteResult(
fullMajors.stream()
.map(c -> c.substring(partialMajor.length()))
.sorted()
.collect(Collectors.toList())

Check warning on line 62 in src/main/java/seedu/address/logic/autocomplete/AutoCompleteEmail.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/autocomplete/AutoCompleteEmail.java#L58-L62

Added lines #L58 - L62 were not covered by tests
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package seedu.address.logic.autocomplete;

import static seedu.address.logic.parser.CliSyntax.PREFIX_MAJOR;

import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import seedu.address.commons.util.Trie;

// TODO: code quality issues
/**
* AutoComplete for major.
*/
public class AutoCompleteMajor implements AutoComplete {
private static Trie majorTrie;
private static final Pattern MAJOR_FORMAT = Pattern.compile(PREFIX_MAJOR.getPrefix() + "(.*)");

/**
* Initializes the major trie with the given majors. This method should be called once at
* the start of the initialization of LogicManager.
*
* @param majors the majors to initialize the trie with
*/
public static void initialize(String... majors) {
majorTrie = new Trie(Arrays.stream(majors).toArray(String[]::new));
}

/**
* Update the majors trie with the given majors. This method is just a wrapper for the
* initialize method in Trie to make the intention clearer.
*
* @param majors the majors to update the trie with
*/
public static void update(String... majors) {
initialize(majors);
}

@Override
public AutoCompleteResult getAutoComplete(String input) {
assert majorTrie != null;

Matcher m = MAJOR_FORMAT.matcher(input);
boolean isMajor = m.find();

Check warning on line 46 in src/main/java/seedu/address/logic/autocomplete/AutoCompleteMajor.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/autocomplete/AutoCompleteMajor.java#L45-L46

Added lines #L45 - L46 were not covered by tests
assert isMajor;

String partialMajor = m.group(1);
List<String> fullMajors = majorTrie.findAllWordsWithPrefix(partialMajor);

Check warning on line 50 in src/main/java/seedu/address/logic/autocomplete/AutoCompleteMajor.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/autocomplete/AutoCompleteMajor.java#L49-L50

Added lines #L49 - L50 were not covered by tests

assert fullMajors != null;
if (fullMajors.isEmpty()) {
return new AutoCompleteResult();

Check warning on line 54 in src/main/java/seedu/address/logic/autocomplete/AutoCompleteMajor.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/autocomplete/AutoCompleteMajor.java#L54

Added line #L54 was not covered by tests
}

// Strip the input from the full commands and sort the list
return new AutoCompleteResult(
fullMajors.stream()
.map(c -> c.substring(partialMajor.length()))
.sorted()
.collect(Collectors.toList())

Check warning on line 62 in src/main/java/seedu/address/logic/autocomplete/AutoCompleteMajor.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/autocomplete/AutoCompleteMajor.java#L58-L62

Added lines #L58 - L62 were not covered by tests
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package seedu.address.logic.autocomplete;

import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;

import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import seedu.address.commons.util.Trie;

// TODO: code quality issues
/**
* AutoComplete for major.
*/
public class AutoCompleteName implements AutoComplete {
private static Trie majorTrie;
private static final Pattern MAJOR_FORMAT = Pattern.compile(PREFIX_NAME.getPrefix() + "(.*)");

/**
* Initializes the major trie with the given majors. This method should be called once at
* the start of the initialization of LogicManager.
*
* @param majors the majors to initialize the trie with
*/
public static void initialize(String... majors) {
majorTrie = new Trie(Arrays.stream(majors).toArray(String[]::new));
}

/**
* Update the majors trie with the given majors. This method is just a wrapper for the
* initialize method in Trie to make the intention clearer.
*
* @param majors the majors to update the trie with
*/
public static void update(String... majors) {
initialize(majors);
}

@Override
public AutoCompleteResult getAutoComplete(String input) {
assert majorTrie != null;

Matcher m = MAJOR_FORMAT.matcher(input);
boolean isMajor = m.find();

Check warning on line 46 in src/main/java/seedu/address/logic/autocomplete/AutoCompleteName.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/autocomplete/AutoCompleteName.java#L45-L46

Added lines #L45 - L46 were not covered by tests
assert isMajor;

String partialMajor = m.group(1);
List<String> fullMajors = majorTrie.findAllWordsWithPrefix(partialMajor);

Check warning on line 50 in src/main/java/seedu/address/logic/autocomplete/AutoCompleteName.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/autocomplete/AutoCompleteName.java#L49-L50

Added lines #L49 - L50 were not covered by tests

assert fullMajors != null;
if (fullMajors.isEmpty()) {
return new AutoCompleteResult();

Check warning on line 54 in src/main/java/seedu/address/logic/autocomplete/AutoCompleteName.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/autocomplete/AutoCompleteName.java#L54

Added line #L54 was not covered by tests
}

// Strip the input from the full commands and sort the list
return new AutoCompleteResult(
fullMajors.stream()
.map(c -> c.substring(partialMajor.length()))
.sorted()
.collect(Collectors.toList())

Check warning on line 62 in src/main/java/seedu/address/logic/autocomplete/AutoCompleteName.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/autocomplete/AutoCompleteName.java#L58-L62

Added lines #L58 - L62 were not covered by tests
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import seedu.address.commons.util.Trie;

// TODO: code quality issues
/**
* AutoComplete for NUSNET ID
*/
Expand Down
Loading

0 comments on commit bf69ba3

Please sign in to comment.