public class Transport extends SubscribableCrudModel<Transport,TransportListener>
Interface to the Pathfinder server's transport API. A transport may be create
by a Cluster object with the Cluster.createTransport(double, double, TransportStatus, JsonObject)
method.
Be careful with the update methods, they do not update the object immediately.
They send the updates to the pathfinder server. If the server responds the transport's
fields will then be updated. To listen for updates add a TransportListener.
Cluster,
TransportListener,
TransportStatus| Modifier and Type | Field and Description |
|---|---|
private List<Commodity> |
commodities
List of commodities being carried by the transport.
|
private String |
createCluster
The cluster to be created under.
|
private double |
latitude
Latitude of the transport.
|
private static org.slf4j.Logger |
logger
Logs actions performed by the class.
|
private double |
longitude
Longitude of the transport.
|
private JsonObject |
metadata
Metadata of the transport.
|
private Route |
route
Route of the transport.
|
private TransportStatus |
status
Status of the transport.
|
| Modifier | Constructor and Description |
|---|---|
private |
Transport(String path,
double latitude,
double longitude,
TransportStatus status,
JsonObject metadata,
List<Commodity> commodities,
PathfinderServices services)
Constructs a transport model with the specified values.
|
private |
Transport(String path,
PathfinderServices services)
Constructs a transport model.
|
| Modifier and Type | Method and Description |
|---|---|
private static boolean |
checkTransportField(JsonObject transportJson,
String field)
Checks for a field in the JSON.
|
private static boolean |
checkTransportFields(JsonObject transportJson)
Checks if the JSON can be parsed to a transport.
|
protected JsonObject |
createValueJson()
Returns the value used in create request to the Pathfinder server
|
List<Commodity> |
getCommodities()
Returns an unmodifiable list of the commodities being carried by this transport.
|
protected static Transport |
getInstance(JsonObject transportJson,
PathfinderServices services)
Returns an instance of a transport model.
|
static Transport |
getInstance(String path,
PathfinderServices services)
Returns an instance of a transport model.
|
double |
getLatitude()
Returns the latitude of this transport.
|
double |
getLongitude()
Returns the longitude of this transport.
|
JsonObject |
getMetadata()
Returns the metadata of this transport.
|
private static String |
getPath(JsonObject transportJson)
Returns the path of the transport from JSON that represents a transport.
|
Route |
getRoute()
Returns the route of this transport.
|
TransportStatus |
getStatus()
Returns the status of this transport.
|
private static TransportStatus |
getStatus(String status)
Converts a string to a
TransportStatus if possible, null otherwise. |
protected Transport |
getThis()
Returns the current object represented by this.
|
protected void |
initTransport(double latitude,
double longitude,
TransportStatus status,
JsonObject metadata,
String cluster)
Initializes a transport object with the specified parameters.
|
protected void |
route(JsonObject json,
PathfinderServices services)
Updates the models routes.
|
private void |
setCommodities(JsonArray json)
Sets the commodities being carried by the transport.
|
private void |
setLatitude(double latitude)
Sets the latitude of the transport.
|
private void |
setLongitude(double longitude)
Sets the longitude of the transport.
|
private void |
setMetadata(JsonObject metadata)
Sets the metadata of the transport.
|
protected void |
setRoute(Route route)
Sets the route of the transport.
|
private void |
setStatus(TransportStatus status)
Sets the status of the transport.
|
JsonObject |
toJson()
Converts the
Model to JSON. |
String |
toString() |
void |
update(Double latitude,
Double longitude,
TransportStatus status,
JsonObject metadata)
Sends update requests to the Pathfinder server.
|
protected boolean |
updateFields(JsonObject json)
Updates the fields of the model.
|
void |
updateLocation(double latitude,
double longitude)
Updates the location of this transport to specified coordinates.
|
void |
updateMetadata(JsonObject metadata)
Updates the metadata of this transport to the specified metadata.
|
void |
updateStatus(TransportStatus status)
Updates the status of this transport to the specified status.
|
connect, create, delete, updategetMessageHeader, routeSubscribe, routeUnsubscribe, subscribe, unsubscribegetChildPath, getModelType, getName, getParentCluster, getParentPath, getPath, getPathName, getServices, isConnected, isPathUnknown, notifyUpdate, sendMessage, setConnected, setPathNameaddListener, getListeners, removeListenerprivate static final org.slf4j.Logger logger
private double latitude
private double longitude
private TransportStatus status
TransportStatusprivate JsonObject metadata
private Route route
private String createCluster
private Transport(String path, PathfinderServices services)
path - of the model.services - a pathfinder services object.IllegalArgumentException - occurs when a transport has already been registered with the same path.private Transport(String path, double latitude, double longitude, TransportStatus status, JsonObject metadata, List<Commodity> commodities, PathfinderServices services)
path - of the model.latitude - of the transport.longitude - of the transport.status - of the transport. If null it is set to TransportStatus.OFFLINEmetadata - of the transports. If null it is set to an empty JsonObject.commodities - being transported by this transport.services - a pathfinder services object.public static Transport getInstance(String path, PathfinderServices services)
path - of the model.services - a pathfinder services object.protected static Transport getInstance(JsonObject transportJson, PathfinderServices services)
transportJson - JSON that represents the transport.services - a pathfinder services object.IllegalArgumentException - if the JSON doesn't represent a transport.private static boolean checkTransportField(JsonObject transportJson, String field)
transportJson - JSON to be checked.field - to check for.private static boolean checkTransportFields(JsonObject transportJson)
transportJson - JSON to be checked.private static String getPath(JsonObject transportJson)
transportJson - JSON that represents a transportprivate static TransportStatus getStatus(String status)
TransportStatus if possible, null otherwise.status - string to convert.protected JsonObject createValueJson()
createValueJson in class SubscribableCrudModel<Transport,TransportListener>protected void initTransport(double latitude,
double longitude,
TransportStatus status,
JsonObject metadata,
String cluster)
SubscribableCrudModel.create() is called.latitude - of the transport.longitude - of the transport.status - of the transport. If null it is set to TransportStatus.OFFLINEmetadata - of the transports. If null it is set to an empty JsonObject.cluster - a string path of the cluster to create this transport under.public void updateLocation(double latitude,
double longitude)
latitude - The latitude to change the location to.longitude - The longitude to change the location to.public double getLatitude()
private void setLatitude(double latitude)
latitude - the of the transport.public double getLongitude()
private void setLongitude(double longitude)
longitude - the of the transport.public TransportStatus getStatus()
private void setStatus(TransportStatus status)
status - the of the transport.public void updateStatus(TransportStatus status)
status - The status to change to.public JsonObject getMetadata()
private void setMetadata(JsonObject metadata)
metadata - the of the transport.public void updateMetadata(JsonObject metadata)
metadata - The metadata to change to.public List<Commodity> getCommodities()
private void setCommodities(JsonArray json)
json - JsonArray of commoditiespublic Route getRoute()
protected void setRoute(Route route)
route - the of the transport.public void update(Double latitude, Double longitude, TransportStatus status, JsonObject metadata)
latitude - to update to.longitude - to update to.status - to update to.metadata - to update to.protected boolean updateFields(JsonObject json)
updateFields in class Model<Transport,TransportListener>json - of the model.protected void route(JsonObject json, PathfinderServices services)
route in class Model<Transport,TransportListener>json - of the model.services - pathfinder services object.public JsonObject toJson()
Model to JSON.toJson in class Model<Transport,TransportListener>Model as JSON.protected Transport getThis()
getThis in class Model<Transport,TransportListener>