Skip to content

Commit

Permalink
Coding style fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxiangs committed Sep 28, 2024
1 parent a48f1a7 commit 9937d76
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 37 deletions.
31 changes: 13 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@ test {
}

task coverage(type: JacocoReport) {
dependsOn test // Ensure tests run before coverage report generation
sourceDirectories.from files(sourceSets.main.allSource.srcDirs)
classDirectories.from files(sourceSets.main.output)
executionData.from files(jacocoTestReport.executionData)

afterEvaluate {
classDirectories.from files(classDirectories.files.collect {
fileTree(dir: it, exclude: ['**/*.jar'])
})
}

reports {
html.required = true
xml.required = true
Expand All @@ -47,31 +44,29 @@ dependencies {
String jUnitVersion = '5.4.0'
String javaFxVersion = '17.0.7'

// JavaFX Dependencies, simplified to cover all platforms
implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion
implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion
implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion
implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'linux'
implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'linux'
implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'linux'
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'linux'

// Jackson Dependencies
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.7.0'
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.7.4'

// JUnit for Testing
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: jUnitVersion

testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: jUnitVersion
}

shadowJar {
archiveFileName = 'addressbook.jar'
}

jacocoTestReport {
reports {
html.enabled true
xml.enabled true
}
}

defaultTasks 'clean', 'test'

3 changes: 2 additions & 1 deletion src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Address;
import seedu.address.model.person.Remark;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Remark;
import seedu.address.model.tag.Tag;


/**
* Edits the details of an existing person in the address book.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public void put(Prefix prefix, String argValue) {
*/
public Optional<String> getValue(Prefix prefix) {
List<String> values = getAllValues(prefix);
return values.isEmpty() ? Optional.empty() :
Optional.of(values.get(values.size() - 1));
return values.isEmpty() ? Optional.empty()
: Optional.of(values.get(values.size() - 1));
}

/**
Expand Down
33 changes: 23 additions & 10 deletions src/main/java/seedu/address/logic/parser/ArgumentTokenizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

/**
* Tokenizes arguments string of the form: {@code preamble <prefix>value <prefix>value ...}<br>
* e.g. {@code some preamble text t/ 11.00 t/12.00 k/ m/ July} where prefixes are {@code t/ k/ m/}.<br>
* e.g. {@code some preamble text t/ 11.00 t/12.00 k/ m/ July} where prefixes are
* {@code t/ k/ m/}.<br>
* 1. An argument's value can be an empty string e.g. the value of {@code k/} in the above example.<br>
* 2. Leading and trailing whitespaces of an argument value will be discarded.<br>
* 3. An argument may be repeated and all its values will be accumulated e.g. the value of {@code t/}
* in the above example.<br>
* in the above example.<br>
*/
public class ArgumentTokenizer {

Expand All @@ -21,10 +22,10 @@ public class ArgumentTokenizer {
* given prefixes will be recognized in the arguments string.
*
* @param argsString Arguments string of the form:
* {@code preamble <prefix>value <prefix>value ...}
* {@code preamble <prefix>value <prefix>value ...}
* @param prefixes Prefixes to tokenize the arguments string with
* @return ArgumentMultimap object that maps prefixes to their
* arguments
* arguments
*/
public static ArgumentMultimap tokenize(String argsString, Prefix... prefixes) {
List<PrefixPosition> positions = findAllPrefixPositions(argsString, prefixes);
Expand All @@ -45,7 +46,11 @@ private static List<PrefixPosition> findAllPrefixPositions(String argsString, Pr
}

/**
* {@see findAllPrefixPositions}
* Finds the positions of all occurrences of {@code prefix} in the arguments string.
*
* @param argsString Arguments string of the form: {@code preamble <prefix>value <prefix>value ...}
* @param prefix Prefix to find in the arguments string
* @return List of zero-based prefix positions in the given arguments string
*/
private static List<PrefixPosition> findPrefixPositions(String argsString, Prefix prefix) {
List<PrefixPosition> positions = new ArrayList<>();
Expand All @@ -65,12 +70,16 @@ private static List<PrefixPosition> findPrefixPositions(String argsString, Prefi
* {@code argsString} starting from index {@code fromIndex}. An occurrence
* is valid if there is a whitespace before {@code prefix}. Returns -1 if no
* such occurrence can be found.
*
* E.g if {@code argsString} = "e/hip/900", {@code prefix} = "p/" and
* E.g. if {@code argsString} = "e/hip/900", {@code prefix} = "p/" and
* {@code fromIndex} = 0, this method returns -1 as there are no valid
* occurrences of "p/" with whitespace before it. However, if
* {@code argsString} = "e/hi p/900", {@code prefix} = "p/" and
* {@code fromIndex} = 0, this method returns 5.
*
* @param argsString Arguments string in which to search for the prefix
* @param prefix The prefix to find in the arguments string
* @param fromIndex The index from which to start searching
* @return The index of the first valid occurrence of the prefix, or -1 if not found
*/
private static int findPrefixPosition(String argsString, String prefix, int fromIndex) {
int prefixIndex = argsString.indexOf(" " + prefix, fromIndex);
Expand Down Expand Up @@ -115,10 +124,15 @@ private static ArgumentMultimap extractArguments(String argsString, List<PrefixP
/**
* Returns the trimmed value of the argument in the arguments string specified by {@code currentPrefixPosition}.
* The end position of the value is determined by {@code nextPrefixPosition}.
*
* @param argsString The arguments string containing the value
* @param currentPrefixPosition The current prefix position
* @param nextPrefixPosition The position of the next prefix
* @return The trimmed value of the argument
*/
private static String extractArgumentValue(String argsString,
PrefixPosition currentPrefixPosition,
PrefixPosition nextPrefixPosition) {
PrefixPosition currentPrefixPosition,
PrefixPosition nextPrefixPosition) {
Prefix prefix = currentPrefixPosition.getPrefix();

int valueStartPos = currentPrefixPosition.getStartPosition() + prefix.getPrefix().length();
Expand Down Expand Up @@ -147,5 +161,4 @@ Prefix getPrefix() {
return prefix;
}
}

}
14 changes: 12 additions & 2 deletions src/main/java/seedu/address/logic/parser/RemarkCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK;

import seedu.address.commons.core.index.Index;
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.logic.commands.RemarkCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.person.Remark;


/**
* Parses input arguments and creates a new RemarkCommand object.
*/
public class RemarkCommandParser implements Parser<RemarkCommand> {

/**
* Parses the given {@code String} of arguments in the context of the RemarkCommand
* and returns a RemarkCommand object for execution.
*
* @param args the input arguments string.
* @return a RemarkCommand object.
* @throws ParseException if the user input does not conform to the expected format.
*/
@Override
public RemarkCommand parse(String args) throws ParseException {
requireNonNull(args);
Expand Down
26 changes: 25 additions & 1 deletion src/main/java/seedu/address/model/person/Remark.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,52 @@

/**
* Represents a Person's remark in the address book.
* Guarantees: immutable; is always valid
* Guarantees: immutable; is always valid as declared in {@link #Remark(String)}.
*/
public class Remark {

/** The remark string of the person. */
public final String value;

/**
* Constructs a {@code Remark}.
*
* @param remark A valid remark string.
*/
public Remark(String remark) {
requireNonNull(remark);
value = remark;
}

/**
* Returns the remark string.
*
* @return the string value of the remark.
*/
@Override
public String toString() {
return value;
}

/**
* Compares this remark to the specified object. The result is true if and only if the argument
* is not null and is a {@code Remark} object that contains the same string value as this remark.
*
* @param other The object to compare this {@code Remark} against.
* @return true if the given object represents a {@code Remark} equivalent to this remark, false otherwise.
*/
@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Remark // instanceof handles nulls
&& value.equals(((Remark) other).value)); // state check
}

/**
* Returns the hash code for this remark.
*
* @return The hash code value for this remark.
*/
@Override
public int hashCode() {
return value.hashCode();
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@
public class SampleDataUtil {

public static final Remark EMPTY_REMARK = new Remark("");

/**
* Returns an array of sample persons.
*/
public static Person[] getSamplePersons() {
return new Person[] {
return new Person[]{
new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("[email protected]"),
new Address("Blk 30 Geylang Street 29, #06-40"), EMPTY_REMARK,
getTagSet("friends")),
Expand All @@ -43,7 +47,9 @@ public static Person[] getSamplePersons() {
};
}


/**
* Returns a sample {@code AddressBook} populated with sample persons.
*/
public static ReadOnlyAddressBook getSampleAddressBook() {
AddressBook sampleAb = new AddressBook();
for (Person samplePerson : getSamplePersons()) {
Expand All @@ -54,11 +60,14 @@ public static ReadOnlyAddressBook getSampleAddressBook() {

/**
* Returns a tag set containing the list of strings given.
*
* @param strings The tags to be added to the set.
* @return A set of {@code Tag} objects.
*/
public static Set<Tag> getTagSet(String... strings) {
return Arrays.stream(strings)
.map(Tag::new)
.collect(Collectors.toSet());
}

}

0 comments on commit 9937d76

Please sign in to comment.