Skip to content

Commit

Permalink
[94] Fix compiler warnings (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
damithc authored Sep 27, 2016
1 parent daf5657 commit 9686528
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 37 deletions.
22 changes: 3 additions & 19 deletions src/main/java/seedu/address/commons/util/CollectionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.Collection;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
Expand All @@ -22,29 +21,14 @@ public static boolean isAnyNull(Object... items) {
return false;
}

/**
* Throws an assertion error if any of the given arguments is null.
*/
public static void assertNotNull(Object... items) {
int argIndex = 0;
for (Object item : items) {
if (Objects.isNull(item)) {
throw new AssertionError("Argument at index " + argIndex + " is null");
}
argIndex++;
}
}


/**
* Throws an assertion error if the collection or any item in it is null.
*/
public static void assertNoNullElements(Collection<?> items) {
assertNotNull(items);
for (Object item : items) {
if (Objects.isNull(item)) {
throw new AssertionError("Collection has null element(s)");
}
}
assert items != null;
assert !isAnyNull(items);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public ReadOnlyPerson getPerson() {

@Override
public CommandResult execute() {
CollectionUtil.assertNotNull(model);
assert model != null;
try {
model.addPerson(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public ClearCommand() {}

@Override
public CommandResult execute() {
CollectionUtil.assertNotNull(model);
assert model != null;
model.resetData(AddressBook.getEmptyAddressBook());
return new CommandResult(MESSAGE_SUCCESS);
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/logic/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ public class CommandResult {
private final List<? extends ReadOnlyPerson> relevantPersons;

public CommandResult(String feedbackToUser) {
CollectionUtil.assertNotNull(feedbackToUser);
assert feedbackToUser != null;
this.feedbackToUser = feedbackToUser;
relevantPersons = null;
}

public CommandResult(String feedbackToUser, List<? extends ReadOnlyPerson> relevantPersons) {
CollectionUtil.assertNotNull(feedbackToUser, relevantPersons);
assert feedbackToUser != null;
assert relevantPersons != null;
this.feedbackToUser = feedbackToUser;
this.relevantPersons = relevantPersons;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/person/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Address {
* @throws IllegalValueException if given address string is invalid.
*/
public Address(String address) throws IllegalValueException {
CollectionUtil.assertNotNull(address);
assert address != null;
if (!isValidAddress(address)) {
throw new IllegalValueException(MESSAGE_ADDRESS_CONSTRAINTS);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/person/Email.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Email {
* @throws IllegalValueException if given email address string is invalid.
*/
public Email(String email) throws IllegalValueException {
CollectionUtil.assertNotNull(email);
assert email != null;
email = email.trim();
if (!isValidEmail(email)) {
throw new IllegalValueException(MESSAGE_EMAIL_CONSTRAINTS);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/person/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Name {
* @throws IllegalValueException if given name string is invalid.
*/
public Name(String name) throws IllegalValueException {
CollectionUtil.assertNotNull(name);
assert name != null;
name = name.trim();
if (!isValidName(name)) {
throw new IllegalValueException(MESSAGE_NAME_CONSTRAINTS);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Person implements ReadOnlyPerson {
* Every field must be present and not null.
*/
public Person(Name name, Phone phone, Email email, Address address, UniqueTagList tags) {
CollectionUtil.assertNotNull(name, phone, email, address, tags);
assert !CollectionUtil.isAnyNull(name, phone, email, address, tags);
this.name = name;
this.phone = phone;
this.email = email;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/person/Phone.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Phone {
* @throws IllegalValueException if given phone string is invalid.
*/
public Phone(String phone) throws IllegalValueException {
CollectionUtil.assertNotNull(phone);
assert phone != null;
phone = phone.trim();
if (!isValidPhone(phone)) {
throw new IllegalValueException(MESSAGE_PHONE_CONSTRAINTS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public UniquePersonList() {}
* Varargs/array constructor, enforces no nulls or duplicates.
*/
public UniquePersonList(Person... persons) throws DuplicatePersonException {
CollectionUtil.assertNotNull(persons);
assert ! CollectionUtil.isAnyNull((Object[]) persons);
final List<Person> initialPersons = Arrays.asList(persons);
if (!CollectionUtil.elementsAreUnique(initialPersons)) {
throw new DuplicatePersonException();
Expand Down Expand Up @@ -97,7 +97,7 @@ public Set<Person> toSet() {
* Returns true if the list contains an equivalent person as the given argument.
*/
public boolean contains(ReadOnlyPerson toCheck) {
CollectionUtil.assertNotNull(toCheck);
assert toCheck != null;
return internalList.contains(toCheck);
}

Expand All @@ -107,7 +107,7 @@ public boolean contains(ReadOnlyPerson toCheck) {
* @throws DuplicatePersonException if the person to add is a duplicate of an existing person in the list.
*/
public void add(Person toAdd) throws DuplicatePersonException {
CollectionUtil.assertNotNull(toAdd);
assert toAdd != null;
if (contains(toAdd)) {
throw new DuplicatePersonException();
}
Expand All @@ -120,7 +120,7 @@ public void add(Person toAdd) throws DuplicatePersonException {
* @throws PersonNotFoundException if no such person could be found in the list.
*/
public boolean remove(ReadOnlyPerson toRemove) throws PersonNotFoundException {
CollectionUtil.assertNotNull(toRemove);
assert toRemove != null;
final boolean personFoundAndDeleted = internalList.remove(toRemove);
if (!personFoundAndDeleted) {
throw new PersonNotFoundException();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/tag/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Tag() {
* @throws IllegalValueException if the given tag name string is invalid.
*/
public Tag(String name) throws IllegalValueException {
CollectionUtil.assertNotNull(name);
assert name != null;
name = name.trim();
if (!isValidTagName(name)) {
throw new IllegalValueException(MESSAGE_TAG_CONSTRAINTS);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/model/tag/UniqueTagList.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public UniqueTagList() {}
* Varargs/array constructor, enforces no nulls or duplicates.
*/
public UniqueTagList(Tag... tags) throws DuplicateTagException {
CollectionUtil.assertNotNull(tags);
assert !CollectionUtil.isAnyNull((Object[]) tags);
final List<Tag> initialTags = Arrays.asList(tags);
if (!CollectionUtil.elementsAreUnique(initialTags)) {
throw new DuplicateTagException();
Expand Down Expand Up @@ -116,7 +116,7 @@ public void mergeFrom(UniqueTagList tags) {
* Checks if the list contains an equivalent Tag as the given argument.
*/
public boolean contains(Tag toCheck) {
CollectionUtil.assertNotNull(toCheck);
assert toCheck != null;
return internalList.contains(toCheck);
}

Expand All @@ -126,7 +126,7 @@ public boolean contains(Tag toCheck) {
* @throws DuplicateTagException if the Tag to add is a duplicate of an existing Tag in the list.
*/
public void add(Tag toAdd) throws DuplicateTagException {
CollectionUtil.assertNotNull(toAdd);
assert toAdd != null;
if (contains(toAdd)) {
throw new DuplicateTagException();
}
Expand All @@ -139,7 +139,7 @@ public void add(Tag toAdd) throws DuplicateTagException {
* @throws TagNotFoundException if no such Tag could be found in the list.
*/
public boolean remove(Tag toRemove) throws TagNotFoundException {
CollectionUtil.assertNotNull(toRemove);
assert toRemove != null;
final boolean tagFoundAndDeleted = internalList.remove(toRemove);
if (!tagFoundAndDeleted) {
throw new TagNotFoundException();
Expand Down

0 comments on commit 9686528

Please sign in to comment.