Skip to content
This repository has been archived by the owner on Apr 13, 2020. It is now read-only.

Commit

Permalink
Merge pull request nus-cs2103-AY1920S1#2 from AY1920S1-CS2103-T11-1/m…
Browse files Browse the repository at this point in the history
…aster

pull from upstream
  • Loading branch information
meiannn authored Oct 11, 2019
2 parents 8e80679 + e10d1b4 commit e751180
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 35 deletions.
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public static Person[] getSamplePersons() {
public static Vehicle[] getSampleVehicles() {
return new Vehicle[] {
new Vehicle(new VehicleType("Ambulance"), new VehicleNumber("SGS2121G"),
new District("16 Upper East Coast"), new Availability("AVAILABLE")),
new District(1), new Availability("AVAILABLE")),
new Vehicle(new VehicleType("Ambulance"), new VehicleNumber("BBA2222F"),
new District("6 City Hall"), new Availability("BUSY")),
new District(6), new Availability("BUSY")),
new Vehicle(new VehicleType("Patrol Car"), new VehicleNumber("FKTH1221P"),
new District("20 Ang Mo Kio"), new Availability("AVAILABLE")),
new District(20), new Availability("AVAILABLE")),
new Vehicle(new VehicleType("Patrol Car"), new VehicleNumber("OLI4445C"),
new District("8 Little India"), new Availability("BUSY"))
new District(8), new Availability("BUSY"))
};
}

Expand Down
30 changes: 11 additions & 19 deletions src/main/java/seedu/address/model/vehicle/District.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,48 @@
import static seedu.address.commons.util.AppUtil.checkArgument;

/**
* Represents a district in the IMS.
* Guarantees: immutable; is valid as declared in {@link #isValidDistrict(String)}
* Represents a Person's in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidDistrict(int)}
*/
public class District {

public static final String MESSAGE_CONSTRAINTS =
"Districts should only contain alphanumeric characters and spaces, and it should not be blank";

/*
* The first character of the address must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/
public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*";
public static final int FIRST_DISTRICT = 1;
public static final int LAST_DISTRICT = 28;

public final String district;
public final int districtNum;

/**
* Constructs a {@code District}.
*
* @param d A valid District.
*/
public District(String d) {
public District(int d) {
requireNonNull(d);
checkArgument(isValidDistrict(d), MESSAGE_CONSTRAINTS);
district = d;
districtNum = d;
}

/**
* Returns true if a given string is a valid District.
*/
public static boolean isValidDistrict(String test) {
return test.matches(VALIDATION_REGEX);
public static boolean isValidDistrict(int test) {
return FIRST_DISTRICT <= test && test <= LAST_DISTRICT;
}


@Override
public String toString() {
return district;
return String.valueOf(districtNum);
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof District // instanceof handles nulls
&& district.equals(((District) other).district)); // state check
}

@Override
public int hashCode() {
return district.hashCode();
&& districtNum == ((District) other).districtNum); // state check
}

}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/seedu/address/storage/JsonAdaptedVehicle.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class JsonAdaptedVehicle {

private final String vehicleType;
private final String vehicleNumber;
private final String district;
private final int districtNum;
private final String availability;

/**
Expand All @@ -28,11 +28,11 @@ class JsonAdaptedVehicle {
@JsonCreator
public JsonAdaptedVehicle(@JsonProperty("vehicleType") String vehicleType,
@JsonProperty("vehicleNumber") String vehicleNumber,
@JsonProperty("district") String district,
@JsonProperty("district") int districtNum,
@JsonProperty("availability") String availability) {
this.vehicleType = vehicleType;
this.vehicleNumber = vehicleNumber;
this.district = district;
this.districtNum = districtNum;
this.availability = availability;
}

Expand All @@ -42,7 +42,7 @@ public JsonAdaptedVehicle(@JsonProperty("vehicleType") String vehicleType,
public JsonAdaptedVehicle(Vehicle source) {
vehicleType = source.getVehicleType().vehicleType;
vehicleNumber = source.getVehicleNumber().vehicleNumber;
district = source.getDistrict().district;
districtNum = source.getDistrict().districtNum;
availability = source.getAvailability().getAvailabilityTag();
}

Expand Down Expand Up @@ -70,14 +70,14 @@ public Vehicle toModelType() throws IllegalValueException {
}
final VehicleType modelVehicleType = new VehicleType(vehicleType);

if (district == null) {
if (districtNum == 0) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT,
District.class.getSimpleName()));
}
if (!District.isValidDistrict(district)) {
if (!District.isValidDistrict(districtNum)) {
throw new IllegalValueException(District.MESSAGE_CONSTRAINTS);
}
final District modelDistrict = new District(district);
final District modelDistrict = new District(districtNum);

if (availability == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/VehicleCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public VehicleCard(Vehicle vehicle, int displayedIndex) {
id.setText(displayedIndex + ". ");
vehicleNumber.setText(vehicle.getVehicleNumber().vehicleNumber);
vehicleType.setText(vehicle.getVehicleType().vehicleType);
district.setText(vehicle.getDistrict().district);
district.setText(String.valueOf(vehicle.getDistrict().districtNum));
availability.setText(vehicle.getAvailability().getAvailabilityTag());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
"vehicles": [ {
"vehicleType": "Ambulance",
"vehicleNumber": "AAA1111A",
"district": "1 Singapore",
"district": 1,
"availability": "AVAILABLE"
}, {
"vehicleType": "Ambulance",
"vehicleNumber": "AAA1111A",
"district": "1 Singapore",
"district": 1,
"availability": "AVAILABLE"
}]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"vehicles": [{
"vehicleType": "Bus",
"vehicleNumber": "invalid####",
"district": "-",
"district": 0,
"availability": "BYE"
}]
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"vehicles": [{
"vehicleType": "Patrol Car",
"vehicleNumber": "SBH3100F",
"district": "16 Upper East Coast",
"district": 16,
"availability": "BUSY"
}]
}

0 comments on commit e751180

Please sign in to comment.