1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

replace IllegalStateException with IllegalArgumentException where there is bad input

This commit is contained in:
oblonski 2016-06-15 14:06:26 +02:00
parent 5c6ef8b8d3
commit 3966590fc7
26 changed files with 146 additions and 171 deletions

View file

@ -97,7 +97,7 @@ public class Capacity {
double sumQuotients = 0.0; double sumQuotients = 0.0;
for (int index = 0; index < Math.max(numerator.getNuOfDimensions(), denominator.getNuOfDimensions()); index++) { for (int index = 0; index < Math.max(numerator.getNuOfDimensions(), denominator.getNuOfDimensions()); index++) {
if (numerator.get(index) != 0 && denominator.get(index) == 0) { if (numerator.get(index) != 0 && denominator.get(index) == 0) {
throw new IllegalStateException("numerator > 0 and denominator = 0. cannot divide by 0"); throw new IllegalArgumentException("numerator > 0 and denominator = 0. cannot divide by 0");
} else if (numerator.get(index) == 0 && denominator.get(index) == 0) { } else if (numerator.get(index) == 0 && denominator.get(index) == 0) {
continue; continue;
} else { } else {

View file

@ -85,7 +85,7 @@ public final class Location implements HasIndex, HasId {
public Location build() { public Location build() {
if (id == null && coordinate == null) { if (id == null && coordinate == null) {
if (index == -1) throw new IllegalStateException("either id or coordinate or index must be set"); if (index == -1) throw new IllegalArgumentException("either id or coordinate or index must be set");
} }
if (coordinate != null && id == null) { if (coordinate != null && id == null) {
this.id = coordinate.toString(); this.id = coordinate.toString();

View file

@ -222,9 +222,9 @@ public class VehicleRoutingProblem {
*/ */
public Builder addJob(AbstractJob job) { public Builder addJob(AbstractJob job) {
if (tentativeJobs.containsKey(job.getId())) if (tentativeJobs.containsKey(job.getId()))
throw new IllegalStateException("vehicle routing problem already contains a service or shipment with id " + job.getId() + ". make sure you use unique ids for all services and shipments"); throw new IllegalArgumentException("vehicle routing problem already contains a service or shipment with id " + job.getId() + ". make sure you use unique ids for all services and shipments");
if (!(job instanceof Service || job instanceof Shipment)) if (!(job instanceof Service || job instanceof Shipment))
throw new IllegalStateException("job must be either a service or a shipment"); throw new IllegalArgumentException("job must be either a service or a shipment");
job.setIndex(jobIndexCounter); job.setIndex(jobIndexCounter);
incJobIndexCounter(); incJobIndexCounter();
tentativeJobs.put(job.getId(), job); tentativeJobs.put(job.getId(), job);
@ -351,7 +351,7 @@ public class VehicleRoutingProblem {
* */ * */
public Builder addVehicle(Vehicle vehicle) { public Builder addVehicle(Vehicle vehicle) {
if (!(vehicle instanceof AbstractVehicle)) if (!(vehicle instanceof AbstractVehicle))
throw new IllegalStateException("vehicle must be an AbstractVehicle"); throw new IllegalArgumentException("vehicle must be an AbstractVehicle");
return addVehicle((AbstractVehicle) vehicle); return addVehicle((AbstractVehicle) vehicle);
} }
@ -363,7 +363,7 @@ public class VehicleRoutingProblem {
*/ */
public Builder addVehicle(AbstractVehicle vehicle) { public Builder addVehicle(AbstractVehicle vehicle) {
if(addedVehicleIds.contains(vehicle.getId())){ if(addedVehicleIds.contains(vehicle.getId())){
throw new IllegalStateException("problem already contains a vehicle with id " + vehicle.getId() + ". choose unique ids for each vehicle."); throw new IllegalArgumentException("problem already contains a vehicle with id " + vehicle.getId() + ". choose unique ids for each vehicle.");
} }
else addedVehicleIds.add(vehicle.getId()); else addedVehicleIds.add(vehicle.getId());
if (!uniqueVehicles.contains(vehicle)) { if (!uniqueVehicles.contains(vehicle)) {

View file

@ -193,9 +193,9 @@ public class VrpXMLReader {
Driver driver = DriverImpl.noDriver(); Driver driver = DriverImpl.noDriver();
String vehicleId = routeConfig.getString("vehicleId"); String vehicleId = routeConfig.getString("vehicleId");
Vehicle vehicle = getVehicle(vehicleId); Vehicle vehicle = getVehicle(vehicleId);
if (vehicle == null) throw new IllegalStateException("vehicle is missing."); if (vehicle == null) throw new IllegalArgumentException("vehicle is missing.");
String start = routeConfig.getString("start"); String start = routeConfig.getString("start");
if (start == null) throw new IllegalStateException("route start-time is missing."); if (start == null) throw new IllegalArgumentException("route start-time is missing.");
double departureTime = Double.parseDouble(start); double departureTime = Double.parseDouble(start);
VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver); VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver);
@ -204,7 +204,7 @@ public class VrpXMLReader {
List<HierarchicalConfiguration> actConfigs = routeConfig.configurationsAt("act"); List<HierarchicalConfiguration> actConfigs = routeConfig.configurationsAt("act");
for (HierarchicalConfiguration actConfig : actConfigs) { for (HierarchicalConfiguration actConfig : actConfigs) {
String type = actConfig.getString("[@type]"); String type = actConfig.getString("[@type]");
if (type == null) throw new IllegalStateException("act[@type] is missing."); if (type == null) throw new IllegalArgumentException("act[@type] is missing.");
double arrTime = 0.; double arrTime = 0.;
double endTime = 0.; double endTime = 0.;
String arrTimeS = actConfig.getString("arrTime"); String arrTimeS = actConfig.getString("arrTime");
@ -221,24 +221,24 @@ public class VrpXMLReader {
if (serviceId != null) { if (serviceId != null) {
Service service = getService(serviceId); Service service = getService(serviceId);
if (service == null) if (service == null)
throw new IllegalStateException("service to serviceId " + serviceId + " is missing (reference in one of your initial routes). make sure you define the service you refer to here in <services> </services>."); throw new IllegalArgumentException("service to serviceId " + serviceId + " is missing (reference in one of your initial routes). make sure you define the service you refer to here in <services> </services>.");
//!!!since job is part of initial route, it does not belong to jobs in problem, i.e. variable jobs that can be assigned/scheduled //!!!since job is part of initial route, it does not belong to jobs in problem, i.e. variable jobs that can be assigned/scheduled
freezedJobIds.add(serviceId); freezedJobIds.add(serviceId);
routeBuilder.addService(service); routeBuilder.addService(service);
} else { } else {
String shipmentId = actConfig.getString("shipmentId"); String shipmentId = actConfig.getString("shipmentId");
if (shipmentId == null) if (shipmentId == null)
throw new IllegalStateException("either serviceId or shipmentId is missing"); throw new IllegalArgumentException("either serviceId or shipmentId is missing");
Shipment shipment = getShipment(shipmentId); Shipment shipment = getShipment(shipmentId);
if (shipment == null) if (shipment == null)
throw new IllegalStateException("shipment to shipmentId " + shipmentId + " is missing (reference in one of your initial routes). make sure you define the shipment you refer to here in <shipments> </shipments>."); throw new IllegalArgumentException("shipment to shipmentId " + shipmentId + " is missing (reference in one of your initial routes). make sure you define the shipment you refer to here in <shipments> </shipments>.");
freezedJobIds.add(shipmentId); freezedJobIds.add(shipmentId);
if (type.equals("pickupShipment")) { if (type.equals("pickupShipment")) {
routeBuilder.addPickup(shipment); routeBuilder.addPickup(shipment);
} else if (type.equals("deliverShipment")) { } else if (type.equals("deliverShipment")) {
routeBuilder.addDelivery(shipment); routeBuilder.addDelivery(shipment);
} else } else
throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here"); throw new IllegalArgumentException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here");
} }
} }
} }
@ -262,20 +262,20 @@ public class VrpXMLReader {
Driver driver = DriverImpl.noDriver(); Driver driver = DriverImpl.noDriver();
String vehicleId = routeConfig.getString("vehicleId"); String vehicleId = routeConfig.getString("vehicleId");
Vehicle vehicle = getVehicle(vehicleId); Vehicle vehicle = getVehicle(vehicleId);
if (vehicle == null) throw new IllegalStateException("vehicle is missing."); if (vehicle == null) throw new IllegalArgumentException("vehicle is missing.");
String start = routeConfig.getString("start"); String start = routeConfig.getString("start");
if (start == null) throw new IllegalStateException("route start-time is missing."); if (start == null) throw new IllegalArgumentException("route start-time is missing.");
double departureTime = Double.parseDouble(start); double departureTime = Double.parseDouble(start);
String end = routeConfig.getString("end"); String end = routeConfig.getString("end");
if (end == null) throw new IllegalStateException("route end-time is missing."); if (end == null) throw new IllegalArgumentException("route end-time is missing.");
VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver); VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver);
routeBuilder.setDepartureTime(departureTime); routeBuilder.setDepartureTime(departureTime);
List<HierarchicalConfiguration> actConfigs = routeConfig.configurationsAt("act"); List<HierarchicalConfiguration> actConfigs = routeConfig.configurationsAt("act");
for (HierarchicalConfiguration actConfig : actConfigs) { for (HierarchicalConfiguration actConfig : actConfigs) {
String type = actConfig.getString("[@type]"); String type = actConfig.getString("[@type]");
if (type == null) throw new IllegalStateException("act[@type] is missing."); if (type == null) throw new IllegalArgumentException("act[@type] is missing.");
double arrTime = 0.; double arrTime = 0.;
double endTime = 0.; double endTime = 0.;
String arrTimeS = actConfig.getString("arrTime"); String arrTimeS = actConfig.getString("arrTime");
@ -294,16 +294,16 @@ public class VrpXMLReader {
} else { } else {
String shipmentId = actConfig.getString("shipmentId"); String shipmentId = actConfig.getString("shipmentId");
if (shipmentId == null) if (shipmentId == null)
throw new IllegalStateException("either serviceId or shipmentId is missing"); throw new IllegalArgumentException("either serviceId or shipmentId is missing");
Shipment shipment = getShipment(shipmentId); Shipment shipment = getShipment(shipmentId);
if (shipment == null) if (shipment == null)
throw new IllegalStateException("shipment with id " + shipmentId + " does not exist."); throw new IllegalArgumentException("shipment with id " + shipmentId + " does not exist.");
if (type.equals("pickupShipment")) { if (type.equals("pickupShipment")) {
routeBuilder.addPickup(shipment); routeBuilder.addPickup(shipment);
} else if (type.equals("deliverShipment")) { } else if (type.equals("deliverShipment")) {
routeBuilder.addDelivery(shipment); routeBuilder.addDelivery(shipment);
} else } else
throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here"); throw new IllegalArgumentException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here");
} }
} }
} }
@ -315,7 +315,7 @@ public class VrpXMLReader {
String jobId = unassignedJobConfig.getString("[@id]"); String jobId = unassignedJobConfig.getString("[@id]");
Job job = getShipment(jobId); Job job = getShipment(jobId);
if (job == null) job = getService(jobId); if (job == null) job = getService(jobId);
if (job == null) throw new IllegalStateException("cannot find unassignedJob with id " + jobId); if (job == null) throw new IllegalArgumentException("cannot find unassignedJob with id " + jobId);
solution.getUnassignedJobs().add(job); solution.getUnassignedJobs().add(job);
} }
@ -351,15 +351,15 @@ public class VrpXMLReader {
List<HierarchicalConfiguration> shipmentConfigs = config.configurationsAt("shipments.shipment"); List<HierarchicalConfiguration> shipmentConfigs = config.configurationsAt("shipments.shipment");
for (HierarchicalConfiguration shipmentConfig : shipmentConfigs) { for (HierarchicalConfiguration shipmentConfig : shipmentConfigs) {
String id = shipmentConfig.getString("[@id]"); String id = shipmentConfig.getString("[@id]");
if (id == null) throw new IllegalStateException("shipment[@id] is missing."); if (id == null) throw new IllegalArgumentException("shipment[@id] is missing.");
String capacityString = shipmentConfig.getString("capacity-demand"); String capacityString = shipmentConfig.getString("capacity-demand");
boolean capacityDimensionsExist = shipmentConfig.containsKey("capacity-dimensions.dimension(0)"); boolean capacityDimensionsExist = shipmentConfig.containsKey("capacity-dimensions.dimension(0)");
if (capacityString == null && !capacityDimensionsExist) { if (capacityString == null && !capacityDimensionsExist) {
throw new IllegalStateException("capacity of shipment is not set. use 'capacity-dimensions'"); throw new IllegalArgumentException("capacity of shipment is not set. use 'capacity-dimensions'");
} }
if (capacityString != null && capacityDimensionsExist) { if (capacityString != null && capacityDimensionsExist) {
throw new IllegalStateException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'."); throw new IllegalArgumentException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'.");
} }
Shipment.Builder builder; Shipment.Builder builder;
@ -475,17 +475,17 @@ public class VrpXMLReader {
List<HierarchicalConfiguration> serviceConfigs = vrpProblem.configurationsAt("services.service"); List<HierarchicalConfiguration> serviceConfigs = vrpProblem.configurationsAt("services.service");
for (HierarchicalConfiguration serviceConfig : serviceConfigs) { for (HierarchicalConfiguration serviceConfig : serviceConfigs) {
String id = serviceConfig.getString("[@id]"); String id = serviceConfig.getString("[@id]");
if (id == null) throw new IllegalStateException("service[@id] is missing."); if (id == null) throw new IllegalArgumentException("service[@id] is missing.");
String type = serviceConfig.getString("[@type]"); String type = serviceConfig.getString("[@type]");
if (type == null) type = "service"; if (type == null) type = "service";
String capacityString = serviceConfig.getString("capacity-demand"); String capacityString = serviceConfig.getString("capacity-demand");
boolean capacityDimensionsExist = serviceConfig.containsKey("capacity-dimensions.dimension(0)"); boolean capacityDimensionsExist = serviceConfig.containsKey("capacity-dimensions.dimension(0)");
if (capacityString == null && !capacityDimensionsExist) { if (capacityString == null && !capacityDimensionsExist) {
throw new IllegalStateException("capacity of service is not set. use 'capacity-dimensions'"); throw new IllegalArgumentException("capacity of service is not set. use 'capacity-dimensions'");
} }
if (capacityString != null && capacityDimensionsExist) { if (capacityString != null && capacityDimensionsExist) {
throw new IllegalStateException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'."); throw new IllegalArgumentException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'.");
} }
Service.Builder builder; Service.Builder builder;
@ -556,15 +556,15 @@ public class VrpXMLReader {
List<HierarchicalConfiguration> typeConfigs = vrpProblem.configurationsAt("vehicleTypes.type"); List<HierarchicalConfiguration> typeConfigs = vrpProblem.configurationsAt("vehicleTypes.type");
for (HierarchicalConfiguration typeConfig : typeConfigs) { for (HierarchicalConfiguration typeConfig : typeConfigs) {
String typeId = typeConfig.getString("id"); String typeId = typeConfig.getString("id");
if (typeId == null) throw new IllegalStateException("typeId is missing."); if (typeId == null) throw new IllegalArgumentException("typeId is missing.");
String capacityString = typeConfig.getString("capacity"); String capacityString = typeConfig.getString("capacity");
boolean capacityDimensionsExist = typeConfig.containsKey("capacity-dimensions.dimension(0)"); boolean capacityDimensionsExist = typeConfig.containsKey("capacity-dimensions.dimension(0)");
if (capacityString == null && !capacityDimensionsExist) { if (capacityString == null && !capacityDimensionsExist) {
throw new IllegalStateException("capacity of type is not set. use 'capacity-dimensions'"); throw new IllegalArgumentException("capacity of type is not set. use 'capacity-dimensions'");
} }
if (capacityString != null && capacityDimensionsExist) { if (capacityString != null && capacityDimensionsExist) {
throw new IllegalStateException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'."); throw new IllegalArgumentException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'.");
} }
VehicleTypeImpl.Builder typeBuilder; VehicleTypeImpl.Builder typeBuilder;
@ -606,10 +606,10 @@ public class VrpXMLReader {
boolean doNotWarnAgain = false; boolean doNotWarnAgain = false;
for (HierarchicalConfiguration vehicleConfig : vehicleConfigs) { for (HierarchicalConfiguration vehicleConfig : vehicleConfigs) {
String vehicleId = vehicleConfig.getString("id"); String vehicleId = vehicleConfig.getString("id");
if (vehicleId == null) throw new IllegalStateException("vehicleId is missing."); if (vehicleId == null) throw new IllegalArgumentException("vehicleId is missing.");
Builder builder = VehicleImpl.Builder.newInstance(vehicleId); Builder builder = VehicleImpl.Builder.newInstance(vehicleId);
String typeId = vehicleConfig.getString("typeId"); String typeId = vehicleConfig.getString("typeId");
if (typeId == null) throw new IllegalStateException("typeId is missing."); if (typeId == null) throw new IllegalArgumentException("typeId is missing.");
String vType = vehicleConfig.getString("[@type]"); String vType = vehicleConfig.getString("[@type]");
if (vType != null) { if (vType != null) {
if (vType.equals("penalty")) { if (vType.equals("penalty")) {
@ -617,7 +617,7 @@ public class VrpXMLReader {
} }
} }
VehicleType type = types.get(typeId); VehicleType type = types.get(typeId);
if (type == null) throw new IllegalStateException("vehicleType with typeId " + typeId + " is missing."); if (type == null) throw new IllegalArgumentException("vehicleType with typeId " + typeId + " is missing.");
builder.setType(type); builder.setType(type);
//read startlocation //read startlocation

View file

@ -44,10 +44,10 @@ public class Delivery extends Service {
* Builds Delivery. * Builds Delivery.
* *
* @return delivery * @return delivery
* @throws IllegalStateException if neither locationId nor coord is set * @throws IllegalArgumentException if neither locationId nor coord is set
*/ */
public Delivery build() { public Delivery build() {
if (location == null) throw new IllegalStateException("location is missing"); if (location == null) throw new IllegalArgumentException("location is missing");
this.setType("delivery"); this.setType("delivery");
super.capacity = super.capacityBuilder.build(); super.capacity = super.capacityBuilder.build();
super.skills = super.skillBuilder.build(); super.skills = super.skillBuilder.build();

View file

@ -46,10 +46,10 @@ public class Pickup extends Service {
* <p>Pickup type is "pickup" * <p>Pickup type is "pickup"
* *
* @return pickup * @return pickup
* @throws IllegalStateException if neither locationId nor coordinate has been set * @throws IllegalArgumentException if neither locationId nor coordinate has been set
*/ */
public Pickup build() { public Pickup build() {
if (location == null) throw new IllegalStateException("location is missing"); if (location == null) throw new IllegalArgumentException("location is missing");
this.setType("pickup"); this.setType("pickup");
super.capacity = super.capacityBuilder.build(); super.capacity = super.capacityBuilder.build();
super.skills = super.skillBuilder.build(); super.skills = super.skillBuilder.build();

View file

@ -176,10 +176,10 @@ public class Service extends AbstractJob {
* Builds the service. * Builds the service.
* *
* @return {@link Service} * @return {@link Service}
* @throws IllegalStateException if neither locationId nor coordinate is set. * @throws IllegalArgumentException if neither locationId nor coordinate is set.
*/ */
public T build() { public T build() {
if (location == null) throw new IllegalStateException("location is missing"); if (location == null) throw new IllegalArgumentException("location is missing");
this.setType("service"); this.setType("service");
capacity = capacityBuilder.build(); capacity = capacityBuilder.build();
skills = skillBuilder.build(); skills = skillBuilder.build();
@ -219,7 +219,7 @@ public class Service extends AbstractJob {
* @return builder * @return builder
*/ */
public Builder<T> setPriority(int priority) { public Builder<T> setPriority(int priority) {
if(priority < 1 || priority > 3) throw new IllegalStateException("incorrect priority. only 1 = high, 2 = medium and 3 = low is allowed"); if(priority < 1 || priority > 3) throw new IllegalArgumentException("incorrect priority. only 1 = high, 2 = medium and 3 = low is allowed");
this.priority = priority; this.priority = priority;
return this; return this;
} }

View file

@ -216,12 +216,12 @@ public class Shipment extends AbstractJob {
* Builds the shipment. * Builds the shipment.
* *
* @return shipment * @return shipment
* @throws IllegalStateException if neither pickup-location nor pickup-coord is set or if neither delivery-location nor delivery-coord * @throws IllegalArgumentException if neither pickup-location nor pickup-coord is set or if neither delivery-location nor delivery-coord
* is set * is set
*/ */
public Shipment build() { public Shipment build() {
if (pickupLocation_ == null) throw new IllegalStateException("pickup location is missing"); if (pickupLocation_ == null) throw new IllegalArgumentException("pickup location is missing");
if (deliveryLocation_ == null) throw new IllegalStateException("delivery location is missing"); if (deliveryLocation_ == null) throw new IllegalArgumentException("delivery location is missing");
capacity = capacityBuilder.build(); capacity = capacityBuilder.build();
skills = skillBuilder.build(); skills = skillBuilder.build();
return new Shipment(this); return new Shipment(this);
@ -276,7 +276,7 @@ public class Shipment extends AbstractJob {
* @return builder * @return builder
*/ */
public Builder setPriority(int priority) { public Builder setPriority(int priority) {
if(priority < 1 || priority > 3) throw new IllegalStateException("incorrect priority. only 1 = high, 2 = medium and 3 = low is allowed"); if(priority < 1 || priority > 3) throw new IllegalArgumentException("incorrect priority. only 1 = high, 2 = medium and 3 = low is allowed");
this.priority = priority; this.priority = priority;
return this; return this;
} }

View file

@ -242,7 +242,7 @@ public class VehicleRoute {
* *
* @param shipment to be picked up and added to this route * @param shipment to be picked up and added to this route
* @return the builder * @return the builder
* @throws IllegalStateException if method has already been called with the specified shipment. * @throws IllegalArgumentException if method has already been called with the specified shipment.
*/ */
public Builder addPickup(Shipment shipment) { public Builder addPickup(Shipment shipment) {
return addPickup(shipment, shipment.getPickupTimeWindow()); return addPickup(shipment, shipment.getPickupTimeWindow());
@ -250,7 +250,7 @@ public class VehicleRoute {
public Builder addPickup(Shipment shipment, TimeWindow pickupTimeWindow) { public Builder addPickup(Shipment shipment, TimeWindow pickupTimeWindow) {
if (openShipments.contains(shipment)) if (openShipments.contains(shipment))
throw new IllegalStateException("shipment has already been added. cannot add it twice."); throw new IllegalArgumentException("shipment has already been added. cannot add it twice.");
List<AbstractActivity> acts = jobActivityFactory.createActivities(shipment); List<AbstractActivity> acts = jobActivityFactory.createActivities(shipment);
TourActivity act = acts.get(0); TourActivity act = acts.get(0);
act.setTheoreticalEarliestOperationStartTime(pickupTimeWindow.getStart()); act.setTheoreticalEarliestOperationStartTime(pickupTimeWindow.getStart());
@ -266,7 +266,7 @@ public class VehicleRoute {
* *
* @param shipment to be delivered and add to this vehicleRoute * @param shipment to be delivered and add to this vehicleRoute
* @return builder * @return builder
* @throws IllegalStateException if specified shipment has not been picked up yet (i.e. method addPickup(shipment) has not been called yet). * @throws IllegalArgumentException if specified shipment has not been picked up yet (i.e. method addPickup(shipment) has not been called yet).
*/ */
public Builder addDelivery(Shipment shipment) { public Builder addDelivery(Shipment shipment) {
return addDelivery(shipment,shipment.getDeliveryTimeWindow()); return addDelivery(shipment,shipment.getDeliveryTimeWindow());
@ -280,7 +280,7 @@ public class VehicleRoute {
tourActivities.addActivity(act); tourActivities.addActivity(act);
openShipments.remove(shipment); openShipments.remove(shipment);
} else { } else {
throw new IllegalStateException("cannot deliver shipment. shipment " + shipment + " needs to be picked up first."); throw new IllegalArgumentException("cannot deliver shipment. shipment " + shipment + " needs to be picked up first.");
} }
return this; return this;
} }
@ -290,11 +290,11 @@ public class VehicleRoute {
* Builds the route. * Builds the route.
* *
* @return {@link VehicleRoute} * @return {@link VehicleRoute}
* @throws IllegalStateException if there are still shipments that have been picked up though but not delivery. * @throws IllegalArgumentException if there are still shipments that have been picked up though but not delivery.
*/ */
public VehicleRoute build() { public VehicleRoute build() {
if (!openShipments.isEmpty()) { if (!openShipments.isEmpty()) {
throw new IllegalStateException("there are still shipments that have not been delivered yet."); throw new IllegalArgumentException("there are still shipments that have not been delivered yet.");
} }
if (!vehicle.isReturnToDepot()) { if (!vehicle.isReturnToDepot()) {
if (!tourActivities.isEmpty()) { if (!tourActivities.isEmpty()) {
@ -419,11 +419,11 @@ public class VehicleRoute {
* Returns the departureTime of this vehicle in this route. * Returns the departureTime of this vehicle in this route.
* *
* @return departureTime * @return departureTime
* @throws IllegalStateException if start is null * @throws IllegalArgumentException if start is null
*/ */
public double getDepartureTime() { public double getDepartureTime() {
if (start == null) if (start == null)
throw new IllegalStateException("cannot get departureTime without having a vehicle on this route. use setVehicle(vehicle,departureTime) instead."); throw new IllegalArgumentException("cannot get departureTime without having a vehicle on this route. use setVehicle(vehicle,departureTime) instead.");
return start.getEndTime(); return start.getEndTime();
} }

View file

@ -14,13 +14,13 @@ public class TimeWindowsImpl implements TimeWindows {
public void add(TimeWindow timeWindow){ public void add(TimeWindow timeWindow){
for(TimeWindow tw : timeWindows){ for(TimeWindow tw : timeWindows){
if(timeWindow.getStart() > tw.getStart() && timeWindow.getStart() < tw.getEnd()){ if(timeWindow.getStart() > tw.getStart() && timeWindow.getStart() < tw.getEnd()){
throw new IllegalStateException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow); throw new IllegalArgumentException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow);
} }
if(timeWindow.getEnd() > tw.getStart() && timeWindow.getEnd() < tw.getEnd()){ if(timeWindow.getEnd() > tw.getStart() && timeWindow.getEnd() < tw.getEnd()){
throw new IllegalStateException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow); throw new IllegalArgumentException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow);
} }
if(timeWindow.getStart() <= tw.getStart() && timeWindow.getEnd() >= tw.getEnd()){ if(timeWindow.getStart() <= tw.getStart() && timeWindow.getEnd() >= tw.getEnd()){
throw new IllegalStateException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow); throw new IllegalArgumentException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow);
} }
} }
timeWindows.add(timeWindow); timeWindows.add(timeWindow);

View file

@ -214,11 +214,11 @@ public class TourActivities {
* <p>If act instanceof JobActivity, it adds underlying job also. * <p>If act instanceof JobActivity, it adds underlying job also.
* *
* @param act to be added * @param act to be added
* @throws IllegalStateException if activity-list already contains act. * @throws IllegalArgumentException if activity-list already contains act.
*/ */
public void addActivity(TourActivity act) { public void addActivity(TourActivity act) {
if (tourActivities.contains(act)) if (tourActivities.contains(act))
throw new IllegalStateException("act " + act + " already in tour. cannot add act twice."); throw new IllegalArgumentException("act " + act + " already in tour. cannot add act twice.");
tourActivities.add(act); tourActivities.add(act);
addJob(act); addJob(act);
} }

View file

@ -139,10 +139,10 @@ public class VehicleImpl extends AbstractVehicle {
* *
* @param type the type to be set * @param type the type to be set
* @return this builder * @return this builder
* @throws IllegalStateException if type is null * @throws IllegalArgumentException if type is null
*/ */
public Builder setType(VehicleType type) { public Builder setType(VehicleType type) {
if (type == null) throw new IllegalStateException("type cannot be null."); if (type == null) throw new IllegalArgumentException("type cannot be null.");
this.type = type; this.type = type;
return this; return this;
} }
@ -224,22 +224,22 @@ public class VehicleImpl extends AbstractVehicle {
* Thus endLocationId can never be null even returnToDepot is false. * Thus endLocationId can never be null even returnToDepot is false.
* *
* @return vehicle * @return vehicle
* @throws IllegalStateException if both locationId and locationCoord is not set or (endLocationCoord!=null AND returnToDepot=false) * @throws IllegalArgumentException if both locationId and locationCoord is not set or (endLocationCoord!=null AND returnToDepot=false)
* or (endLocationId!=null AND returnToDepot=false) * or (endLocationId!=null AND returnToDepot=false)
*/ */
public VehicleImpl build() { public VehicleImpl build() {
if (latestArrival < earliestStart) if (latestArrival < earliestStart)
throw new IllegalStateException("latest arrival of vehicle " + id + " must not be smaller than its start time"); throw new IllegalArgumentException("latest arrival of vehicle " + id + " must not be smaller than its start time");
if (startLocation != null && endLocation != null) { if (startLocation != null && endLocation != null) {
if (!startLocation.getId().equals(endLocation.getId()) && !returnToDepot) if (!startLocation.getId().equals(endLocation.getId()) && !returnToDepot)
throw new IllegalStateException("this must not be. you specified both endLocationId and open-routes. this is contradictory. <br>" + throw new IllegalArgumentException("this must not be. you specified both endLocationId and open-routes. this is contradictory. <br>" +
"if you set endLocation, returnToDepot must be true. if returnToDepot is false, endLocationCoord must not be specified."); "if you set endLocation, returnToDepot must be true. if returnToDepot is false, endLocationCoord must not be specified.");
} }
if (startLocation != null && endLocation == null) { if (startLocation != null && endLocation == null) {
endLocation = startLocation; endLocation = startLocation;
} }
if (startLocation == null && endLocation == null) { if (startLocation == null && endLocation == null) {
throw new IllegalStateException("vehicle requires startLocation. but neither locationId nor locationCoord nor startLocationId nor startLocationCoord has been set"); throw new IllegalArgumentException("vehicle requires startLocation. but neither locationId nor locationCoord nor startLocationId nor startLocationCoord has been set");
} }
skills = skillBuilder.build(); skills = skillBuilder.build();
return new VehicleImpl(this); return new VehicleImpl(this);

View file

@ -91,7 +91,7 @@ public class VehicleTypeImpl implements VehicleType {
public static VehicleTypeImpl.Builder newInstance(String id) { public static VehicleTypeImpl.Builder newInstance(String id) {
if (id == null) throw new IllegalStateException(); if (id == null) throw new IllegalArgumentException();
return new Builder(id); return new Builder(id);
} }
@ -124,10 +124,10 @@ public class VehicleTypeImpl implements VehicleType {
* *
* @param inMeterPerSeconds * @param inMeterPerSeconds
* @return this builder * @return this builder
* @throws IllegalStateException if velocity is smaller than zero * @throws IllegalArgumentException if velocity is smaller than zero
*/ */
public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds) { public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds) {
if (inMeterPerSeconds < 0.0) throw new IllegalStateException("velocity cannot be smaller than zero"); if (inMeterPerSeconds < 0.0) throw new IllegalArgumentException("velocity cannot be smaller than zero");
this.maxVelo = inMeterPerSeconds; this.maxVelo = inMeterPerSeconds;
return this; return this;
} }
@ -139,10 +139,10 @@ public class VehicleTypeImpl implements VehicleType {
* *
* @param fixedCost * @param fixedCost
* @return this builder * @return this builder
* @throws IllegalStateException if fixedCost is smaller than zero * @throws IllegalArgumentException if fixedCost is smaller than zero
*/ */
public VehicleTypeImpl.Builder setFixedCost(double fixedCost) { public VehicleTypeImpl.Builder setFixedCost(double fixedCost) {
if (fixedCost < 0.0) throw new IllegalStateException("fixed costs cannot be smaller than zero"); if (fixedCost < 0.0) throw new IllegalArgumentException("fixed costs cannot be smaller than zero");
this.fixedCost = fixedCost; this.fixedCost = fixedCost;
return this; return this;
} }
@ -154,10 +154,10 @@ public class VehicleTypeImpl implements VehicleType {
* *
* @param perDistance * @param perDistance
* @return this builder * @return this builder
* @throws IllegalStateException if perDistance is smaller than zero * @throws IllegalArgumentException if perDistance is smaller than zero
*/ */
public VehicleTypeImpl.Builder setCostPerDistance(double perDistance) { public VehicleTypeImpl.Builder setCostPerDistance(double perDistance) {
if (perDistance < 0.0) throw new IllegalStateException("cost per distance must not be smaller than zero"); if (perDistance < 0.0) throw new IllegalArgumentException("cost per distance must not be smaller than zero");
this.perDistance = perDistance; this.perDistance = perDistance;
return this; return this;
} }
@ -169,12 +169,12 @@ public class VehicleTypeImpl implements VehicleType {
* *
* @param perTime * @param perTime
* @return this builder * @return this builder
* @throws IllegalStateException if costPerTime is smaller than zero * @throws IllegalArgumentException if costPerTime is smaller than zero
* @deprecated use .setCostPerTransportTime(..) instead * @deprecated use .setCostPerTransportTime(..) instead
*/ */
@Deprecated @Deprecated
public VehicleTypeImpl.Builder setCostPerTime(double perTime) { public VehicleTypeImpl.Builder setCostPerTime(double perTime) {
if (perTime < 0.0) throw new IllegalStateException(); if (perTime < 0.0) throw new IllegalArgumentException();
this.perTime = perTime; this.perTime = perTime;
return this; return this;
} }
@ -186,10 +186,10 @@ public class VehicleTypeImpl implements VehicleType {
* *
* @param perTime * @param perTime
* @return this builder * @return this builder
* @throws IllegalStateException if costPerTime is smaller than zero * @throws IllegalArgumentException if costPerTime is smaller than zero
*/ */
public VehicleTypeImpl.Builder setCostPerTransportTime(double perTime) { public VehicleTypeImpl.Builder setCostPerTransportTime(double perTime) {
if (perTime < 0.0) throw new IllegalStateException(); if (perTime < 0.0) throw new IllegalArgumentException();
this.perTime = perTime; this.perTime = perTime;
return this; return this;
} }
@ -201,10 +201,10 @@ public class VehicleTypeImpl implements VehicleType {
* *
* @param perWaitingTime * @param perWaitingTime
* @return this builder * @return this builder
* @throws IllegalStateException if costPerTime is smaller than zero * @throws IllegalArgumentException if costPerTime is smaller than zero
*/ */
public VehicleTypeImpl.Builder setCostPerWaitingTime(double perWaitingTime) { public VehicleTypeImpl.Builder setCostPerWaitingTime(double perWaitingTime) {
if (perWaitingTime < 0.0) throw new IllegalStateException(); if (perWaitingTime < 0.0) throw new IllegalArgumentException();
this.perWaitingTime = perWaitingTime; this.perWaitingTime = perWaitingTime;
return this; return this;
} }
@ -233,12 +233,12 @@ public class VehicleTypeImpl implements VehicleType {
* @param dimVal * @param dimVal
* @return the builder * @return the builder
* @throws IllegalArgumentException if dimVal < 0 * @throws IllegalArgumentException if dimVal < 0
* @throws IllegalStateException if capacity dimension is already set * @throws IllegalArgumentException if capacity dimension is already set
*/ */
public Builder addCapacityDimension(int dimIndex, int dimVal) { public Builder addCapacityDimension(int dimIndex, int dimVal) {
if (dimVal < 0) throw new IllegalArgumentException("capacity value cannot be negative"); if (dimVal < 0) throw new IllegalArgumentException("capacity value cannot be negative");
if (capacityDimensions != null) if (capacityDimensions != null)
throw new IllegalStateException("either build your dimension with build your dimensions with " + throw new IllegalArgumentException("either build your dimension with build your dimensions with " +
"addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." + "addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." +
"You used both methods."); "You used both methods.");
dimensionAdded = true; dimensionAdded = true;
@ -255,11 +255,11 @@ public class VehicleTypeImpl implements VehicleType {
* *
* @param capacity * @param capacity
* @return this builder * @return this builder
* @throws IllegalStateException if capacityDimension has already been added * @throws IllegalArgumentException if capacityDimension has already been added
*/ */
public Builder setCapacityDimensions(Capacity capacity) { public Builder setCapacityDimensions(Capacity capacity) {
if (dimensionAdded) if (dimensionAdded)
throw new IllegalStateException("either build your dimension with build your dimensions with " + throw new IllegalArgumentException("either build your dimension with build your dimensions with " +
"addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." + "addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." +
"You used both methods."); "You used both methods.");
this.capacityDimensions = capacity; this.capacityDimensions = capacity;

View file

@ -349,7 +349,7 @@ public class CapacityTest {
assertEquals(0.0, Capacity.divide(cap1, cap2), 0.001); assertEquals(0.0, Capacity.divide(cap1, cap2), 0.001);
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenDividingByAZeroDim_itShouldThrowException() { public void whenDividingByAZeroDim_itShouldThrowException() {
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build(); Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build();
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 0).build(); Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 0).build();

View file

@ -45,7 +45,7 @@ public class LocationTest {
Location l = Location.Builder.newInstance().setIndex(-1).build(); Location l = Location.Builder.newInstance().setIndex(-1).build();
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenCoordinateAndIdAndIndexNotSet_throwException() { public void whenCoordinateAndIdAndIndexNotSet_throwException() {
Location l = Location.Builder.newInstance().build(); Location l = Location.Builder.newInstance().build();
} }

View file

@ -303,7 +303,7 @@ public class VehicleRoutingProblemTest {
return Location.Builder.newInstance().setId(i).build(); return Location.Builder.newInstance().setId(i).build();
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenAddingVehiclesWithSameId_itShouldThrowException(){ public void whenAddingVehiclesWithSameId_itShouldThrowException(){
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build();
@ -453,7 +453,7 @@ public class VehicleRoutingProblemTest {
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenAddingTwoServicesWithTheSameId_itShouldThrowException() { public void whenAddingTwoServicesWithTheSameId_itShouldThrowException() {
Service service1 = Service.Builder.newInstance("myService").setLocation(Location.newInstance("loc")).build(); Service service1 = Service.Builder.newInstance("myService").setLocation(Location.newInstance("loc")).build();
Service service2 = Service.Builder.newInstance("myService").setLocation(Location.newInstance("loc")).build(); Service service2 = Service.Builder.newInstance("myService").setLocation(Location.newInstance("loc")).build();
@ -463,7 +463,7 @@ public class VehicleRoutingProblemTest {
@SuppressWarnings("UnusedDeclaration") VehicleRoutingProblem vrp = vrpBuilder.build(); @SuppressWarnings("UnusedDeclaration") VehicleRoutingProblem vrp = vrpBuilder.build();
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenAddingTwoShipmentsWithTheSameId_itShouldThrowException() { public void whenAddingTwoShipmentsWithTheSameId_itShouldThrowException() {
Shipment shipment1 = Shipment.Builder.newInstance("shipment").setPickupLocation(Location.Builder.newInstance().setId("pick").build()) Shipment shipment1 = Shipment.Builder.newInstance("shipment").setPickupLocation(Location.Builder.newInstance().setId("pick").build())
.setDeliveryLocation(Location.newInstance("del")).build(); .setDeliveryLocation(Location.newInstance("del")).build();

View file

@ -24,7 +24,7 @@ import static org.junit.Assert.*;
public class DeliveryTest { public class DeliveryTest {
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenNeitherLocationIdNorCoordIsSet_itThrowsException() { public void whenNeitherLocationIdNorCoordIsSet_itThrowsException() {
Delivery.Builder.newInstance("p").build(); Delivery.Builder.newInstance("p").build();
} }

View file

@ -24,7 +24,7 @@ import static org.junit.Assert.*;
public class PickupTest { public class PickupTest {
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenNeitherLocationIdNorCoordIsSet_itThrowsException() { public void whenNeitherLocationIdNorCoordIsSet_itThrowsException() {
Pickup.Builder.newInstance("p").build(); Pickup.Builder.newInstance("p").build();
} }

View file

@ -124,7 +124,7 @@ public class ServiceTest {
assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01); assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01);
} }
@Test(expected=IllegalStateException.class) @Test(expected=IllegalArgumentException.class)
public void whenSettingNeitherLocationIdNorCoord_throwsException(){ public void whenSettingNeitherLocationIdNorCoord_throwsException(){
@SuppressWarnings("unused") @SuppressWarnings("unused")
Service s = Service.Builder.newInstance("s").build(); Service s = Service.Builder.newInstance("s").build();
@ -219,7 +219,7 @@ public class ServiceTest {
assertEquals(2,s.getTimeWindows().size()); assertEquals(2,s.getTimeWindows().size());
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenMultipleTWOverlap_throwEx(){ public void whenMultipleTWOverlap_throwEx(){
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
.addTimeWindow(TimeWindow.newInstance(0.,10.)) .addTimeWindow(TimeWindow.newInstance(0.,10.))
@ -227,7 +227,7 @@ public class ServiceTest {
.setName("name").build(); .setName("name").build();
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenMultipleTWOverlap2_throwEx(){ public void whenMultipleTWOverlap2_throwEx(){
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
.addTimeWindow(TimeWindow.newInstance(20., 30.)) .addTimeWindow(TimeWindow.newInstance(20., 30.))
@ -256,14 +256,14 @@ public class ServiceTest {
Assert.assertEquals(2, s.getPriority()); Assert.assertEquals(2, s.getPriority());
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenSettingIncorrectPriorities_itShouldThrowException(){ public void whenSettingIncorrectPriorities_itShouldThrowException(){
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
.setPriority(30).build(); .setPriority(30).build();
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenSettingIncorrectPriorities_itShouldThrowException2(){ public void whenSettingIncorrectPriorities_itShouldThrowException2(){
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
.setPriority(0).build(); .setPriority(0).build();

View file

@ -86,13 +86,13 @@ public class ShipmentTest {
assertNotNull(builder); assertNotNull(builder);
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenNeitherPickupLocationIdNorPickupCoord_itThrowsException() { public void whenNeitherPickupLocationIdNorPickupCoord_itThrowsException() {
@SuppressWarnings("unused") @SuppressWarnings("unused")
Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocation(TestUtils.loc("delLoc")).build(); Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocation(TestUtils.loc("delLoc")).build();
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenNeitherDeliveryLocationIdNorDeliveryCoord_itThrowsException() { public void whenNeitherDeliveryLocationIdNorDeliveryCoord_itThrowsException() {
@SuppressWarnings("unused") @SuppressWarnings("unused")
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
@ -105,7 +105,7 @@ public class ShipmentTest {
assertEquals("pickLoc", s.getPickupLocation().getId()); assertEquals("pickLoc", s.getPickupLocation().getId());
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenPickupLocationIsNull_itThrowsException() { public void whenPickupLocationIsNull_itThrowsException() {
@SuppressWarnings("unused") @SuppressWarnings("unused")
Shipment.Builder builder = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId(null).build()); Shipment.Builder builder = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId(null).build());
@ -253,7 +253,7 @@ public class ShipmentTest {
assertThat(s.getDeliveryTimeWindows(),hasItem(is(tw2))); assertThat(s.getDeliveryTimeWindows(),hasItem(is(tw2)));
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenAddingMultipleOverlappingDeliveryTimeWindows_itShouldThrowException() { public void whenAddingMultipleOverlappingDeliveryTimeWindows_itShouldThrowException() {
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(1, 3).addDeliveryTimeWindow(2,5) Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(1, 3).addDeliveryTimeWindow(2,5)
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
@ -290,7 +290,7 @@ public class ShipmentTest {
assertThat(s.getPickupTimeWindows(), hasItem(is(tw2))); assertThat(s.getPickupTimeWindows(), hasItem(is(tw2)));
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenAddingMultipleOverlappingPickupTimeWindows_itShouldThrowException() { public void whenAddingMultipleOverlappingPickupTimeWindows_itShouldThrowException() {
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(1, 3).addPickupTimeWindow(2,5) Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(1, 3).addPickupTimeWindow(2,5)
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
@ -408,7 +408,7 @@ public class ShipmentTest {
Assert.assertEquals(2, s.getPriority()); Assert.assertEquals(2, s.getPriority());
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenSettingIncorrectPriorities_itShouldThrowException(){ public void whenSettingIncorrectPriorities_itShouldThrowException(){
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc")) Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
.setDeliveryLocation(Location.newInstance("loc")) .setDeliveryLocation(Location.newInstance("loc"))
@ -416,7 +416,7 @@ public class ShipmentTest {
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenSettingIncorrectPriorities_itShouldThrowException2(){ public void whenSettingIncorrectPriorities_itShouldThrowException2(){
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc")) Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
.setDeliveryLocation(Location.newInstance("loc")) .setDeliveryLocation(Location.newInstance("loc"))

View file

@ -32,14 +32,14 @@ import static org.mockito.Mockito.when;
public class VehicleRouteBuilderTest { public class VehicleRouteBuilderTest {
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenDeliveryIsAddedBeforePickup_throwsException() { public void whenDeliveryIsAddedBeforePickup_throwsException() {
Shipment s = mock(Shipment.class); Shipment s = mock(Shipment.class);
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class)); VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class));
builder.addDelivery(s); builder.addDelivery(s);
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenPickupIsAddedTwice_throwsException() { public void whenPickupIsAddedTwice_throwsException() {
Shipment s = mock(Shipment.class); Shipment s = mock(Shipment.class);
when(s.getSize()).thenReturn(Capacity.Builder.newInstance().build()); when(s.getSize()).thenReturn(Capacity.Builder.newInstance().build());
@ -49,7 +49,7 @@ public class VehicleRouteBuilderTest {
builder.addPickup(s); builder.addPickup(s);
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenShipmentIsPickedDeliveredAndDeliveredAgain_throwsException() { public void whenShipmentIsPickedDeliveredAndDeliveredAgain_throwsException() {
Shipment s = mock(Shipment.class); Shipment s = mock(Shipment.class);
Capacity capacity = Capacity.Builder.newInstance().build(); Capacity capacity = Capacity.Builder.newInstance().build();
@ -62,7 +62,7 @@ public class VehicleRouteBuilderTest {
builder.addDelivery(s); builder.addDelivery(s);
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenShipmentIsPickedUpThoughButHasNotBeenDeliveredAndRouteIsBuilt_throwsException() { public void whenShipmentIsPickedUpThoughButHasNotBeenDeliveredAndRouteIsBuilt_throwsException() {
Shipment s = mock(Shipment.class); Shipment s = mock(Shipment.class);
Capacity capacity = Capacity.Builder.newInstance().build(); Capacity capacity = Capacity.Builder.newInstance().build();

View file

@ -45,7 +45,7 @@ public class TestTourActivities {
assertTrue(tour.servesJob(service)); assertTrue(tour.servesJob(service));
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenAddingServiceActTwice_anExceptionIsThrown() { public void whenAddingServiceActTwice_anExceptionIsThrown() {
assertFalse(tour.servesJob(service)); assertFalse(tour.servesJob(service));
tour.addActivity(act); tour.addActivity(act);

View file

@ -7,21 +7,21 @@ import org.junit.Test;
*/ */
public class TimeWindowsImplTest { public class TimeWindowsImplTest {
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void overlappingTW_shouldThrowException(){ public void overlappingTW_shouldThrowException(){
TimeWindowsImpl tws = new TimeWindowsImpl(); TimeWindowsImpl tws = new TimeWindowsImpl();
tws.add(TimeWindow.newInstance(50, 100)); tws.add(TimeWindow.newInstance(50, 100));
tws.add(TimeWindow.newInstance(90,150)); tws.add(TimeWindow.newInstance(90,150));
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void overlappingTW2_shouldThrowException(){ public void overlappingTW2_shouldThrowException(){
TimeWindowsImpl tws = new TimeWindowsImpl(); TimeWindowsImpl tws = new TimeWindowsImpl();
tws.add(TimeWindow.newInstance(50, 100)); tws.add(TimeWindow.newInstance(50, 100));
tws.add(TimeWindow.newInstance(40,150)); tws.add(TimeWindow.newInstance(40,150));
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void overlappingTW3_shouldThrowException(){ public void overlappingTW3_shouldThrowException(){
TimeWindowsImpl tws = new TimeWindowsImpl(); TimeWindowsImpl tws = new TimeWindowsImpl();
tws.add(TimeWindow.newInstance(50, 100)); tws.add(TimeWindow.newInstance(50, 100));

View file

@ -30,7 +30,7 @@ import static org.junit.Assert.*;
public class VehicleImplTest { public class VehicleImplTest {
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenVehicleIsBuiltWithoutSettingNeitherLocationNorCoord_itThrowsAnIllegalStateException() { public void whenVehicleIsBuiltWithoutSettingNeitherLocationNorCoord_itThrowsAnIllegalStateException() {
@SuppressWarnings("unused") @SuppressWarnings("unused")
Vehicle v = VehicleImpl.Builder.newInstance("v").build(); Vehicle v = VehicleImpl.Builder.newInstance("v").build();
@ -133,7 +133,7 @@ public class VehicleImplTest {
assertEquals("startLoc", v.getStartLocation().getId()); assertEquals("startLoc", v.getStartLocation().getId());
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenStartLocationIsNull_itThrowsException() { public void whenStartLocationIsNull_itThrowsException() {
@SuppressWarnings("unused") @SuppressWarnings("unused")
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(null)).build(); Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(null)).build();
@ -185,13 +185,13 @@ public class VehicleImplTest {
assertEquals(v.getEndLocation().getCoordinate().toString(), v.getEndLocation().getId()); assertEquals(v.getEndLocation().getCoordinate().toString(), v.getEndLocation().getId());
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenEndLocationIdIsSpecifiedANDReturnToDepotIsFalse_itShouldThrowException() { public void whenEndLocationIdIsSpecifiedANDReturnToDepotIsFalse_itShouldThrowException() {
@SuppressWarnings("unused") @SuppressWarnings("unused")
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setEndLocation(Location.newInstance("endLoc")).setReturnToDepot(false).build(); Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setEndLocation(Location.newInstance("endLoc")).setReturnToDepot(false).build();
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenEndLocationCoordIsSpecifiedANDReturnToDepotIsFalse_itShouldThrowException() { public void whenEndLocationCoordIsSpecifiedANDReturnToDepotIsFalse_itShouldThrowException() {
@SuppressWarnings("unused") @SuppressWarnings("unused")
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setEndLocation(Location.newInstance(3, 4)).setReturnToDepot(false).build(); Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setEndLocation(Location.newInstance(3, 4)).setReturnToDepot(false).build();
@ -209,7 +209,7 @@ public class VehicleImplTest {
assertEquals(v.getStartLocation().getCoordinate().toString(), v.getEndLocation().getId()); assertEquals(v.getStartLocation().getCoordinate().toString(), v.getEndLocation().getId());
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenStartAndEndAreUnequalANDReturnToDepotIsFalse_itShouldThrowException() { public void whenStartAndEndAreUnequalANDReturnToDepotIsFalse_itShouldThrowException() {
@SuppressWarnings("unused") @SuppressWarnings("unused")
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).setReturnToDepot(false).build(); Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).setReturnToDepot(false).build();

View file

@ -85,7 +85,7 @@ public class VehicleTypeImplTest {
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("foo").addCapacityDimension(0, -10).build(); VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("foo").addCapacityDimension(0, -10).build();
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenBuildingTypeWithNullId_throwIllegalStateException() { public void whenBuildingTypeWithNullId_throwIllegalStateException() {
@SuppressWarnings("unused") @SuppressWarnings("unused")
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance(null).addCapacityDimension(0, 10).build(); VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance(null).addCapacityDimension(0, 10).build();
@ -99,13 +99,13 @@ public class VehicleTypeImplTest {
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenMaxVelocitySmallerThanZero_itShouldThrowException() { public void whenMaxVelocitySmallerThanZero_itShouldThrowException() {
@SuppressWarnings("unused") @SuppressWarnings("unused")
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setMaxVelocity(-10).build(); VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setMaxVelocity(-10).build();
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenFixedCostsSmallerThanZero_itShouldThrowException() { public void whenFixedCostsSmallerThanZero_itShouldThrowException() {
@SuppressWarnings("unused") @SuppressWarnings("unused")
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setFixedCost(-10).build(); VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setFixedCost(-10).build();
@ -116,7 +116,7 @@ public class VehicleTypeImplTest {
assertEquals(10.0, type.getVehicleCostParams().fix, 0.0); assertEquals(10.0, type.getVehicleCostParams().fix, 0.0);
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenPerDistanceCostsSmallerThanZero_itShouldThrowException() { public void whenPerDistanceCostsSmallerThanZero_itShouldThrowException() {
@SuppressWarnings("unused") @SuppressWarnings("unused")
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerDistance(-10).build(); VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerDistance(-10).build();
@ -127,7 +127,7 @@ public class VehicleTypeImplTest {
assertEquals(10.0, type.getVehicleCostParams().perDistanceUnit, 0.0); assertEquals(10.0, type.getVehicleCostParams().perDistanceUnit, 0.0);
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalArgumentException.class)
public void whenPerTimeCostsSmallerThanZero_itShouldThrowException() { public void whenPerTimeCostsSmallerThanZero_itShouldThrowException() {
@SuppressWarnings("unused") @SuppressWarnings("unused")
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerTime(-10).build(); VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerTime(-10).build();

View file

@ -2,7 +2,7 @@
<problem xmlns="http://www.w3schools.com" <problem xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
<problemType> <problemType>
<fleetSize>INFINITE</fleetSize> <fleetSize>FINITE</fleetSize>
</problemType> </problemType>
<vehicles> <vehicles>
<vehicle> <vehicle>
@ -20,6 +20,21 @@
</timeSchedule> </timeSchedule>
<returnToDepot>true</returnToDepot> <returnToDepot>true</returnToDepot>
</vehicle> </vehicle>
<vehicle>
<id>v2</id>
<typeId>vehType2</typeId>
<startLocation>
<id>loc</id>
</startLocation>
<endLocation>
<id>loc</id>
</endLocation>
<timeSchedule>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeSchedule>
<returnToDepot>true</returnToDepot>
</vehicle>
</vehicles> </vehicles>
<vehicleTypes> <vehicleTypes>
<type> <type>
@ -35,58 +50,18 @@
<wait>0.0</wait> <wait>0.0</wait>
</costs> </costs>
</type> </type>
<type>
<id>vehType2</id>
<capacity-dimensions>
<dimension index="0">200</dimension>
</capacity-dimensions>
<costs>
<fixed>0.0</fixed>
<distance>1.0</distance>
<time>0.0</time>
<service>0.0</service>
<wait>0.0</wait>
</costs>
</type>
</vehicleTypes> </vehicleTypes>
<services>
<service id="1" type="service">
<location>
<id>loc</id>
</location>
<capacity-dimensions>
<dimension index="0">1</dimension>
</capacity-dimensions>
<duration>2.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeWindow>
</timeWindows>
</service>
<service id="2" type="service">
<location>
<id>loc2</id>
</location>
<capacity-dimensions>
<dimension index="0">1</dimension>
</capacity-dimensions>
<duration>4.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeWindow>
</timeWindows>
</service>
</services>
<solutions>
<solution>
<cost>10.0</cost>
<routes>
<route>
<driverId>noDriver</driverId>
<vehicleId>v1</vehicleId>
<start>0.0</start>
<act type="service">
<serviceId>1</serviceId>
<arrTime>0.0</arrTime>
<endTime>0.0</endTime>
</act>
<end>0.0</end>
</route>
</routes>
<unassignedJobs>
<job id="2"/>
</unassignedJobs>
</solution>
</solutions>
</problem> </problem>