Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
de.aipark.api.parkingarea.ParkingArea Maven / Gradle / Ivy
package de.aipark.api.parkingarea;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.Point;
import de.aipark.api.chargingstation.ChargingPlugType;
import de.aipark.api.payment.PriceModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.*;
/**
* Created by torgen on 24.08.17.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class ParkingArea {
@ApiModelProperty(value = "name of parking area", dataType = "java.lang.String", required = true, example = "Rathaus")
private String name;
@ApiModelProperty(value = "shape of parking area, e.g. multipolygon for areas or line for on street parking", required = true)
private Geometry shape;
@ApiModelProperty(value = "center point of parking area", required = true)
private Point center;
@ApiModelProperty(value = "capacity of parking area (number of spots)", dataType = "java.lang.Integer", required = true, example = "100")
private Integer capacity;
@ApiModelProperty(value = "type of parking area, types getting added in the future", dataType = "de.aipark.api.parkingarea.ParkingAreaType", required = true, example = "ON_STREET")
private String parkingAreaType;
@ApiModelProperty(value = "unique id of parking area", dataType = "java.lang.Long", required = true, example = "504838")
private Long id;
@ApiModelProperty(value =
"value=null indicates no information about capacity designated for disabled, " +
"value>0 indicates number of spots designated for women, " +
"value=0 indicates no special capacity for women, " +
"value=-1 indicates that there are spots designated for women but capacity is unknown",
dataType = "java.lang.Integer", example = "10")
private Integer capacityWoman;
@ApiModelProperty(value =
"value=null indicates no information about capacity designated for disabled, " +
"value>0 indicates number of spots designated for disabled, " +
"value=0 indicates no special capacity for disabled, " +
"value=-1 indicates that there are spots designated for disabled but capacity is unknown",
dataType = "java.lang.Integer", example = "10")
private Integer capacityDisabled;
@ApiModelProperty(value = "schedule when parking area is opened or closed", dataType = "MapEntry")
private MapEntry scheduleOpen;
@ApiModelProperty(value = "schedule for parking disc (value = allowed time in minutes)", dataType = "MapEntry")
private MapEntry scheduleMaxStay;
@ApiModelProperty(value = "price model mapping", dataType = "MapEntry")
private MapEntry schedulePriceModel;
@ApiModelProperty(value = "schedule with capacity of parking area (number of spots) for residential parking only", dataType = "MapEntry")
private MapEntry scheduleResidential;
@ApiModelProperty(value = "entrance point for parking area", dataType = "List")
private List entrancePoints;
@ApiModelProperty(value = "mapping of charging plug type to number of plugs with this type", dataType = "MapEntry")
private MapEntry chargingPlugTypes;
public ParkingArea() {
scheduleOpen = new MapEntry();
scheduleMaxStay = new MapEntry();
schedulePriceModel = new MapEntry();
scheduleResidential = new MapEntry();
entrancePoints = new ArrayList();
chargingPlugTypes = new MapEntry();
}
public ParkingArea(String name, Geometry shape, Point center, Integer capacity, String parkingAreaType, Long id, Integer capacityWoman, Integer capacityDisabled, MapEntry scheduleOpen, MapEntry scheduleMaxStay, MapEntry schedulePriceModel, MapEntry scheduleResidential, List entrancePoints, MapEntry chargingPlugTypes) {
this.name = name;
this.shape = shape;
this.center = center;
this.capacity = capacity;
this.parkingAreaType = parkingAreaType;
this.id = id;
this.capacityWoman = capacityWoman;
this.capacityDisabled = capacityDisabled;
this.scheduleOpen = scheduleOpen;
this.scheduleMaxStay = scheduleMaxStay;
this.schedulePriceModel = schedulePriceModel;
this.scheduleResidential = scheduleResidential;
this.entrancePoints = entrancePoints;
this.chargingPlugTypes = chargingPlugTypes;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Geometry getShape() {
return shape;
}
public void setShape(Geometry shape) {
this.shape = shape;
}
public Integer getCapacity() {
return capacity;
}
public void setCapacity(Integer capacity) {
this.capacity = capacity;
}
public ParkingAreaType getParkingAreaType() {
try{
return ParkingAreaType.valueOf(parkingAreaType);
}
catch (IllegalArgumentException e){
return ParkingAreaType.PARKINGAREA;
}
}
public void setParkingAreaType(String parkingAreaType) {
this.parkingAreaType = parkingAreaType;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Integer getCapacityWoman() {
return capacityWoman;
}
public void setCapacityWoman(Integer capacityWoman) {
this.capacityWoman = capacityWoman;
}
public Integer getCapacityDisabled() {
return capacityDisabled;
}
public void setCapacityDisabled(Integer capacityDisabled) {
this.capacityDisabled = capacityDisabled;
}
public MapEntry getScheduleOpen() {
return scheduleOpen;
}
public void setScheduleOpen(MapEntry scheduleOpen) {
this.scheduleOpen = scheduleOpen;
}
public MapEntry getScheduleMaxStay() {
return scheduleMaxStay;
}
public void setScheduleMaxStay(MapEntry scheduleMaxStay) {
this.scheduleMaxStay = scheduleMaxStay;
}
public MapEntry getSchedulePriceModel() {
return schedulePriceModel;
}
public void setSchedulePriceModel(MapEntry schedulePriceModel) {
this.schedulePriceModel = schedulePriceModel;
}
public MapEntry getScheduleResidential() {
return scheduleResidential;
}
public void setScheduleResidential(MapEntry scheduleResidential) {
this.scheduleResidential = scheduleResidential;
}
public List getEntrancePoints() {
return entrancePoints;
}
public void setEntrancePoints(List entrancePoints) {
this.entrancePoints = entrancePoints;
}
public MapEntry getChargingPlugTypes() {
return chargingPlugTypes;
}
public void setChargingPlugTypes(MapEntry chargingPlugTypes) {
this.chargingPlugTypes = chargingPlugTypes;
}
public Point getCenter() {
return center;
}
public void setCenter(Point center) {
this.center = center;
}
@Override
public String toString() {
return "ParkingArea{" +
"name='" + name + '\'' +
", shape=" + shape +
", center=" + center +
", capacity=" + capacity +
", parkingAreaType=" + parkingAreaType +
", id=" + id +
", capacityWoman=" + capacityWoman +
", capacityDisabled=" + capacityDisabled +
", scheduleOpen=" + scheduleOpen +
", scheduleMaxStay=" + scheduleMaxStay +
", schedulePriceModel=" + schedulePriceModel +
", scheduleResidential=" + scheduleResidential +
", entrancePoints=" + entrancePoints +
", chargingPlugTypes=" + chargingPlugTypes +
'}';
}
@JsonIgnore
public String getPriceString() {
ResourceBundle bundle = ResourceBundle.getBundle("Api");
String result = "";
Map> scheduleListMap = new HashMap>();
for (MapEntry.Entry entry : schedulePriceModel.getEntryList()) {
List priceModels = scheduleListMap.get(entry.getKey());
if (priceModels == null) {
priceModels = new ArrayList();
}
priceModels.add(entry.getValue());
scheduleListMap.put(entry.getKey(), priceModels);
}
List schedules = new ArrayList(scheduleListMap.keySet());
Collections.sort(schedules, new ScheduleComparator());
boolean onlyDefaultPriceModels = false;
for (Schedule schedule : schedules) {
if (schedule.toString().isEmpty()) {
if (schedules.size() > 1) {
result += bundle.getString("otherwise") + ":\n";
} else {
onlyDefaultPriceModels = true;
}
} else {
result += schedule.toString() + ":\n";
}
List priceModels = new ArrayList(scheduleListMap.get(schedule));
Collections.sort(priceModels, new PriceModelComparator());
boolean hasPeriodPricemodels = false;
for (PriceModel priceModel : priceModels) {
if (!onlyDefaultPriceModels) {
result += "\t";
}
if (priceModel.getFromMinute() != null || priceModel.getUntilMinute() != null) {
hasPeriodPricemodels = true;
} else if (hasPeriodPricemodels && priceModel.getInterval() != null && priceModel.getMaxPriceInCent() == null) {
result += bundle.getString("otherwise") + " ";
}
result += priceModel.toString() + "\n";
}
}
return result;
}
@JsonIgnore
public String getMaxStayString() {
ResourceBundle bundle = ResourceBundle.getBundle("Api");
String result = "";
for (MapEntry.Entry entry : scheduleMaxStay.getEntryList()) {
if (!result.isEmpty()) {
result += "\n";
}
result += entry.getKey().toString() + " " + bundle.getString("maximal") + " " + entry.getValue() + " " + bundle.getString("minutes");
}
return result;
}
private class ScheduleComparator implements Comparator {
@Override
public int compare(Schedule o1, Schedule o2) {
if (o1.toString().isEmpty()) {
return 1;
}
if (o2.toString().isEmpty()) {
return -1;
} else {
return o1.toString().length() - o2.toString().length();
}
}
}
private class PriceModelComparator implements Comparator {
@Override
public int compare(PriceModel o1, PriceModel o2) {
if ((o1.getFromMinute() != null || o1.getUntilMinute() != null)
&& (o2.getFromMinute() == null || o2.getUntilMinute() == null)) {
return -1;
}
if ((o2.getFromMinute() != null || o2.getUntilMinute() != null)
&& (o1.getFromMinute() == null || o1.getUntilMinute() == null)) {
return 1;
}
if (o1.getFromMinute() != null && o2.getFromMinute() != null) {
return o1.getFromMinute() - o2.getFromMinute();
}
if (o1.getUntilMinute() != null && o2.getUntilMinute() != null) {
return o1.getUntilMinute() - o2.getUntilMinute();
}
if (o1.getInterval() != null && o2.getInterval() != null) {
return o1.getInterval() - o2.getInterval();
}
if (o1.getInterval() != null && o2.getInterval() == null) {
return -1;
}
if (o1.getInterval() == null && o2.getInterval() != null) {
return 1;
}
if (o1.getMaxPriceInCent() == null && o2.getMaxPriceInCent() != null) {
return -1;
}
return 0;
}
}
}