forked from nus-cs2103-AY1819S1/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into change-tag-colour
- Loading branch information
Showing
8 changed files
with
267 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ lib/* | |
*.log | ||
*.log.* | ||
*.csv | ||
config.json | ||
src/test/data/sandbox/ | ||
preferences.json | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"authors": | ||
[ | ||
{ | ||
"githubId": "FongYuan", | ||
"displayName": "Lim Fong Yuan", | ||
"authorNames": ["Fong Yuan", "FongYuan"] | ||
}, | ||
{ | ||
"githubId": "Kelly9373", | ||
"displayName": "Liu Xiaohang", | ||
"authorNames": ["Liu Xiaohang", "Kelly9373"] | ||
}, | ||
{ | ||
"githubId": "prokarius", | ||
"displayName": "David Kum", | ||
"authorNames": ["David Kum", "prokarius"] | ||
}, | ||
{ | ||
"githubId": "wn96", | ||
"displayName": "Ang Wei Neng", | ||
"authorNames": ["Ang Wei Neng", "wn96", "weineng"] | ||
}, | ||
{ | ||
"githubId": "xantho09", | ||
"displayName": "Muhammad Irham Rasyidi Bin Zainal", | ||
"authorNames": ["xantho09", "Muhammad Irham Rasyidi Bin Zainal"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package seedu.address.model.bike; | ||
|
||
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; | ||
|
||
import java.util.Objects; | ||
|
||
import seedu.address.model.loan.Name; | ||
|
||
/** | ||
* Represents a Bike in the loan book. | ||
* Guarantees: details are present and not null, field values are validated, immutable. | ||
*/ | ||
public class Bike { | ||
|
||
//Identity fields | ||
/** | ||
* The name of the Bike also doubles as its ID, i.e. it should be unique as it is used to identify this bike. | ||
* For now, borrow the Name class from Loan. It can be its own separate class once the difference matters. | ||
*/ | ||
private final Name name; | ||
|
||
// Data fields | ||
private final BikeStatus status; | ||
|
||
/** | ||
* Every field must be present and not null. | ||
*/ | ||
public Bike(Name name) { | ||
requireAllNonNull(name); | ||
this.name = name; | ||
|
||
this.status = BikeStatus.AVAILABLE; | ||
} | ||
|
||
public Name getName() { | ||
return name; | ||
} | ||
|
||
public BikeStatus getStatus() { | ||
return status; | ||
} | ||
|
||
public boolean isAvailable() { | ||
return this.getStatus().equals(BikeStatus.AVAILABLE); | ||
} | ||
|
||
/** | ||
* Returns true iff both bikes have the same name. | ||
* This defines a weaker notion of equality between two bikes. | ||
*/ | ||
public boolean isSameBike(Bike otherBike) { | ||
if (otherBike == this) { | ||
return true; | ||
} | ||
|
||
return otherBike != null | ||
&& otherBike.getName().equals(this.getName()); | ||
} | ||
|
||
/** | ||
* Returns true if both bikes have the same identity and data fields. | ||
* This defines a stronger notion of equality between two bikes. | ||
*/ | ||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
if (!(other instanceof Bike)) { | ||
return false; | ||
} | ||
|
||
Bike otherBike = (Bike) other; | ||
return otherBike.getName().equals(getName()) | ||
&& otherBike.getStatus().equals(getStatus()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
// use this method for custom fields hashing instead of implementing your own | ||
return Objects.hash(name, status); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
final StringBuilder builder = new StringBuilder(); | ||
builder.append(getName()) | ||
.append(" Status: ").append(getStatus()); | ||
return builder.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package seedu.address.model.bike; | ||
|
||
/** | ||
* Represents the status of a bike in the loan book. | ||
*/ | ||
public enum BikeStatus { | ||
AVAILABLE { | ||
public String toString() { | ||
return "Available"; | ||
} | ||
}, | ||
LOANED_OUT { | ||
public String toString() { | ||
return "Loaned Out"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package seedu.address.model.bike; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
|
||
import seedu.address.testutil.BikeBuilder; | ||
|
||
public class BikeTest { | ||
|
||
private static final Bike BIKE1 = new BikeBuilder().withName("B001").build(); | ||
private static final Bike BIKE2 = new BikeBuilder().withName("B002").build(); | ||
|
||
@Test | ||
public void isSameBike() { | ||
// same object -> returns true | ||
assertTrue(BIKE1.isSameBike(BIKE1)); | ||
|
||
// null -> returns false | ||
assertFalse(BIKE1.isSameBike(null)); | ||
|
||
// different name -> returns false | ||
Bike editedBike1 = new BikeBuilder(BIKE1).withName("B002").build(); | ||
assertFalse(BIKE1.isSameBike(editedBike1)); | ||
} | ||
|
||
@Test | ||
public void equals() { | ||
// same values -> returns true | ||
Bike bike1Copy = new BikeBuilder(BIKE1).build(); | ||
assertTrue(BIKE1.equals(bike1Copy)); | ||
|
||
// same object -> returns true | ||
assertTrue(BIKE1.equals(BIKE1)); | ||
|
||
// null -> returns false | ||
assertFalse(BIKE1 == null); | ||
|
||
// different type -> returns false | ||
assertFalse(BIKE1.equals(5)); | ||
|
||
// different bike -> returns false | ||
assertFalse(BIKE1.equals(BIKE2)); | ||
|
||
// different name -> returns false | ||
Bike editedBike1 = new BikeBuilder(BIKE1).withName("B002").build(); | ||
assertFalse(BIKE1.equals(editedBike1)); | ||
} | ||
|
||
@Test | ||
public void toStringTest() { | ||
assertEquals(BIKE1.toString(), "B001 Status: Available"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package seedu.address.testutil; | ||
|
||
import seedu.address.model.bike.Bike; | ||
import seedu.address.model.loan.Name; | ||
|
||
/** | ||
* A utility class to help with building Bike objects. | ||
*/ | ||
public class BikeBuilder { | ||
public static final String DEFAULT_NAME = "BIKE001"; | ||
|
||
private Name name; | ||
|
||
public BikeBuilder() { | ||
name = new Name(DEFAULT_NAME); | ||
} | ||
|
||
/** | ||
* Initializes the BikeBuilder with the data of {@code bikeToCopy}. | ||
*/ | ||
public BikeBuilder(Bike bikeToCopy) { | ||
name = bikeToCopy.getName(); | ||
} | ||
|
||
/** | ||
* Sets the {@code Name} of the {@code Bike} that we are building. | ||
*/ | ||
public BikeBuilder withName(String name) { | ||
this.name = new Name(name); | ||
return this; | ||
} | ||
|
||
public Bike build() { | ||
return new Bike(name); | ||
} | ||
} |