Skip to content

Commit 9686528

Browse files
authored
[94] Fix compiler warnings (#117)
1 parent daf5657 commit 9686528

File tree

12 files changed

+22
-37
lines changed

12 files changed

+22
-37
lines changed

src/main/java/seedu/address/commons/util/CollectionUtil.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.util.Collection;
44
import java.util.HashSet;
5-
import java.util.Objects;
65
import java.util.Set;
76

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

25-
/**
26-
* Throws an assertion error if any of the given arguments is null.
27-
*/
28-
public static void assertNotNull(Object... items) {
29-
int argIndex = 0;
30-
for (Object item : items) {
31-
if (Objects.isNull(item)) {
32-
throw new AssertionError("Argument at index " + argIndex + " is null");
33-
}
34-
argIndex++;
35-
}
36-
}
24+
3725

3826
/**
3927
* Throws an assertion error if the collection or any item in it is null.
4028
*/
4129
public static void assertNoNullElements(Collection<?> items) {
42-
assertNotNull(items);
43-
for (Object item : items) {
44-
if (Objects.isNull(item)) {
45-
throw new AssertionError("Collection has null element(s)");
46-
}
47-
}
30+
assert items != null;
31+
assert !isAnyNull(items);
4832
}
4933

5034
/**

src/main/java/seedu/address/logic/commands/AddCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public ReadOnlyPerson getPerson() {
5555

5656
@Override
5757
public CommandResult execute() {
58-
CollectionUtil.assertNotNull(model);
58+
assert model != null;
5959
try {
6060
model.addPerson(toAdd);
6161
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));

src/main/java/seedu/address/logic/commands/ClearCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public ClearCommand() {}
1919

2020
@Override
2121
public CommandResult execute() {
22-
CollectionUtil.assertNotNull(model);
22+
assert model != null;
2323
model.resetData(AddressBook.getEmptyAddressBook());
2424
return new CommandResult(MESSAGE_SUCCESS);
2525
}

src/main/java/seedu/address/logic/commands/CommandResult.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ public class CommandResult {
1313
private final List<? extends ReadOnlyPerson> relevantPersons;
1414

1515
public CommandResult(String feedbackToUser) {
16-
CollectionUtil.assertNotNull(feedbackToUser);
16+
assert feedbackToUser != null;
1717
this.feedbackToUser = feedbackToUser;
1818
relevantPersons = null;
1919
}
2020

2121
public CommandResult(String feedbackToUser, List<? extends ReadOnlyPerson> relevantPersons) {
22-
CollectionUtil.assertNotNull(feedbackToUser, relevantPersons);
22+
assert feedbackToUser != null;
23+
assert relevantPersons != null;
2324
this.feedbackToUser = feedbackToUser;
2425
this.relevantPersons = relevantPersons;
2526
}

src/main/java/seedu/address/model/person/Address.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class Address {
2222
* @throws IllegalValueException if given address string is invalid.
2323
*/
2424
public Address(String address) throws IllegalValueException {
25-
CollectionUtil.assertNotNull(address);
25+
assert address != null;
2626
if (!isValidAddress(address)) {
2727
throw new IllegalValueException(MESSAGE_ADDRESS_CONSTRAINTS);
2828
}

src/main/java/seedu/address/model/person/Email.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class Email {
2323
* @throws IllegalValueException if given email address string is invalid.
2424
*/
2525
public Email(String email) throws IllegalValueException {
26-
CollectionUtil.assertNotNull(email);
26+
assert email != null;
2727
email = email.trim();
2828
if (!isValidEmail(email)) {
2929
throw new IllegalValueException(MESSAGE_EMAIL_CONSTRAINTS);

src/main/java/seedu/address/model/person/Name.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class Name {
2424
* @throws IllegalValueException if given name string is invalid.
2525
*/
2626
public Name(String name) throws IllegalValueException {
27-
CollectionUtil.assertNotNull(name);
27+
assert name != null;
2828
name = name.trim();
2929
if (!isValidName(name)) {
3030
throw new IllegalValueException(MESSAGE_NAME_CONSTRAINTS);

src/main/java/seedu/address/model/person/Person.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class Person implements ReadOnlyPerson {
2222
* Every field must be present and not null.
2323
*/
2424
public Person(Name name, Phone phone, Email email, Address address, UniqueTagList tags) {
25-
CollectionUtil.assertNotNull(name, phone, email, address, tags);
25+
assert !CollectionUtil.isAnyNull(name, phone, email, address, tags);
2626
this.name = name;
2727
this.phone = phone;
2828
this.email = email;

src/main/java/seedu/address/model/person/Phone.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class Phone {
2121
* @throws IllegalValueException if given phone string is invalid.
2222
*/
2323
public Phone(String phone) throws IllegalValueException {
24-
CollectionUtil.assertNotNull(phone);
24+
assert phone != null;
2525
phone = phone.trim();
2626
if (!isValidPhone(phone)) {
2727
throw new IllegalValueException(MESSAGE_PHONE_CONSTRAINTS);

src/main/java/seedu/address/model/person/UniquePersonList.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public UniquePersonList() {}
4343
* Varargs/array constructor, enforces no nulls or duplicates.
4444
*/
4545
public UniquePersonList(Person... persons) throws DuplicatePersonException {
46-
CollectionUtil.assertNotNull(persons);
46+
assert ! CollectionUtil.isAnyNull((Object[]) persons);
4747
final List<Person> initialPersons = Arrays.asList(persons);
4848
if (!CollectionUtil.elementsAreUnique(initialPersons)) {
4949
throw new DuplicatePersonException();
@@ -97,7 +97,7 @@ public Set<Person> toSet() {
9797
* Returns true if the list contains an equivalent person as the given argument.
9898
*/
9999
public boolean contains(ReadOnlyPerson toCheck) {
100-
CollectionUtil.assertNotNull(toCheck);
100+
assert toCheck != null;
101101
return internalList.contains(toCheck);
102102
}
103103

@@ -107,7 +107,7 @@ public boolean contains(ReadOnlyPerson toCheck) {
107107
* @throws DuplicatePersonException if the person to add is a duplicate of an existing person in the list.
108108
*/
109109
public void add(Person toAdd) throws DuplicatePersonException {
110-
CollectionUtil.assertNotNull(toAdd);
110+
assert toAdd != null;
111111
if (contains(toAdd)) {
112112
throw new DuplicatePersonException();
113113
}
@@ -120,7 +120,7 @@ public void add(Person toAdd) throws DuplicatePersonException {
120120
* @throws PersonNotFoundException if no such person could be found in the list.
121121
*/
122122
public boolean remove(ReadOnlyPerson toRemove) throws PersonNotFoundException {
123-
CollectionUtil.assertNotNull(toRemove);
123+
assert toRemove != null;
124124
final boolean personFoundAndDeleted = internalList.remove(toRemove);
125125
if (!personFoundAndDeleted) {
126126
throw new PersonNotFoundException();

0 commit comments

Comments
 (0)