All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.aipark.api.payment.PriceModel Maven / Gradle / Ivy

Go to download

AIPARK offers detailed parking information for more than 1.8 Mio parking areas in Germany with nationwide coverage. Additionally, accurate occupancy predictions are derived using data from a network of more than 5 million smartphones. Use the AIPARK API Explorer application to try out and test the interface. Please send a request via email if you are a developer and require an API key. We'll be in touch with you shortly. This application is provided via a demo backend environment. Please note that API load tests do not reflect the performance of the productive system. Mail: [email protected]

There is a newer version: 30.06
Show newest version
package de.aipark.api.payment;

import io.swagger.annotations.ApiModelProperty;

import java.util.Currency;
import java.util.Locale;
import java.util.ResourceBundle;

/**
 * Created by torgen on 13.07.17.
 */
public class PriceModel implements Comparable {

    @ApiModelProperty(position = 1, value = "start time in minutes", example = "30")
    private Integer fromMinute;

    @ApiModelProperty(position = 2, value = "end time in minutes", example = "90")
    private Integer untilMinute;

    @ApiModelProperty(position = 3, value = "interval time in minutes, e.g. 50 cent per 30 minutes", dataType = "java.lang.Integer", required = true, example = "30")
    private Integer interval;

    @ApiModelProperty(position = 4, value = "price in cent, value=-1 means paid but price is unknown, value=0 means free", required = true, example = "50")
    private Integer priceInCent;

    @ApiModelProperty(position = 5, value = "priority, e.g. one price model could dominate another", dataType = "java.lang.Integer", example = "50")
    private Integer priority;

    @ApiModelProperty(position = 6, value = "textual description for special price models", dataType = "java.lang.String", example = "Tennisclub")
    private String description;

    @ApiModelProperty(position = 7, value = "maximal price in cent", example = "50")
    private Integer maxPriceInCent;

    @ApiModelProperty(position = 8, value = "currency", dataType = "java.lang.String", example = "EUR")
    private Currency currency;

    public PriceModel() {
        this.currency = Currency.getInstance("EUR");
    }

    public PriceModel(Integer fromMinute, Integer untilMinute, Integer interval, Integer priceInCent, Integer priority, String description, Integer maxPriceInCent, Currency currency) {
        this.fromMinute = fromMinute;
        this.untilMinute = untilMinute;
        this.interval = interval;
        this.priceInCent = priceInCent;
        this.priority = priority;
        this.description = description;
        this.maxPriceInCent = maxPriceInCent;
        this.currency = currency;
    }

    public Integer getFromMinute() {
        return fromMinute;
    }

    public void setFromMinute(Integer fromMinute) {
        this.fromMinute = fromMinute;
    }

    public Integer getUntilMinute() {
        return untilMinute;
    }

    public void setUntilMinute(Integer untilMinute) {
        this.untilMinute = untilMinute;
    }

    public Integer getInterval() {
        return interval;
    }

    public void setInterval(Integer interval) {
        this.interval = interval;
    }

    public Integer getPriceInCent() {
        return priceInCent;
    }

