Skip to content

Commit b610626

Browse files
committed
refine error messages
1 parent 76aa693 commit b610626

File tree

5 files changed

+43
-35
lines changed

5 files changed

+43
-35
lines changed

jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/VehicleRoutingProblem.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ public Builder addJob(Job job) {
232232
*/
233233
public Builder addJob(AbstractJob job) {
234234
if (tentativeJobs.containsKey(job.getId()))
235-
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");
235+
throw new IllegalArgumentException("The vehicle routing problem already contains a service or shipment with id " + job.getId() + ". Please make sure you use unique ids for all services and shipments.");
236236
if (!(job instanceof Service || job instanceof Shipment))
237-
throw new IllegalArgumentException("job must be either a service or a shipment");
237+
throw new IllegalArgumentException("Job must be either a service or a shipment.");
238238
job.setIndex(jobIndexCounter);
239239
incJobIndexCounter();
240240
tentativeJobs.put(job.getId(), job);
@@ -285,10 +285,11 @@ private boolean addBreaksToActivityMap() {
285285
for (Vehicle v : uniqueVehicles) {
286286
if (v.getBreak() != null) {
287287
if (!uniqueBreakIds.add(v.getBreak().getId()))
288-
throw new IllegalArgumentException("problem already contains a vehicle break with id " + v.getBreak().getId() + ". choose unique ids for each vehicle break.");
288+
throw new IllegalArgumentException("The vehicle routing roblem already contains a vehicle break with id " + v.getBreak().getId() + ". Please choose unique ids for each vehicle break.");
289289
hasBreaks = true;
290290
List<AbstractActivity> breakActivities = jobActivityFactory.createActivities(v.getBreak());
291-
if(breakActivities.isEmpty()) throw new IllegalArgumentException("at least one activity for break needs to be created by activityFactory");
291+
if (breakActivities.isEmpty())
292+
throw new IllegalArgumentException("At least one activity for break needs to be created by activityFactory.");
292293
for(AbstractActivity act : breakActivities){
293294
act.setIndex(activityIndexCounter);
294295
incActivityIndexCounter();
@@ -351,7 +352,7 @@ public Builder addInitialVehicleRoutes(Collection<VehicleRoute> routes) {
351352

352353
private void addShipment(Shipment job) {
353354
if (jobs.containsKey(job.getId())) {
354-
logger.warn("job " + job + " already in job list. overrides existing job.");
355+
logger.warn("The job " + job + " has already been added to the job list. This overrides the existing job.");
355356
}
356357
addLocationToTentativeLocations(job);
357358
// tentative_coordinates.put(job.getPickupLocation().getId(), job.getPickupLocation().getCoordinate());
@@ -367,7 +368,7 @@ private void addShipment(Shipment job) {
367368
* */
368369
public Builder addVehicle(Vehicle vehicle) {
369370
if (!(vehicle instanceof AbstractVehicle))
370-
throw new IllegalArgumentException("vehicle must be an AbstractVehicle");
371+
throw new IllegalArgumentException("A vehicle must be an AbstractVehicle.");
371372
return addVehicle((AbstractVehicle) vehicle);
372373
}
373374

@@ -379,7 +380,7 @@ public Builder addVehicle(Vehicle vehicle) {
379380
*/
380381
public Builder addVehicle(AbstractVehicle vehicle) {
381382
if(addedVehicleIds.contains(vehicle.getId())){
382-
throw new IllegalArgumentException("problem already contains a vehicle with id " + vehicle.getId() + ". choose unique ids for each vehicle.");
383+
throw new IllegalArgumentException("The vehicle routing problem already contains a vehicle with id " + vehicle.getId() + ". Please choose unique ids for each vehicle.");
383384
}
384385
else addedVehicleIds.add(vehicle.getId());
385386
if (!uniqueVehicles.contains(vehicle)) {
@@ -443,7 +444,7 @@ public VehicleRoutingProblem build() {
443444
}
444445
boolean hasBreaks = addBreaksToActivityMap();
445446
if (hasBreaks && fleetSize.equals(FleetSize.INFINITE))
446-
throw new UnsupportedOperationException("breaks are not yet supported when dealing with infinite fleet. either set it to finite or omit breaks.");
447+
throw new UnsupportedOperationException("Breaks are not yet supported when dealing with infinite fleet. Either set it to finite or omit breaks.");
447448
return new VehicleRoutingProblem(this);
448449
}
449450

@@ -510,7 +511,7 @@ private Builder addService(Service service) {
510511
// tentative_coordinates.put(service.getLocation().getId(), service.getLocation().getCoordinate());
511512
addLocationToTentativeLocations(service);
512513
if (jobs.containsKey(service.getId())) {
513-
logger.warn("service " + service + " already in job list. overrides existing job.");
514+
logger.warn("The service " + service + " has already been added to job list. This overrides existing job.");
514515
}
515516
jobs.put(service.getId(), service);
516517
return this;

jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Job.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
*/
3131
public interface Job extends HasId, HasIndex {
3232

33+
3334
/**
3435
* Returns the unique identifier (id) of a job.
3536
*

jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Service.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static Builder newInstance(String id) {
9292
protected Object userData;
9393

9494
protected double maxTimeInVehicle = Double.MAX_VALUE;
95-
95+
9696
Builder(String id){
9797
this.id = id;
9898
timeWindows = new TimeWindowsImpl();
@@ -135,7 +135,7 @@ public Builder<T> setLocation(Location location) {
135135
*/
136136
public Builder<T> setServiceTime(double serviceTime) {
137137
if (serviceTime < 0)
138-
throw new IllegalArgumentException("serviceTime must be greater than or equal to zero");
138+
throw new IllegalArgumentException("The service time of a service must be greater than or equal to zero.");
139139
this.serviceTime = serviceTime;
140140
return this;
141141
}
@@ -167,20 +167,20 @@ public Builder<T> setUserData(Object userData) {
167167
* @throws IllegalArgumentException if dimensionValue < 0
168168
*/
169169
public Builder<T> addSizeDimension(int dimensionIndex, int dimensionValue) {
170-
if (dimensionValue < 0) throw new IllegalArgumentException("capacity value cannot be negative");
170+
if (dimensionValue < 0) throw new IllegalArgumentException("The capacity value must not be negative.");
171171
capacityBuilder.addDimension(dimensionIndex, dimensionValue);
172172
return this;
173173
}
174174

175175
public Builder<T> setTimeWindow(TimeWindow tw){
176-
if(tw == null) throw new IllegalArgumentException("time-window arg must not be null");
176+
if (tw == null) throw new IllegalArgumentException("The time window must not be null.");
177177
this.timeWindows = new TimeWindowsImpl();
178178
timeWindows.add(tw);
179179
return this;
180180
}
181181

182182
public Builder<T> addTimeWindow(TimeWindow timeWindow) {
183-
if(timeWindow == null) throw new IllegalArgumentException("time-window arg must not be null");
183+
if (timeWindow == null) throw new IllegalArgumentException("The time window must not be null.");
184184
if(!twAdded){
185185
timeWindows = new TimeWindowsImpl();
186186
twAdded = true;
@@ -205,7 +205,7 @@ public Builder<T> addAllTimeWindows(Collection<TimeWindow> timeWindows) {
205205
* @throws IllegalArgumentException if neither locationId nor coordinate is set.
206206
*/
207207
public T build() {
208-
if (location == null) throw new IllegalArgumentException("location is missing");
208+
if (location == null) throw new IllegalArgumentException("The location of service " + id + " is missing.");
209209
this.setType("service");
210210
capacity = capacityBuilder.build();
211211
skills = skillBuilder.build();
@@ -246,13 +246,13 @@ public Builder<T> addAllSizeDimensions(Capacity size){
246246
*/
247247
public Builder<T> setPriority(int priority) {
248248
if (priority < 1 || priority > 10)
249-
throw new IllegalArgumentException("incorrect priority. only priority values from 1 to 10 are allowed where 1 = high and 10 is low");
249+
throw new IllegalArgumentException("The priority value is not valid. Only 1 (very high) to 10 (very low) are allowed.");
250250
this.priority = priority;
251251
return this;
252252
}
253253

254254
public Builder<T> setMaxTimeInVehicle(double maxTimeInVehicle){
255-
throw new UnsupportedOperationException("maxTimeInVehicle is not yet supported for Pickups and Services (only for Deliveries and Shipments)");
255+
throw new UnsupportedOperationException("The maximum time in vehicle is not yet supported for Pickups and Services (only for Deliveries and Shipments).");
256256
// if(maxTimeInVehicle < 0) throw new IllegalArgumentException("maxTimeInVehicle should be positive");
257257
// this.maxTimeInVehicle = maxTimeInVehicle;
258258
// return this;

jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Shipment.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ public Builder setPickupLocation(Location pickupLocation) {
148148
* @throws IllegalArgumentException if servicTime < 0.0
149149
*/
150150
public Builder setPickupServiceTime(double serviceTime) {
151-
if (serviceTime < 0.0) throw new IllegalArgumentException("serviceTime must not be < 0.0");
151+
if (serviceTime < 0.0)
152+
throw new IllegalArgumentException("The service time of a shipment must not be < 0.0.");
152153
this.pickupServiceTime = serviceTime;
153154
return this;
154155
}
@@ -164,7 +165,7 @@ public Builder setPickupServiceTime(double serviceTime) {
164165
* @throws IllegalArgumentException if timeWindow is null
165166
*/
166167
public Builder setPickupTimeWindow(TimeWindow timeWindow) {
167-
if (timeWindow == null) throw new IllegalArgumentException("delivery time-window must not be null");
168+
if (timeWindow == null) throw new IllegalArgumentException("The delivery time window must not be null.");
168169
this.pickupTimeWindows = new TimeWindowsImpl();
169170
this.pickupTimeWindows.add(timeWindow);
170171
return this;
@@ -193,7 +194,8 @@ public Builder setDeliveryLocation(Location deliveryLocation) {
193194
* @throws IllegalArgumentException if serviceTime < 0.0
194195
*/
195196
public Builder setDeliveryServiceTime(double deliveryServiceTime) {
196-
if (deliveryServiceTime < 0.0) throw new IllegalArgumentException("deliveryServiceTime must not be < 0.0");
197+
if (deliveryServiceTime < 0.0)
198+
throw new IllegalArgumentException("The service time of a delivery must not be < 0.0.");
197199
this.deliveryServiceTime = deliveryServiceTime;
198200
return this;
199201
}
@@ -209,7 +211,7 @@ public Builder setDeliveryServiceTime(double deliveryServiceTime) {
209211
* @throws IllegalArgumentException if timeWindow is null
210212
*/
211213
public Builder setDeliveryTimeWindow(TimeWindow timeWindow) {
212-
if (timeWindow == null) throw new IllegalArgumentException("delivery time-window must not be null");
214+
if (timeWindow == null) throw new IllegalArgumentException("The delivery time window must not be null.");
213215
this.deliveryTimeWindows = new TimeWindowsImpl();
214216
this.deliveryTimeWindows.add(timeWindow);
215217
return this;
@@ -224,7 +226,8 @@ public Builder setDeliveryTimeWindow(TimeWindow timeWindow) {
224226
* @throws IllegalArgumentException if dimVal < 0
225227
*/
226228
public Builder addSizeDimension(int dimensionIndex, int dimensionValue) {
227-
if (dimensionValue < 0) throw new IllegalArgumentException("capacity value cannot be negative");
229+
if (dimensionValue < 0)
230+
throw new IllegalArgumentException("The capacity value must not be negative, but is " + dimensionValue + ".");
228231
capacityBuilder.addDimension(dimensionIndex, dimensionValue);
229232
return this;
230233
}
@@ -245,8 +248,8 @@ public Builder addAllSizeDimensions(Capacity size) {
245248
* is set
246249
*/
247250
public Shipment build() {
248-
if (pickupLocation_ == null) throw new IllegalArgumentException("pickup location is missing");
249-
if (deliveryLocation_ == null) throw new IllegalArgumentException("delivery location is missing");
251+
if (pickupLocation_ == null) throw new IllegalArgumentException("The pickup location is missing.");
252+
if (deliveryLocation_ == null) throw new IllegalArgumentException("The delivery location is missing.");
250253
capacity = capacityBuilder.build();
251254
skills = skillBuilder.build();
252255
return new Shipment(this);
@@ -271,7 +274,7 @@ public Builder setName(String name) {
271274
}
272275

273276
public Builder addDeliveryTimeWindow(TimeWindow timeWindow) {
274-
if(timeWindow == null) throw new IllegalArgumentException("time-window arg must not be null");
277+
if (timeWindow == null) throw new IllegalArgumentException("The time window must not be null.");
275278
if(!deliveryTimeWindowAdded){
276279
deliveryTimeWindows = new TimeWindowsImpl();
277280
deliveryTimeWindowAdded = true;
@@ -291,7 +294,7 @@ public Builder addAllDeliveryTimeWindows(Collection<TimeWindow> timeWindow) {
291294
}
292295

293296
public Builder addPickupTimeWindow(TimeWindow timeWindow) {
294-
if(timeWindow == null) throw new IllegalArgumentException("time-window arg must not be null");
297+
if (timeWindow == null) throw new IllegalArgumentException("The time window must not be null.");
295298
if(!pickupTimeWindowAdded){
296299
pickupTimeWindows = new TimeWindowsImpl();
297300
pickupTimeWindowAdded = true;
@@ -319,7 +322,7 @@ public Builder addAllPickupTimeWindows(Collection<TimeWindow> timeWindow) {
319322
*/
320323
public Builder setPriority(int priority) {
321324
if (priority < 1 || priority > 10)
322-
throw new IllegalArgumentException("incorrect priority. only 1 (very high) to 10 (very low) are allowed");
325+
throw new IllegalArgumentException("The priority value is not valid. Only 1 (very high) to 10 (very low) are allowed.");
323326
this.priority = priority;
324327
return this;
325328
}
@@ -331,7 +334,8 @@ public Builder setPriority(int priority) {
331334
* @return
332335
*/
333336
public Builder setMaxTimeInVehicle(double maxTimeInVehicle){
334-
if(maxTimeInVehicle < 0) throw new IllegalArgumentException("maxTimeInVehicle should be positive");
337+
if (maxTimeInVehicle < 0)
338+
throw new IllegalArgumentException("The maximum time in vehicle must be positive.");
335339
this.maxTimeInVehicle = maxTimeInVehicle;
336340
return this;
337341
}
@@ -436,7 +440,7 @@ public Collection<TimeWindow> getPickupTimeWindows() {
436440
return pickupTimeWindows.getTimeWindows();
437441
}
438442

439-
443+
440444
/**
441445
* Returns a string with the shipment's attributes.
442446
* <p>

jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleTypeImpl.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ public Builder setUserData(Object userData) {
151151
* if velocity is smaller than zero
152152
*/
153153
public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds) {
154-
if (inMeterPerSeconds < 0.0) throw new IllegalArgumentException("velocity cannot be smaller than zero");
154+
if (inMeterPerSeconds < 0.0)
155+
throw new IllegalArgumentException("The velocity of a vehicle (type) cannot be smaller than zero.");
155156
this.maxVelo = inMeterPerSeconds;
156157
return this;
157158
}
@@ -166,7 +167,7 @@ public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds) {
166167
* @throws IllegalArgumentException if fixedCost is smaller than zero
167168
*/
168169
public VehicleTypeImpl.Builder setFixedCost(double fixedCost) {
169-
if (fixedCost < 0.0) throw new IllegalArgumentException("fixed costs cannot be smaller than zero");
170+
if (fixedCost < 0.0) throw new IllegalArgumentException("Fixed costs must not be smaller than zero.");
170171
this.fixedCost = fixedCost;
171172
return this;
172173
}
@@ -181,7 +182,8 @@ public VehicleTypeImpl.Builder setFixedCost(double fixedCost) {
181182
* @throws IllegalArgumentException if perDistance is smaller than zero
182183
*/
183184
public VehicleTypeImpl.Builder setCostPerDistance(double perDistance) {
184-
if (perDistance < 0.0) throw new IllegalArgumentException("cost per distance must not be smaller than zero");
185+
if (perDistance < 0.0)
186+
throw new IllegalArgumentException("Cost per distance must not be smaller than zero.");
185187
this.perDistance = perDistance;
186188
return this;
187189
}
@@ -260,9 +262,9 @@ public VehicleTypeImpl build() {
260262
* @throws IllegalArgumentException if capacity dimension is already set
261263
*/
262264
public Builder addCapacityDimension(int dimIndex, int dimVal) {
263-
if (dimVal < 0) throw new IllegalArgumentException("capacity value cannot be negative");
265+
if (dimVal < 0) throw new IllegalArgumentException("The capacity value must not be negative.");
264266
if (capacityDimensions != null)
265-
throw new IllegalArgumentException("either build your dimension with build your dimensions with " +
267+
throw new IllegalArgumentException("Either build your dimension with build your dimensions with " +
266268
"addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." +
267269
"You used both methods.");
268270
dimensionAdded = true;
@@ -283,7 +285,7 @@ public Builder addCapacityDimension(int dimIndex, int dimVal) {
283285
*/
284286
public Builder setCapacityDimensions(Capacity capacity) {
285287
if (dimensionAdded)
286-
throw new IllegalArgumentException("either build your dimension with build your dimensions with " +
288+
throw new IllegalArgumentException("Either build your dimension with build your dimensions with " +
287289
"addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." +
288290
"You used both methods.");
289291
this.capacityDimensions = capacity;

0 commit comments

Comments
 (0)