001package org.matsim.contrib.carsharing.stations;
002
003import java.util.ArrayList;
004import java.util.HashMap;
005import java.util.Map;
006
007import org.matsim.api.core.v01.network.Link;
008import org.matsim.contrib.carsharing.vehicles.CSVehicle;
009/** 
010 * @author balac
011 */
012
013public class OneWayCarsharingStation implements CarsharingStation{
014
015        private Map<String, Integer> numberOfvehiclesPerType = new HashMap<String, Integer>();
016        private Map<String, ArrayList<CSVehicle>> vehiclesPerType = new HashMap<String, ArrayList<CSVehicle>>();
017        private String stationId;
018        private int avaialbleParkingSpots;
019        private Link link;
020
021        public OneWayCarsharingStation(String stationId, Link link, Map<String, Integer> numberOfvehiclesPerType,
022                        Map<String, ArrayList<CSVehicle>> vehiclesPerType, int availableParkingSpots) {
023                this.link = link;
024                this.stationId = stationId;
025                this.numberOfvehiclesPerType = numberOfvehiclesPerType;
026                this.vehiclesPerType = vehiclesPerType;
027                this.setAvaialbleParkingSpots(availableParkingSpots);
028
029        }
030        
031        public int getNumberOfVehicles(String type) {
032                if (this.numberOfvehiclesPerType.containsKey(type))
033                        return this.numberOfvehiclesPerType.get(type);
034                else 
035                        return 0;
036        }       
037        
038        public ArrayList<CSVehicle> getVehicles(String type) {
039                if (this.vehiclesPerType.containsKey(type))
040                        return this.vehiclesPerType.get(type);
041                else
042                        return new ArrayList<CSVehicle>();
043        }       
044
045        public void removeCar(String type, CSVehicle vehicle) {
046                
047                ArrayList<CSVehicle> currentVehicles = this.vehiclesPerType.get(type);          
048                currentVehicles.remove(vehicle);
049                int currentNumberOfVehicles = this.numberOfvehiclesPerType.get(type);
050                currentNumberOfVehicles--;
051                this.numberOfvehiclesPerType.put(type, currentNumberOfVehicles);
052                
053        }
054        
055        public void addCar(String type, CSVehicle vehicle){
056                
057                ArrayList<CSVehicle> currentVehicles = this.vehiclesPerType.get(type);          
058                
059                if (currentVehicles == null)
060                        currentVehicles = new ArrayList<CSVehicle>();
061                
062                currentVehicles.add(vehicle);
063                this.vehiclesPerType.put(type, currentVehicles);
064                if (this.numberOfvehiclesPerType.get(type) == null)
065                        this.numberOfvehiclesPerType.put(type, 1);      
066                else {
067                        int currentNumberOfVehicles = this.numberOfvehiclesPerType.get(type);
068                        currentNumberOfVehicles++;
069                        this.numberOfvehiclesPerType.put(type, currentNumberOfVehicles);
070                }
071        }
072
073        @Override
074        public String getStationId() {
075                return stationId;
076        }
077        
078        private void setAvaialbleParkingSpots(int i) {
079
080                this.avaialbleParkingSpots = i;
081        }
082
083        public void reserveParkingSpot() {
084
085                this.setAvaialbleParkingSpots(this.getAvaialbleParkingSpots() - 1);
086        }       
087
088        public void freeParkingSpot() {
089                this.setAvaialbleParkingSpots(this.getAvaialbleParkingSpots() + 1);
090        }
091
092        public int getAvaialbleParkingSpots() {
093                return avaialbleParkingSpots;
094        }
095        @Override
096        public Link getLink() {
097                return link;
098        }
099
100        public Map<String, ArrayList<CSVehicle>> getVehiclesPerType() {
101                return vehiclesPerType;
102        }
103
104        public void removeCar(CSVehicle vehicle) {
105                String type = vehicle.getType();
106                ArrayList<CSVehicle> currentVehicles = this.vehiclesPerType.get(type);          
107                currentVehicles.remove(vehicle);
108                int currentNumberOfVehicles = this.numberOfvehiclesPerType.get(type);
109                currentNumberOfVehicles--;
110                this.numberOfvehiclesPerType.put(type, currentNumberOfVehicles);                
111                
112        }
113        
114}