public class Commodity extends SubscribableCrudModel<CommodityListener>
Cluster object with the Cluster.createCommodity(double, double, double, double, CommodityStatus, 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 commodity's
fields will then be updated. To listen for updates add a CommodityListener.
Cluster,
CommodityListener,
CommodityStatus,
Transport| Modifier and Type | Field and Description |
|---|---|
private double |
endLatitude
The drop off latitude of the commodity.
|
private double |
endLongitude
The drop off longitude of the commodity.
|
private static org.slf4j.Logger |
logger |
private JsonObject |
metadata
The metadata of this commodity.
|
private Route |
route
The route of this commodity.
|
private double |
startLatitude
The pickup latitude of the commodity.
|
private double |
startLongitude
The pickup longitude of the commodity.
|
private CommodityStatus |
status
The current status of this commodity.
|
private Long |
transportId
The transport caring the commodity.
|
| Modifier | Constructor and Description |
|---|---|
protected |
Commodity(String path,
double startLatitude,
double startLongitude,
double endLatitude,
double endLongitude,
CommodityStatus status,
JsonObject metadata,
Long transportId,
PathfinderServices services)
Constructs a commodity object with the specified parameters.
|
protected |
Commodity(String path,
PathfinderServices services)
Constructs a commodity object with the path specified.
|
| Modifier and Type | Method and Description |
|---|---|
private static boolean |
checkCommodityField(JsonObject commodityJson,
String field)
Checks a JSON object for a specific field.
|
private static boolean |
checkCommodityFields(JsonObject commodityJson)
Checks if a JSON object can be parsed to a commodity.
|
protected JsonObject |
createValueJson()
Returns the value used in create request to the Pathfinder server
|
double |
getEndLatitude()
Returns the current end latitude of the commodity.
|
double |
getEndLongitude()
Returns the current end longitude of the commodity.
|
protected static Commodity |
getInstance(JsonObject commodityJson,
PathfinderServices services)
Returns a commodity that has been registered with the
ModelRegistry or a new
commodity if one hasn't been created with that path. |
protected static Commodity |
getInstance(String path,
PathfinderServices services)
Returns a commodity that has been registered with the
ModelRegistry or a new
commodity if one hasn't been created with that path. |
JsonObject |
getMetadata()
Returns the metadata of the commodity in the form of a Json Object.
|
private static String |
getPath(JsonObject commodityJson)
Returns the path for a JSON object that represents a commodity.
|
Route |
getRoute()
Returns the route for this commodity.
|
double |
getStartLatitude()
Returns the current start latitude of the commodity.
|
double |
getStartLongitude()
Returns the current start longitude of the commodity.
|
CommodityStatus |
getStatus()
Returns the current status of the commodity.
|
private static CommodityStatus |
getStatus(String status)
Returns the enum version of a status from a string.
|
Transport |
getTransport()
Returns the transport carrying the commodity.
|
private Long |
getTransportId()
Returns the transport id carrying the commodity.
|
protected void |
route(JsonObject json,
PathfinderServices services)
Updates the models routes.
|
private void |
setEndLatitude(double latitude)
Sets the end latitude field to a new latitude
|
private void |
setEndLongitude(double longitude)
Sets the end longitude field to a new longitude
|
private void |
setMetadata(JsonObject metadata)
Sets the metadata field to a new JSON object.
|
private void |
setRoute(Route route)
Sets the route field to a new route
|
private void |
setStartLatitude(double latitude)
Sets the start latitude field to a new latitude
|
private void |
setStartLongitude(double longitude)
Sets the start longitude field to a new longitude
|
private void |
setStatus(CommodityStatus status)
Sets the status field to a new status
|
private void |
setStatus(String status)
Sets the status field to a new status
|
private void |
setTransportId(Long transportId)
Sets the transport id field to a new transport.
|
String |
toString() |
void |
update(Double startLatitude,
Double startLongitude,
Double endLatitude,
Double endLongitude,
CommodityStatus status,
JsonObject metadata,
Long transportId)
Sends update requests to the Pathfinder server.
|
void |
updateDroppedOff()
Updates the commodity to have a status of dropped off.
|
void |
updateEndLocation(double endLatitude,
double endLongitude)
Updates the end location of this commodity to specified coordinates.
|
protected boolean |
updateFields(JsonObject json)
Updates the fields of the model.
|
void |
updateMetadata(JsonObject metadata)
Updates the metadata of this commodity to the specified Json Object.
|
void |
updatePickedUp(Transport transport)
Updates the transport of this commodity to the specified transport and sets the status to picked up.
|
void |
updateStartLocation(double startLatitude,
double startLongitude)
Updates the start location of this commodity to specified coordinates.
|
void |
updateStatus(CommodityStatus status)
Updates the status of this commodity to the specified status.
|
connect, create, delete, updategetMessageHeader, routeSubscribe, routeUnsubscribe, subscribe, unsubscribegetChildPath, getModelType, getName, getParentCluster, getParentPath, getPath, getPathName, getServices, isConnected, notifyUpdate, setConnectedaddListener, getListeners, removeListenerprivate static final org.slf4j.Logger logger
private double startLatitude
private double startLongitude
private double endLatitude
private double endLongitude
private CommodityStatus status
private JsonObject metadata
private Long transportId
private Route route
protected Commodity(String path, PathfinderServices services)
path - the path to commodityservices - a pathfinder services objectsIllegalArgumentException - occurs if the path has already been used to create a commodity.protected Commodity(String path, double startLatitude, double startLongitude, double endLatitude, double endLongitude, CommodityStatus status, JsonObject metadata, Long transportId, PathfinderServices services)
path - the path on the Pathfinder server.startLatitude - the pickup latitude of the commodity.startLongitude - the pickup longitude of the commodity.endLatitude - the drop off latitude of the commodity.endLongitude - the drop off longitude of the commodity.status - the current status of the commodity.metadata - a JSON object that holds metadata for the commodity.transportId - the id of the transport that picked up the commodity, null if not in a transport.services - a pathfinder services object.protected static Commodity getInstance(String path, PathfinderServices services)
ModelRegistry or a new
commodity if one hasn't been created with that path.path - the path to model on the pathfinder serverservices - a pathfinder services object.protected static Commodity getInstance(JsonObject commodityJson, PathfinderServices services)
ModelRegistry or a new
commodity if one hasn't been created with that path. The commodity will be updated to
reflect the values in JSON object provided.commodityJson - a JSON object that represents a commodity.services - a pathfinder services object.IllegalArgumentException - occurs when the commodity JSON cannot parse to a commodityprivate static boolean checkCommodityField(JsonObject commodityJson, String field)
commodityJson - a JSON object that represents a commodity.field - the field to check for.private static boolean checkCommodityFields(JsonObject commodityJson)
commodityJson - JSON object to check.private static String getPath(JsonObject commodityJson)
commodityJson - a JSON object that represents a commodity.public void updateStartLocation(double startLatitude,
double startLongitude)
startLatitude - The latitude to change the start location to.startLongitude - The longitude to change the start location to.public double getStartLatitude()
private void setStartLatitude(double latitude)
latitude - the latitude to change to.public double getStartLongitude()
private void setStartLongitude(double longitude)
longitude - the longitude to change to.public void updateEndLocation(double endLatitude,
double endLongitude)
endLatitude - The latitude to change the end location to.endLongitude - The longitude to change the end location to.public double getEndLatitude()
private void setEndLatitude(double latitude)
latitude - the latitude to change to.public double getEndLongitude()
private void setEndLongitude(double longitude)
longitude - the longitude to change to.public CommodityStatus getStatus()
CommodityStatus
for the status's available to commodities.private static CommodityStatus getStatus(String status)
status - the status as a string.private void setStatus(CommodityStatus status)
status - the status to change to.IllegalArgumentException - when an illegal status is providedprivate void setStatus(String status)
status - the status to change to.IllegalArgumentException - when an illegal status is providedpublic void updateStatus(CommodityStatus status)
status - The status to change to.public JsonObject getMetadata()
private void setMetadata(JsonObject metadata)
metadata - the JSON object to change to.public void updateMetadata(JsonObject metadata)
metadata - The metadata to change to.public Route getRoute()
private void setRoute(Route route)
route - the route to change to.public Transport getTransport()
private Long getTransportId()
public void updatePickedUp(Transport transport)
transport - The transport that picked up this commodity.public void updateDroppedOff()
private void setTransportId(Long transportId)
transportId - of the transport carrying the commodity, null if not being carried.public void update(Double startLatitude, Double startLongitude, Double endLatitude, Double endLongitude, CommodityStatus status, JsonObject metadata, Long transportId)
startLatitude - The start latitude to change to.startLongitude - The start longitude to change to.endLatitude - The end latitude to change to.endLongitude - The end longitude to change to.status - The status to change to.metadata - The metadata to change to.transportId - The id of the transport that picked up the commodity.protected JsonObject createValueJson()
createValueJson in class Model<CommodityListener>protected boolean updateFields(JsonObject json)
updateFields in class Model<CommodityListener>json - of the model.protected void route(JsonObject json, PathfinderServices services)
route in class Model<CommodityListener>json - of the model.services - pathfinder services object.