    public void setPriceInCent(Integer priceInCent) {
        this.priceInCent = priceInCent;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getMaxPriceInCent() {
        return maxPriceInCent;
    }

    public void setMaxPriceInCent(Integer maxPriceInCent) {
        this.maxPriceInCent = maxPriceInCent;
    }

    public Currency getCurrency() {
        return currency;
    }

    public void setCurrency(Currency currency) {
        this.currency = currency;
    }

    @Override
    public int compareTo(PriceModel o) {
        if ((getFromMinute() != null || getUntilMinute() != null)
                && (o.getFromMinute() == null || o.getUntilMinute() == null)) {
            return -1;
        }
        if ((o.getFromMinute() != null || o.getUntilMinute() != null)
                && (getFromMinute() == null || getUntilMinute() == null)) {
            return 1;
        }
        if (getFromMinute() != null && o.getFromMinute() != null) {
            return getFromMinute() - o.getFromMinute();
        }
        if (getUntilMinute() != null && o.getUntilMinute() != null) {
            return getUntilMinute() - o.getUntilMinute();
        }
        if (getInterval() != null && o.getInterval() != null) {
            return getInterval() - o.getInterval();
        }
        if (getInterval() != null && o.getInterval() == null) {
            return -1;
        }
        if (getInterval() == null && o.getInterval() != null) {
            return 1;
        }
        if (getMaxPriceInCent() == null && o.getMaxPriceInCent() != null) {
            return -1;
        }
        return 0;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        PriceModel that = (PriceModel) o;

        if (fromMinute != null ? !fromMinute.equals(that.fromMinute) : that.fromMinute != null) return false;
        if (untilMinute != null ? !untilMinute.equals(that.untilMinute) : that.untilMinute != null) return false;
        if (interval != null ? !interval.equals(that.interval) : that.interval != null) return false;
        if (priceInCent != null ? !priceInCent.equals(that.priceInCent) : that.priceInCent != null) return false;
        if (priority != null ? !priority.equals(that.priority) : that.priority != null) return false;
        return description != null ? description.equals(that.description) : that.description == null;
    }

    @Override
    public int hashCode() {
        int result = fromMinute != null ? fromMinute.hashCode() : 0;
        result = 31 * result + (untilMinute != null ? untilMinute.hashCode() : 0);
        result = 31 * result + (interval != null ? interval.hashCode() : 0);
        result = 31 * result + (priceInCent != null ? priceInCent.hashCode() : 0);
        result = 31 * result + (priority != null ? priority.hashCode() : 0);
        result = 31 * result + (description != null ? description.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        //don't copy the following line
        ResourceBundle bundle = ResourceBundle.getBundle("Api");


        //---- COPY CODE FROM HERE TO de.aipark.backend.modules.parser.parkingarea.scheduleparser.jsCompatible.PriceModel.priceModelToString() ------
        String result = "";
        if ((description == null || description.isEmpty()) && (priceInCent == null || priceInCent == -1) && maxPriceInCent == null) {
            result += bundle.getString("withCosts") + " ";
        } else if (priceInCent != null && priceInCent != -1) {
            result += getCurrencyAsString(priceInCent)+ " ";
        }
        if (maxPriceInCent != null) {
            result += bundle.getString("maximal") + " " + getCurrencyAsString(maxPriceInCent) + " ";
        }
        if (interval != null) {
            result += bundle.getString("inIntervalOf") + " " + getTimeString(interval, bundle, true) + " ";
        }
        if (fromMinute != null && fromMinute > 0) {
            if (untilMinute != null) {
                result += " ";
            } else {
                result += " " + bundle.getString("from") + " ";
            }
            result += getTimeString(fromMinute, bundle, false) + " ";
        }
        if (untilMinute != null) {
            result += bundle.getString("until") + " " + getTimeString(untilMinute, bundle, false) + " ";
        }
        if (description != null) {
            result += description;
        }
        result = result.trim();

        return result;

        //---- COPY CODE UNTIL HERE TO de.aipark.backend.modules.parser.parkingarea.scheduleparser.jsCompatible.PriceModel.priceModelToString() ------
    }

    private String getTimeString(Integer minute, ResourceBundle bundle, boolean isInterval) {
        int days = (int) Math.floor(minute / 60f / 24f);
        int hours = minute / 60 % 24; //since both are ints, you get an int
        int minutes = minute % 60;

        String time = "";
        if (days > 0) {
            if (days == 1) {
                if (isInterval) {
                    time = bundle.getString("day") + " ";
                } else {
                    time = bundle.getString("oneDay") + " ";
                }
            } else {
                time = days + " " + bundle.getString("days") + " ";
            }
        }
        if (hours > 0) {
            String hourString = "";
            if (!time.isEmpty()) {
                hourString += bundle.getString("and") + " ";
            }
            if (hours == 1) {
                if (isInterval) {
                    hourString += bundle.getString("hour") + " ";
                } else {
                    hourString += bundle.getString("oneHour") + " ";
                }
            } else {
                hourString += hours + " " + bundle.getString("hours") + " ";
            }
            time += hourString;
        }
        if (minutes > 0) {
            String minuteString = "";
            if (!time.isEmpty()) {
                minuteString += bundle.getString("and") + " ";
            }
            if (minutes == 1) {
                if (isInterval) {
                    minuteString += bundle.getString("minute") + " ";
                } else {
                    minuteString += bundle.getString("oneMinute") + " ";
                }
            } else {
                minuteString += minutes + " " + bundle.getString("minutes") + " ";
            }
            time += minuteString;
        }
        time = time.trim();
        return time;
    }

//    /**
//     * use {@link #getCurrencyAsString(Integer)} instead
//     */
//    //TODO: remove later
//    @Deprecated
//    protected String getCurrenceAsString(Integer priceInCent) {
//        return getCurrencyAsString(priceInCent);
//    }

    protected String getCurrencyAsString(Integer priceInCent) {
        int euro = priceInCent / 100;
        int cent = priceInCent % 100;
        String centString = "" + cent;
        if (cent < 10) {
            centString = "0" + centString;
        }
        return euro + "," + centString + currency.getSymbol(Locale.getDefault());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy