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;
for (int index = 0; index < Math.max(numerator.getNuOfDimensions(), denominator.getNuOfDimensions()); index++) {
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) {
continue;
} else {

View file

@ -85,7 +85,7 @@ public final class Location implements HasIndex, HasId {
public Location build() {
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) {
this.id = coordinate.toString();

View file

@ -222,9 +222,9 @@ public class VehicleRoutingProblem {
*/
public Builder addJob(AbstractJob job) {
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))
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);
incJobIndexCounter();
tentativeJobs.put(job.getId(), job);
@ -351,7 +351,7 @@ public class VehicleRoutingProblem {
* */
public Builder addVehicle(Vehicle vehicle) {
if (!(vehicle instanceof AbstractVehicle))
throw new IllegalStateException("vehicle must be an AbstractVehicle");
throw new IllegalArgumentException("vehicle must be an AbstractVehicle");
return addVehicle((AbstractVehicle) vehicle);
}
@ -363,7 +363,7 @@ public class VehicleRoutingProblem {
*/
public Builder addVehicle(AbstractVehicle vehicle) {
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());
if (!uniqueVehicles.contains(vehicle)) {

View file

@ -193,9 +193,9 @@ public class VrpXMLReader {
Driver driver = DriverImpl.noDriver();
String vehicleId = routeConfig.getString("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");
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);
VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver);
@ -204,7 +204,7 @@ public class VrpXMLReader {
List<HierarchicalConfiguration> actConfigs = routeConfig.configurationsAt("act");
for (HierarchicalConfiguration actConfig : actConfigs) {
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 endTime = 0.;
String arrTimeS = actConfig.getString("arrTime");
@ -221,24 +221,24 @@ public class VrpXMLReader {
if (serviceId != null) {
Service service = getService(serviceId);
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
freezedJobIds.add(serviceId);
routeBuilder.addService(service);
} else {
String shipmentId = actConfig.getString("shipmentId");
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);
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);
if (type.equals("pickupShipment")) {
routeBuilder.addPickup(shipment);
} else if (type.equals("deliverShipment")) {
routeBuilder.addDelivery(shipment);
} 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();
String vehicleId = routeConfig.getString("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");
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);
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);
routeBuilder.setDepartureTime(departureTime);
List<HierarchicalConfiguration> actConfigs = routeConfig.configurationsAt("act");
for (HierarchicalConfiguration actConfig : actConfigs) {
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 endTime = 0.;
String arrTimeS = actConfig.getString("arrTime");
@ -294,16 +294,16 @@ public class VrpXMLReader {
} else {
String shipmentId = actConfig.getString("shipmentId");
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);
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")) {
routeBuilder.addPickup(shipment);
} else if (type.equals("deliverShipment")) {
routeBuilder.addDelivery(shipment);
} 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]");
Job job = getShipment(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);
}
@ -351,15 +351,15 @@ public class VrpXMLReader {
List<HierarchicalConfiguration> shipmentConfigs = config.configurationsAt("shipments.shipment");
for (HierarchicalConfiguration shipmentConfig : shipmentConfigs) {
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");
boolean capacityDimensionsExist = shipmentConfig.containsKey("capacity-dimensions.dimension(0)");
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) {
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;
@ -475,17 +475,17 @@ public class VrpXMLReader {
List<HierarchicalConfiguration> serviceConfigs = vrpProblem.configurationsAt("services.service");
for (HierarchicalConfiguration serviceConfig : serviceConfigs) {
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]");
if (type == null) type = "service";
String capacityString = serviceConfig.getString("capacity-demand");
boolean capacityDimensionsExist = serviceConfig.containsKey("capacity-dimensions.dimension(0)");
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) {
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;
@ -556,15 +556,15 @@ public class VrpXMLReader {
List<HierarchicalConfiguration> typeConfigs = vrpProblem.configurationsAt("vehicleTypes.type");
for (HierarchicalConfiguration typeConfig : typeConfigs) {
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");
boolean capacityDimensionsExist = typeConfig.containsKey("capacity-dimensions.dimension(0)");
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) {
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;
@ -606,10 +606,10 @@ public class VrpXMLReader {
boolean doNotWarnAgain = false;
for (HierarchicalConfiguration vehicleConfig : vehicleConfigs) {
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);
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]");
if (vType != null) {
if (vType.equals("penalty")) {
@ -617,7 +617,7 @@ public class VrpXMLReader {
}
}
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);
//read startlocation

View file

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

View file

@ -46,10 +46,10 @@ public class Pickup extends Service {
* <p>Pickup type is "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() {
if (location == null) throw new IllegalStateException("location is missing");
if (location == null) throw new IllegalArgumentException("location is missing");
this.setType("pickup");
super.capacity = super.capacityBuilder.build();
super.skills = super.skillBuilder.build();

View file

@ -176,10 +176,10 @@ public class Service extends AbstractJob {
* Builds the 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() {
if (location == null) throw new IllegalStateException("location is missing");
if (location == null) throw new IllegalArgumentException("location is missing");
this.setType("service");
capacity = capacityBuilder.build();
skills = skillBuilder.build();
@ -219,7 +219,7 @@ public class Service extends AbstractJob {
* @return builder
*/
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;
return this;
}

View file

@ -216,12 +216,12 @@ public class Shipment extends AbstractJob {
* Builds the 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
*/
public Shipment build() {
if (pickupLocation_ == null) throw new IllegalStateException("pickup location is missing");
if (deliveryLocation_ == null) throw new IllegalStateException("delivery location is missing");
if (pickupLocation_ == null) throw new IllegalArgumentException("pickup location is missing");
if (deliveryLocation_ == null) throw new IllegalArgumentException("delivery location is missing");
capacity = capacityBuilder.build();
skills = skillBuilder.build();
return new Shipment(this);
@ -276,7 +276,7 @@ public class Shipment extends AbstractJob {
* @return builder
*/
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;
return this;
}

View file

@ -242,7 +242,7 @@ public class VehicleRoute {
*
* @param shipment to be picked up and added to this route
* @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) {
return addPickup(shipment, shipment.getPickupTimeWindow());
@ -250,7 +250,7 @@ public class VehicleRoute {
public Builder addPickup(Shipment shipment, TimeWindow pickupTimeWindow) {
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);
TourActivity act = acts.get(0);
act.setTheoreticalEarliestOperationStartTime(pickupTimeWindow.getStart());
@ -266,7 +266,7 @@ public class VehicleRoute {
*
* @param shipment to be delivered and add to this vehicleRoute
* @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) {
return addDelivery(shipment,shipment.getDeliveryTimeWindow());
@ -280,7 +280,7 @@ public class VehicleRoute {
tourActivities.addActivity(act);
openShipments.remove(shipment);
} 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;
}
@ -290,11 +290,11 @@ public class VehicleRoute {
* Builds the route.
*
* @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() {
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 (!tourActivities.isEmpty()) {
@ -419,11 +419,11 @@ public class VehicleRoute {
* Returns the departureTime of this vehicle in this route.
*
* @return departureTime
* @throws IllegalStateException if start is null
* @throws IllegalArgumentException if start is null
*/
public double getDepartureTime() {
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();
}

View file

@ -14,13 +14,13 @@ public class TimeWindowsImpl implements TimeWindows {
public void add(TimeWindow timeWindow){
for(TimeWindow tw : timeWindows){
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()){
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()){
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);

View file

@ -214,11 +214,11 @@ public class TourActivities {
* <p>If act instanceof JobActivity, it adds underlying job also.
*
* @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) {
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);
addJob(act);
}

View file

@ -139,10 +139,10 @@ public class VehicleImpl extends AbstractVehicle {
*
* @param type the type to be set
* @return this builder
* @throws IllegalStateException if type is null
* @throws IllegalArgumentException if type is null
*/
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;
return this;
}
@ -224,22 +224,22 @@ public class VehicleImpl extends AbstractVehicle {
* Thus endLocationId can never be null even returnToDepot is false.
*
* @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)
*/
public VehicleImpl build() {
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.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 (startLocation != null && endLocation == null) {
endLocation = startLocation;
}
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();
return new VehicleImpl(this);

View file

@ -91,7 +91,7 @@ public class VehicleTypeImpl implements VehicleType {
public static VehicleTypeImpl.Builder newInstance(String id) {
if (id == null) throw new IllegalStateException();
if (id == null) throw new IllegalArgumentException();
return new Builder(id);
}
@ -124,10 +124,10 @@ public class VehicleTypeImpl implements VehicleType {
*
* @param inMeterPerSeconds
* @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) {
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;
return this;
}
@ -139,10 +139,10 @@ public class VehicleTypeImpl implements VehicleType {
*
* @param fixedCost
* @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) {
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;
return this;
}
@ -154,10 +154,10 @@ public class VehicleTypeImpl implements VehicleType {
*
* @param perDistance
* @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) {
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;
return this;
}
@ -169,12 +169,12 @@ public class VehicleTypeImpl implements VehicleType {
*
* @param perTime
* @return this builder
* @throws IllegalStateException if costPerTime is smaller than zero
* @throws IllegalArgumentException if costPerTime is smaller than zero
* @deprecated use .setCostPerTransportTime(..) instead
*/
@Deprecated
public VehicleTypeImpl.Builder setCostPerTime(double perTime) {
if (perTime < 0.0) throw new IllegalStateException();
if (perTime < 0.0) throw new IllegalArgumentException();
this.perTime = perTime;
return this;
}
@ -186,10 +186,10 @@ public class VehicleTypeImpl implements VehicleType {
*
* @param perTime
* @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) {
if (perTime < 0.0) throw new IllegalStateException();
if (perTime < 0.0) throw new IllegalArgumentException();
this.perTime = perTime;
return this;
}
@ -201,10 +201,10 @@ public class VehicleTypeImpl implements VehicleType {
*
* @param perWaitingTime
* @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) {
if (perWaitingTime < 0.0) throw new IllegalStateException();
if (perWaitingTime < 0.0) throw new IllegalArgumentException();
this.perWaitingTime = perWaitingTime;
return this;
}
@ -233,12 +233,12 @@ public class VehicleTypeImpl implements VehicleType {
* @param dimVal
* @return the builder
* @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) {
if (dimVal < 0) throw new IllegalArgumentException("capacity value cannot be negative");
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)." +
"You used both methods.");
dimensionAdded = true;
@ -255,11 +255,11 @@ public class VehicleTypeImpl implements VehicleType {
*
* @param capacity
* @return this builder
* @throws IllegalStateException if capacityDimension has already been added
* @throws IllegalArgumentException if capacityDimension has already been added
*/
public Builder setCapacityDimensions(Capacity capacity) {
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)." +
"You used both methods.");
this.capacityDimensions = capacity;