public VehicleReaderV1(final Vehicles vehicles) { this.vehicles = vehicles; this.builder = this.vehicles.getFactory(); }
public void run() { VehiclesFactory vb = this.vehicles.getFactory(); VehicleType vehicleType = vb.createVehicleType(Id.create("defaultTransitVehicleType", VehicleType.class)); VehicleCapacity capacity = new VehicleCapacityImpl(); capacity.setSeats(Integer.valueOf(101)); capacity.setStandingRoom(Integer.valueOf(0)); vehicleType.setCapacity(capacity); this.vehicles.addVehicleType(vehicleType); long vehId = 0; for (TransitLine line : this.schedule.getTransitLines().values()) { for (TransitRoute route : line.getRoutes().values()) { for (Departure departure : route.getDepartures().values()) { Vehicle veh = vb.createVehicle(Id.create("tr_" + Long.toString(vehId++), Vehicle.class), vehicleType); this.vehicles.addVehicle(veh); departure.setVehicleId(veh.getId()); } } } } }
@Test public void testGetVehicleTypes(){ Vehicles vehicles = VehicleUtils.createVehiclesContainer(); VehicleType t1 = vehicles.getFactory().createVehicleType(Id.create("type1", VehicleType.class)); /* Should get an unmodifiable Map of the Vehicles container. */ try{ vehicles.getVehicleTypes().put(Id.create("type1", VehicleType.class), t1 ); Assert.fail("Should not be able to add to an unmodiafiable Map"); } catch (UnsupportedOperationException e){ /* Pass. */ } }
@Test public void testAddVehicleType(){ Vehicles vehicles = VehicleUtils.createVehiclesContainer(); VehicleType t1 = vehicles.getFactory().createVehicleType(Id.create("type1", VehicleType.class)); VehicleType t2 = vehicles.getFactory().createVehicleType(Id.create("type1", VehicleType.class)); vehicles.addVehicleType(t1); try{ vehicles.addVehicleType(t2); Assert.fail("Cannot add another vehicle type with the same Id"); } catch (IllegalArgumentException e){ /* Pass. */ } }
@Test public void testRemoveVehicle() { Vehicles vehicles = VehicleUtils.createVehiclesContainer(); VehicleType t1 = vehicles.getFactory().createVehicleType(Id.create("type1", VehicleType.class)); vehicles.addVehicleType(t1); Vehicle v1 = vehicles.getFactory().createVehicle(Id.create("v1", Vehicle.class), t1); Assert.assertEquals(0, vehicles.getVehicles().size()); vehicles.addVehicle(v1); Assert.assertEquals(1, vehicles.getVehicles().size()); vehicles.removeVehicle(Id.create("v1", Vehicle.class)); Assert.assertEquals(0, vehicles.getVehicles().size()); }
private void createVehicles() { Vehicles vehicles = this.scenario.getTransitVehicles(); VehiclesFactory vb = vehicles.getFactory(); VehicleType vehicleType = vb.createVehicleType(Id.create("transitVehicleType", VehicleType.class)); vehicles.addVehicleType(vehicleType); VehicleCapacity capacity = vb.createVehicleCapacity(); capacity.setSeats(101); capacity.setStandingRoom(0); vehicleType.setCapacity(capacity); for (int i = 0; i < nOfBuses; i++) { vehicles.addVehicle( vb.createVehicle(Id.create(i, Vehicle.class), vehicleType)); } }
@Test public void testGetVehicles(){ Vehicles vehicles = VehicleUtils.createVehiclesContainer(); VehicleType testType = vehicles.getFactory().createVehicleType(Id.create("test", VehicleType.class)); vehicles.addVehicleType(testType); Vehicle v1 = vehicles.getFactory().createVehicle(Id.create("v1", Vehicle.class), testType); /* Should get an unmodifiable Map of the Vehicles container. */ try{ vehicles.getVehicles().put(Id.create("v1", Vehicle.class), v1 ); vehicles.getVehicles(); Assert.fail("Should not be able to add to an unmodiafiable Map"); } catch (UnsupportedOperationException e){ /* Pass. */ } }
VehiclesFactory vehFactory = vehicles.getFactory(); VehicleType vehType = vehFactory.createVehicleType(Id.create(this.pConfig.getPIdentifier(), VehicleType.class)); VehicleCapacity capacity = new VehicleCapacityImpl();
@Test public void testAddVehicle() { Vehicles vehicles = VehicleUtils.createVehiclesContainer(); VehicleType testType = vehicles.getFactory().createVehicleType(Id.create("test", VehicleType.class)); Vehicle v1 = vehicles.getFactory().createVehicle(Id.create("v1", Vehicle.class), testType); /* Must add vehicle type before adding vehicle. */ try{ vehicles.addVehicle(v1); Assert.fail("Should not allow adding a vehicle if vehicle type has not been added to container first."); } catch(IllegalArgumentException e){ /* Pass. */ } vehicles.addVehicleType(testType); vehicles.addVehicle(v1); Vehicle v2 = vehicles.getFactory().createVehicle(Id.create("v1", Vehicle.class), testType); try{ vehicles.addVehicle(v2); Assert.fail("Cannot add another vehicle with the same Id."); } catch (IllegalArgumentException e){ /* Pass. */ } }
private void createVehicles() { Vehicles vehicles = this.scenario.getTransitVehicles(); VehiclesFactory vb = vehicles.getFactory(); VehicleType vehicleType = vb.createVehicleType(Id.create("transitVehicleType", VehicleType.class)); VehicleCapacity capacity = vb.createVehicleCapacity(); capacity.setSeats(101); capacity.setStandingRoom(0); vehicleType.setCapacity(capacity); vehicles.addVehicleType(vehicleType); Id<Vehicle> id = Id.create("tr_1", Vehicle.class); vehicles.addVehicle( vb.createVehicle(id, vehicleType)); id = Id.create("tr_2", Vehicle.class); vehicles.addVehicle( vb.createVehicle(id, vehicleType)); }
@Test public void testRemoveVehicleType() { Vehicles vehicles = VehicleUtils.createVehiclesContainer(); VehicleType t1 = vehicles.getFactory().createVehicleType(Id.create("type1", VehicleType.class)); vehicles.addVehicleType(t1); Vehicle v1 = vehicles.getFactory().createVehicle(Id.create("v1", Vehicle.class), t1); vehicles.addVehicle(v1); try { vehicles.removeVehicleType(t1.getId()); Assert.fail("expected exception, as vehicle type is still in use."); } catch (IllegalArgumentException e) { // pass } vehicles.removeVehicle(v1.getId()); vehicles.removeVehicleType(t1.getId()); // also test for non-existant vehicle types vehicles.removeVehicleType(Id.create("type2", VehicleType.class)); }
VehiclesFactory vb = vehicles.getFactory(); VehicleType vehicleType = vb.createVehicleType(Id.create("transitVehicleType", VehicleType.class)); VehicleCapacity capacity = vb.createVehicleCapacity();
Arrays.asList(link12, link23, link34, link45).forEach(l -> l.setFreespeed(10.0)); Vehicle vehicle = scenario.getVehicles().getFactory().createVehicle(Id.createVehicleId("P"), VehicleUtils.getDefaultVehicleType()); scenario.getVehicles().addVehicleType(VehicleUtils.getDefaultVehicleType());
Arrays.asList(link12, link23, link34, link45).forEach(l -> l.setFreespeed(10.0)); Vehicle vehicle = scenario.getVehicles().getFactory().createVehicle(Id.createVehicleId("P"), VehicleUtils.getDefaultVehicleType()); scenario.getVehicles().addVehicleType(VehicleUtils.getDefaultVehicleType());
VehicleType vehicleType = vehicles.getFactory().createVehicleType(Id.create("VT1", VehicleType.class)); VehicleCapacity vehicleCapacity = vehicles.getFactory().createVehicleCapacity(); vehicleCapacity.setSeats(30); vehicleCapacity.setStandingRoom(70); vehicles.addVehicleType(vehicleType); Vehicle vehicle = vehicles.getFactory().createVehicle(Id.create("V1", Vehicle.class), vehicleType); vehicles.addVehicle(vehicle);