mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-13 16:20:34 +00:00
Guava: Use MoreObjects.ToStringHelper to implement .toString().
This commit is contained in:
parent
797448ef0e
commit
353e5815c7
14 changed files with 148 additions and 166 deletions
|
@ -20,7 +20,10 @@ package de.schildbach.pte.dto;
|
|||
import java.io.Serializable;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.MoreObjects.ToStringHelper;
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
|
@ -61,18 +64,12 @@ public final class Departure implements Serializable
|
|||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final StringBuilder builder = new StringBuilder("Departure(");
|
||||
builder.append(plannedTime != null ? plannedTime : "null");
|
||||
builder.append(",");
|
||||
builder.append(predictedTime != null ? predictedTime : "null");
|
||||
builder.append(",");
|
||||
builder.append(line != null ? line : "null");
|
||||
builder.append(",");
|
||||
builder.append(position != null ? position : "null");
|
||||
builder.append(",");
|
||||
builder.append(destination != null ? destination : "null");
|
||||
builder.append(")");
|
||||
return builder.toString();
|
||||
final ToStringHelper helper = MoreObjects.toStringHelper(this);
|
||||
if (plannedTime != null)
|
||||
helper.add("planned", String.format(Locale.US, "%ta %<tR", plannedTime));
|
||||
if (predictedTime != null)
|
||||
helper.add("predicted", String.format(Locale.US, "%ta %<tR", predictedTime));
|
||||
return helper.addValue(line).addValue(position).add("destination", destination).omitNullValues().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,6 +20,7 @@ package de.schildbach.pte.dto;
|
|||
import java.io.Serializable;
|
||||
import java.util.Currency;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
|
@ -77,4 +78,11 @@ public final class Fare implements Serializable
|
|||
{
|
||||
return Objects.hashCode(network, type, currency, fare, unitName, units);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return MoreObjects.toStringHelper(this).addValue(network).addValue(type).addValue(currency).addValue(fare).addValue(unitName).addValue(units)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ package de.schildbach.pte.dto;
|
|||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
|
@ -79,15 +80,6 @@ public final class Line implements Serializable, Comparable<Line>
|
|||
return attrs != null && attrs.contains(attr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final StringBuilder builder = new StringBuilder("Line(");
|
||||
builder.append(label);
|
||||
builder.append(")");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
|
@ -105,6 +97,12 @@ public final class Line implements Serializable, Comparable<Line>
|
|||
return Objects.hashCode(label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return MoreObjects.toStringHelper(this).addValue(label).toString();
|
||||
}
|
||||
|
||||
public int compareTo(final Line other)
|
||||
{
|
||||
final int productThis = PRODUCT_ORDER.indexOf(this.product);
|
||||
|
|
|
@ -19,6 +19,7 @@ package de.schildbach.pte.dto;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
|
@ -35,17 +36,6 @@ public final class LineDestination implements Serializable
|
|||
this.destination = destination;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder("LineDestination(");
|
||||
builder.append(line != null ? line : "null");
|
||||
builder.append(",");
|
||||
builder.append(destination != null ? destination : "null");
|
||||
builder.append(")");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
|
@ -66,4 +56,10 @@ public final class LineDestination implements Serializable
|
|||
{
|
||||
return Objects.hashCode(line, destination);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return MoreObjects.toStringHelper(this).add("line", line).add("destination", destination).omitNullValues().toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ package de.schildbach.pte.dto;
|
|||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.MoreObjects.ToStringHelper;
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
|
@ -152,13 +154,6 @@ public final class Location implements Serializable
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "[" + type + " " + id + " " + lat + "/" + lon + " " + (place != null ? "\"" + place + "\"" : "null") + " "
|
||||
+ (name != null ? "\"" + name + "\"" : "null") + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
|
@ -190,4 +185,13 @@ public final class Location implements Serializable
|
|||
else
|
||||
return Objects.hashCode(type, lat, lon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final ToStringHelper helper = MoreObjects.toStringHelper(this).addValue(type).addValue(id);
|
||||
if (lat != 0 || lon != 0)
|
||||
helper.addValue(lat + "/" + lon);
|
||||
return helper.add("place", place).add("name", name).omitNullValues().toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@ package de.schildbach.pte.dto;
|
|||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.MoreObjects.ToStringHelper;
|
||||
|
||||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
|
@ -51,11 +54,9 @@ public final class NearbyStationsResult implements Serializable
|
|||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final StringBuilder builder = new StringBuilder(getClass().getSimpleName());
|
||||
builder.append("[").append(this.status);
|
||||
final ToStringHelper helper = MoreObjects.toStringHelper(this).addValue(status);
|
||||
if (stations != null)
|
||||
builder.append(" ").append(stations.size()).append(stations);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
helper.add("size", stations.size()).add("stations", stations);
|
||||
return helper.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,12 +39,6 @@ public final class Point implements Serializable
|
|||
return new Point((int) Math.round(lat * 1E6), (int) Math.round(lon * 1E6));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "[" + lat + "/" + lon + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
|
@ -65,4 +59,10 @@ public final class Point implements Serializable
|
|||
{
|
||||
return Objects.hashCode(lat, lon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return lat + "/" + lon;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,9 @@ import java.io.Serializable;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.MoreObjects.ToStringHelper;
|
||||
|
||||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
|
@ -47,17 +50,6 @@ public final class QueryDeparturesResult implements Serializable
|
|||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final StringBuilder builder = new StringBuilder(getClass().getSimpleName());
|
||||
builder.append("[").append(this.status);
|
||||
if (stationDepartures != null)
|
||||
builder.append(" ").append(stationDepartures.size()).append(stationDepartures);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public StationDepartures findStationDepartures(final String stationId)
|
||||
{
|
||||
for (final StationDepartures departures : stationDepartures)
|
||||
|
@ -68,4 +60,13 @@ public final class QueryDeparturesResult implements Serializable
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final ToStringHelper helper = MoreObjects.toStringHelper(this).addValue(status);
|
||||
if (stationDepartures != null)
|
||||
helper.add("size", stationDepartures.size()).add("stationDepartures", stationDepartures);
|
||||
return helper.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@ package de.schildbach.pte.dto;
|
|||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.MoreObjects.ToStringHelper;
|
||||
|
||||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
|
@ -97,31 +100,25 @@ public final class QueryTripsResult implements Serializable
|
|||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final StringBuilder builder = new StringBuilder(getClass().getSimpleName());
|
||||
builder.append("[").append(this.status).append(" ");
|
||||
|
||||
final ToStringHelper helper = MoreObjects.toStringHelper(this).addValue(status);
|
||||
if (status == Status.OK)
|
||||
{
|
||||
if (trips != null)
|
||||
builder.append(trips.size()).append(trips);
|
||||
helper.add("size", trips.size()).add("trips", trips);
|
||||
}
|
||||
else if (status == Status.AMBIGUOUS)
|
||||
{
|
||||
if (ambiguousFrom != null)
|
||||
builder.append(ambiguousFrom.size()).append(" ambiguous from, ");
|
||||
helper.add("size", ambiguousFrom.size()).add("ambiguousFrom", ambiguousFrom);
|
||||
if (ambiguousVia != null)
|
||||
builder.append(ambiguousVia.size()).append(" ambiguous via, ");
|
||||
helper.add("size", ambiguousVia.size()).add("ambiguousVia", ambiguousVia);
|
||||
if (ambiguousTo != null)
|
||||
builder.append(ambiguousTo.size()).append(" ambiguous to, ");
|
||||
helper.add("size", ambiguousTo.size()).add("ambiguousTo", ambiguousTo);
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.append(this.status);
|
||||
helper.addValue(status);
|
||||
}
|
||||
|
||||
if (builder.substring(builder.length() - 2).equals(", "))
|
||||
builder.setLength(builder.length() - 2);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
return helper.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ package de.schildbach.pte.dto;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
|
||||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
|
@ -44,4 +46,11 @@ public final class ResultHeader implements Serializable
|
|||
this.serverTime = serverTime;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return MoreObjects.toStringHelper(this).add("serverProduct", serverProduct).add("serverVersion", serverVersion).add("serverTime", serverTime)
|
||||
.add("context", context).omitNullValues().toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ package de.schildbach.pte.dto;
|
|||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.MoreObjects.ToStringHelper;
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
|
@ -38,19 +40,6 @@ public final class StationDepartures implements Serializable
|
|||
this.lines = lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final StringBuilder builder = new StringBuilder(getClass().getSimpleName());
|
||||
builder.append("[");
|
||||
if (location != null)
|
||||
builder.append(location);
|
||||
if (departures != null)
|
||||
builder.append(" ").append(departures.size()).append(" departures");
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
|
@ -73,4 +62,13 @@ public final class StationDepartures implements Serializable
|
|||
{
|
||||
return Objects.hashCode(location, departures, lines);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final ToStringHelper helper = MoreObjects.toStringHelper(this).addValue(location);
|
||||
if (departures != null)
|
||||
helper.add("size", departures.size()).add("departures", departures);
|
||||
return helper.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,10 @@ package de.schildbach.pte.dto;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.MoreObjects.ToStringHelper;
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
|
@ -195,31 +198,6 @@ public final class Stop implements Serializable
|
|||
return plannedArrivalTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final StringBuilder builder = new StringBuilder("Stop('");
|
||||
builder.append(location);
|
||||
builder.append("', arr: ");
|
||||
builder.append(plannedArrivalTime != null ? plannedArrivalTime : "-");
|
||||
builder.append("/");
|
||||
builder.append(arrivalCancelled ? "cancelled" : (predictedArrivalTime != null ? predictedArrivalTime : "-"));
|
||||
builder.append(", ");
|
||||
builder.append(plannedArrivalPosition != null ? plannedArrivalPosition : "-");
|
||||
builder.append("/");
|
||||
builder.append(predictedArrivalPosition != null ? predictedArrivalPosition : "-");
|
||||
builder.append(", dep: ");
|
||||
builder.append(plannedDepartureTime != null ? plannedDepartureTime : "-");
|
||||
builder.append("/");
|
||||
builder.append(departureCancelled ? "cancelled" : (predictedDepartureTime != null ? predictedDepartureTime : "-"));
|
||||
builder.append(", ");
|
||||
builder.append(plannedDeparturePosition != null ? plannedDeparturePosition : "-");
|
||||
builder.append("/");
|
||||
builder.append(predictedDeparturePosition != null ? predictedDeparturePosition : "-");
|
||||
builder.append(")");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
|
@ -260,4 +238,23 @@ public final class Stop implements Serializable
|
|||
arrivalCancelled, plannedDepartureTime, predictedDepartureTime, plannedDeparturePosition, predictedDeparturePosition,
|
||||
departureCancelled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final ToStringHelper helper = MoreObjects.toStringHelper(this).addValue(location);
|
||||
if (plannedArrivalTime != null)
|
||||
helper.add("plannedArrivalTime", String.format(Locale.US, "%ta %<tR", plannedArrivalTime));
|
||||
if (arrivalCancelled)
|
||||
helper.addValue("cancelled");
|
||||
else if (predictedArrivalTime != null)
|
||||
helper.add("predictedArrivalTime", String.format(Locale.US, "%ta %<tR", predictedArrivalTime));
|
||||
if (plannedDepartureTime != null)
|
||||
helper.add("plannedDepartureTime", String.format(Locale.US, "%ta %<tR", plannedDepartureTime));
|
||||
if (departureCancelled)
|
||||
helper.addValue("cancelled");
|
||||
else if (predictedDepartureTime != null)
|
||||
helper.add("predictedDepartureTime", String.format(Locale.US, "%ta %<tR", predictedDepartureTime));
|
||||
return helper.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,9 @@ import java.util.Collections;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.MoreObjects.ToStringHelper;
|
||||
|
||||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
|
@ -52,17 +55,6 @@ public final class SuggestLocationsResult implements Serializable
|
|||
this.suggestedLocations = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final StringBuilder builder = new StringBuilder(getClass().getSimpleName());
|
||||
builder.append("[").append(this.status);
|
||||
if (suggestedLocations != null)
|
||||
builder.append(" ").append(suggestedLocations.size()).append(suggestedLocations);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public List<Location> getLocations()
|
||||
{
|
||||
final List<Location> locations = new ArrayList<Location>(suggestedLocations.size());
|
||||
|
@ -71,4 +63,13 @@ public final class SuggestLocationsResult implements Serializable
|
|||
|
||||
return locations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final ToStringHelper helper = MoreObjects.toStringHelper(this).addValue(status);
|
||||
if (suggestedLocations != null)
|
||||
helper.add("size", suggestedLocations.size()).add("suggestedLocations", suggestedLocations);
|
||||
return helper.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,12 +18,13 @@
|
|||
package de.schildbach.pte.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.MoreObjects.ToStringHelper;
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
|
@ -196,23 +197,6 @@ public final class Trip implements Serializable
|
|||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final SimpleDateFormat FORMAT = new SimpleDateFormat("E HH:mm", Locale.US);
|
||||
|
||||
final StringBuilder str = new StringBuilder(getId());
|
||||
str.append(' ');
|
||||
final Date firstPublicLegDepartureTime = getFirstPublicLegDepartureTime();
|
||||
str.append(firstPublicLegDepartureTime != null ? FORMAT.format(firstPublicLegDepartureTime) : "null");
|
||||
str.append('-');
|
||||
final Date lastPublicLegArrivalTime = getLastPublicLegArrivalTime();
|
||||
str.append(lastPublicLegArrivalTime != null ? FORMAT.format(lastPublicLegArrivalTime) : "null");
|
||||
str.append(' ').append(numChanges).append("ch");
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
|
@ -230,6 +214,18 @@ public final class Trip implements Serializable
|
|||
return Objects.hashCode(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final ToStringHelper helper = MoreObjects.toStringHelper(this).addValue(getId());
|
||||
final Date firstPublicLegDepartureTime = getFirstPublicLegDepartureTime();
|
||||
final Date lastPublicLegArrivalTime = getLastPublicLegArrivalTime();
|
||||
helper.addValue(firstPublicLegDepartureTime != null ? String.format(Locale.US, "%ta %<tR", firstPublicLegDepartureTime) : "null" + '-'
|
||||
+ lastPublicLegArrivalTime != null ? String.format(Locale.US, "%ta %<tR", lastPublicLegArrivalTime) : "null");
|
||||
helper.add("numChanges", numChanges);
|
||||
return helper.toString();
|
||||
}
|
||||
|
||||
public abstract static class Leg implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 8498461220084523265L;
|
||||
|
@ -359,19 +355,8 @@ public final class Trip implements Serializable
|
|||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final StringBuilder builder = new StringBuilder(getClass().getSimpleName() + "[");
|
||||
builder.append("line=").append(line);
|
||||
if (destination != null)
|
||||
{
|
||||
builder.append(",");
|
||||
builder.append("destination=").append(destination);
|
||||
}
|
||||
builder.append(",");
|
||||
builder.append("departure=").append(departureStop);
|
||||
builder.append(",");
|
||||
builder.append("arrival=").append(arrivalStop);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
return MoreObjects.toStringHelper(this).add("line", line).add("destination", destination).add("departureStop", departureStop)
|
||||
.add("arrivalStop", arrivalStop).omitNullValues().toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -434,18 +419,8 @@ public final class Trip implements Serializable
|
|||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final StringBuilder builder = new StringBuilder(getClass().getSimpleName() + "[");
|
||||
builder.append("type=").append(type);
|
||||
builder.append(",");
|
||||
builder.append("departure=").append(departure);
|
||||
builder.append(",");
|
||||
builder.append("arrival=").append(arrival);
|
||||
builder.append(",");
|
||||
builder.append("min=").append(min);
|
||||
builder.append(",");
|
||||
builder.append("distance=").append(distance);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
return MoreObjects.toStringHelper(this).addValue(type).add("departure", departure).add("arrival", arrival).add("min", min)
|
||||
.add("distance", distance).omitNullValues().toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue