Trip fetching and model

This commit is contained in:
2016-12-24 18:19:11 +01:00
parent f12e359e2a
commit 6ec93ba0f7
3 changed files with 233 additions and 26 deletions

View File

@@ -1,48 +1,58 @@
package de.stklcode.pubtrans.ura.model;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.databind.annotation.JsonAppend;
import java.io.IOException;
import java.util.List;
import java.util.StringJoiner;
/**
* Created by stefan on 24.12.16.
* Entity for a single stop.
*
* @author Stefan Kalscheuer <stefan@stklcode.de>
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class Stop {
private final String id;
private final String name;
private final String indicator;
private final Integer state;
private final Double latitude;
private final Double longitude;
public Stop(String id, String name, Double latitude, Double longitude) {
public Stop(String id, String name, String indicator, Integer state, Double latitude, Double longitude) {
this.id = id;
this.name = name;
this.indicator = indicator;
this.state = state;
this.latitude = latitude;
this.longitude = longitude;
}
public Stop(List raw) {
public Stop(List raw) throws IOException {
if (raw == null || raw.size() < 7)
throw new IOException("Invalid number of fields");
if (raw.get(1) instanceof String)
name = (String)raw.get(1);
else
throw new UnsupportedOperationException("Field 1 not of expected Type String");
throw new IOException("Field 1 not of expected type String, found " + raw.get(1).getClass().getSimpleName());
if (raw.get(2) instanceof String)
id = (String)raw.get(2);
else
throw new UnsupportedOperationException("Field 2 not of expected Type String");
if (raw.get(3) instanceof Double)
latitude = (Double)raw.get(3);
throw new IOException("Field 2 not of expected type String, found " + raw.get(2).getClass().getSimpleName());
if (raw.get(3) instanceof String)
indicator = (String)raw.get(3);
else
throw new UnsupportedOperationException("Field 3 not of expected Type Double");
throw new IOException("Field 3 not of expected type String, found " + raw.get(3).getClass().getSimpleName());
if (raw.get(4) instanceof String)
state = (Integer)raw.get(4);
else
throw new IOException("Field 4 not of expected type Integer, found " + raw.get(4).getClass().getSimpleName());
if (raw.get(5) instanceof Double)
latitude = (Double)raw.get(5);
else
throw new IOException("Field 5 not of expected type Double, found " + raw.get(5).getClass().getSimpleName());
if (raw.get(4) instanceof Double)
longitude = (Double)raw.get(4);
longitude = (Double)raw.get(6);
else
throw new UnsupportedOperationException("Field 4 not of expected Type Double");
throw new IOException("Field 6 not of expected type Double, found " + raw.get(6).getClass().getSimpleName());
}
@@ -54,6 +64,14 @@ public class Stop {
return name;
}
public String getIndicator() {
return indicator;
}
public Integer getState() {
return state;
}
public Double getLatitude() {
return latitude;
}

View File

@@ -0,0 +1,85 @@
package de.stklcode.pubtrans.ura.model;
import java.io.IOException;
import java.util.List;
/**
* Entity for a single trip.
*
* @author Stefan Kalscheuer <stefan@stklcode.de>
*/
public class Trip {
private final Stop stop;
private final String id;
private final Integer visitID;
private final String lineID;
private final String lineName;
private final Integer directionID;
private final String destinationName;
private final String destinationText;
private final Long estimatedTime;
private final String vehicleID;
public Trip(String stopID, String stopName, String stopIndicator, Integer stopState, Double stopLatitude, Double stopLongitude,
Integer visitID, String lineID, String lineName, Integer directionID, String destinationName, String destinationText, String vehicleID, String tripID, Long estimatedTime) {
this(new Stop(stopID, stopName, stopIndicator, stopState, stopLatitude, stopLongitude),
visitID, lineID, lineName, directionID, destinationName, destinationText, vehicleID, tripID, estimatedTime);
}
public Trip(Stop stop, Integer visitID, String lineID, String lineName, Integer directionID, String destinationName, String destinationText, String vehicleID, String tripID, Long estimatedTime) {
this.stop = stop;
this.visitID = visitID;
this.lineID = lineID;
this.lineName = lineName;
this.directionID = directionID;
this.destinationName = destinationName;
this.destinationText = destinationText;
this.vehicleID = vehicleID;
this.id = tripID;
this.estimatedTime = estimatedTime;
}
public Trip(List raw) throws IOException {
if (raw == null || raw.size() < 16)
throw new IOException("Invalid number of fields");
stop = new Stop(raw);
if (raw.get(7) instanceof Integer)
visitID = (Integer) raw.get(7);
else
throw new IOException("Field 7 not of expected type Integer, found " + raw.get(7).getClass().getSimpleName());
if (raw.get(8) instanceof String)
lineID = (String)raw.get(8);
else
throw new IOException("Field 8 not of expected type String, found " + raw.get(8).getClass().getSimpleName());
if (raw.get(9) instanceof String)
lineName = (String)raw.get(9);
else
throw new IOException("Field 9 not of expected type String, found " + raw.get(9).getClass().getSimpleName());
if (raw.get(10) instanceof Integer)
directionID = (Integer)raw.get(10);
else
throw new IOException("Field 10 not of expected type Integer, found " + raw.get(10).getClass().getSimpleName());
if (raw.get(11) instanceof String)
destinationName = (String)raw.get(11);
else
throw new IOException("Field 11 not of expected type String, found " + raw.get(11).getClass().getSimpleName());
if (raw.get(12) instanceof String)
destinationText = (String)raw.get(12);
else
throw new IOException("Field 12 not of expected type String, found " + raw.get(12).getClass().getSimpleName());
if (raw.get(13) instanceof String)
vehicleID = (String)raw.get(13);
else
throw new IOException("Field 13 not of expected type String, found " + raw.get(13).getClass().getSimpleName());
if (raw.get(14) instanceof String)
id = (String)raw.get(14);
else
throw new IOException("Field 14 not of expected type String, found " + raw.get(14).getClass().getSimpleName());
if (raw.get(15) instanceof Long)
estimatedTime = (Long)raw.get(15);
else
throw new IOException("Field 15 not of expected type Long, found " + raw.get(15).getClass().getSimpleName());
}
}