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

de.schildbach.pte.dto.Departure Maven / Gradle / Ivy

There is a newer version: 2
Show newest version
/*
 * Copyright 2010-2015 the original author or authors.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */

package de.schildbach.pte.dto;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import java.io.Serializable;
import java.util.Comparator;
import java.util.Date;
import java.util.Locale;

import javax.annotation.Nullable;

import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.base.Objects;

/**
 * @author Andreas Schildbach
 */
@SuppressWarnings("serial")
public final class Departure implements Serializable {
    final public @Nullable Date plannedTime;
    final public @Nullable Date predictedTime;
    final public Line line;
    final public @Nullable Position position;
    final public @Nullable Location destination;
    final public @Nullable int[] capacity;
    final public @Nullable String message;

    public Departure(final Date plannedTime, final Date predictedTime, final Line line, final Position position,
            final Location destination, final int[] capacity, final String message) {
        this.plannedTime = plannedTime;
        this.predictedTime = predictedTime;
        checkArgument(plannedTime != null || predictedTime != null);
        this.line = checkNotNull(line);
        this.position = position;
        this.destination = destination;
        this.capacity = capacity;
        this.message = message;
    }

    public Date getTime() {
        if (predictedTime != null)
            return predictedTime;
        else
            return plannedTime;
    }

    @Override
    public String toString() {
        final ToStringHelper helper = MoreObjects.toStringHelper(this);
        if (plannedTime != null)
            helper.add("planned", String.format(Locale.US, "%ta % TIME_COMPARATOR = new Comparator() {
        @Override
        public int compare(final Departure departure0, final Departure departure1) {
            return departure0.getTime().compareTo(departure1.getTime());
        }
    };
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy