/** * Add the vehicle to the container. * * @param v * @throws IllegalArgumentException if another {@link Vehicle} with * the same {@link Id} already exists in the container. */ @Override public void addVehicle(final Vehicle v) { /* Validation. */ if(this.getVehicles().containsKey(v.getId())){ throw new IllegalArgumentException("Vehicle with id = " + v.getId() + " already exists."); } /* Check if the VehicleType associated with the vehicle already exist. * Here only an error message is given. A RuntimeException is thrown * when the VehicleWriterV1 is called (JWJ, '14). */ if(!this.vehicleTypes.containsKey(v.getType().getId())){ throw new IllegalArgumentException("Cannot add Vehicle with type = " + v.getType().getId().toString() + " if the VehicleType has not been added to the Vehicles container."); } /* Add the vehicle. */ this.vehicles.put(v.getId(), v); this.counter.incCounter(); }