/** * Builds and returns the vehicle. * * <p>if {@link VehicleType} is not set, default vehicle-type is set with id="default" and * capacity=0 * * <p>if startLocationId || locationId is null (=> startLocationCoordinate || locationCoordinate * must be set) then startLocationId=startLocationCoordinate.toString() and * locationId=locationCoordinate.toString() [coord.toString() --> [x=x_val][y=y_val]) * * <p>if endLocationId is null and endLocationCoordinate is set then * endLocationId=endLocationCoordinate.toString() * * <p>if endLocationId==null AND endLocationCoordinate==null then endLocationId=startLocationId * AND endLocationCoord=startLocationCoord 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) or (endLocationId!=null AND * returnToDepot=false) */ public VehicleImpl build() { 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>" + "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"); } skills = skillBuilder.build(); return new VehicleImpl(this); }