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);
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 + " ]===========================");
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);
ui.start(primaryStage);
}

@Override
public void stop() {
logger.info("============================ [ Stopping TAPro ] =============================");
logger.info("============================ [ Stopping " + APP_NAME + " ] =============================");
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))
.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();
assert isMajor;

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

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

// 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())
);
}
}
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();
assert isMajor;

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

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

// 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())
);
}
}
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();
assert isMajor;

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

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

// 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())
);
}
}
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.