Skip to content

Package: KapuaPosition

KapuaPosition

nameinstructionbranchcomplexitylinemethod
toDisplayString()
M: 68 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.message;
14:
15: import org.eclipse.kapua.commons.util.Payloads;
16: import org.eclipse.kapua.message.xml.MessageXmlRegistry;
17: import org.eclipse.kapua.model.xml.DateXmlAdapter;
18:
19: import javax.xml.bind.annotation.XmlAccessType;
20: import javax.xml.bind.annotation.XmlAccessorType;
21: import javax.xml.bind.annotation.XmlElement;
22: import javax.xml.bind.annotation.XmlRootElement;
23: import javax.xml.bind.annotation.XmlType;
24: import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
25: import java.io.Serializable;
26: import java.util.Date;
27: import java.util.HashMap;
28: import java.util.Map;
29:
30: /**
31: * {@link KapuaPosition} definition.
32: * <p>
33: * {@link KapuaPosition} is a data structure to capture a geo location.
34: * <p>
35: * It can be associated to an {@link org.eclipse.kapua.message.KapuaPayload} to geotag an {@link org.eclipse.kapua.message.KapuaMessage} before sending to Kapua.
36: *
37: * @since 1.0.0
38: */
39: @XmlRootElement(name = "position")
40: @XmlAccessorType(XmlAccessType.PROPERTY)
41: @XmlType(factoryClass = MessageXmlRegistry.class, factoryMethod = "newPosition")
42: public interface KapuaPosition extends Position, Serializable {
43:
44: /**
45: * Gets the GPS position longitude
46: *
47: * @return The GPS position longitude
48: * @since 1.0.0
49: */
50: @XmlElement(name = "longitude")
51: Double getLongitude();
52:
53: /**
54: * Sets the GPS position longitude
55: *
56: * @param longitude The GPS position longitude
57: * @since 1.0.0
58: */
59: void setLongitude(Double longitude);
60:
61: /**
62: * Gets the GPS position latitude
63: *
64: * @return The GPS position latitude
65: * @since 1.0.0
66: */
67: @XmlElement(name = "latitude")
68: Double getLatitude();
69:
70: /**
71: * Sets the GPS position latitude
72: *
73: * @param latitude The GPS position latitude
74: * @since 1.0.0
75: */
76: void setLatitude(Double latitude);
77:
78: /**
79: * Gets the GPS position altitude
80: *
81: * @return The GPS position altitude
82: * @since 1.0.0
83: */
84: @XmlElement(name = "altitude")
85: Double getAltitude();
86:
87: /**
88: * Sets the GPS position altitude
89: *
90: * @param altitude The GPS position altitude
91: * @since 1.0.0
92: */
93: void setAltitude(Double altitude);
94:
95: /**
96: * Gets the GPS precision
97: *
98: * @return The GPS precision
99: * @since 1.0.0
100: */
101: @XmlElement(name = "precision")
102: Double getPrecision();
103:
104: /**
105: * Sets the GPS precision
106: *
107: * @param precision The GPS precision
108: * @since 1.0.0
109: */
110: void setPrecision(Double precision);
111:
112: /**
113: * Gets the GPS heading
114: *
115: * @return The GPS heading
116: * @since 1.0.0
117: */
118: @XmlElement(name = "heading")
119: Double getHeading();
120:
121: /**
122: * Sets the GPS heading
123: *
124: * @param heading The GPS heading
125: * @since 1.0.0
126: */
127: void setHeading(Double heading);
128:
129: /**
130: * Gets the GPS speed
131: *
132: * @return The GPS speed.
133: * @since 1.0.0
134: */
135: @XmlElement(name = "speed")
136: Double getSpeed();
137:
138: /**
139: * Sets the GPS speed
140: *
141: * @param speed The GPS speed
142: * @since 1.0.0
143: */
144: void setSpeed(Double speed);
145:
146: /**
147: * Gets the timestamp
148: *
149: * @return The timestamp
150: * @since 1.0.0
151: */
152: @XmlElement(name = "timestamp")
153: @XmlJavaTypeAdapter(DateXmlAdapter.class)
154: Date getTimestamp();
155:
156: /**
157: * Sets the timestamp
158: *
159: * @param timestamp The timestamp
160: * @since 1.0.0
161: */
162: void setTimestamp(Date timestamp);
163:
164: /**
165: * Gets the satellites count
166: *
167: * @return The satellites count
168: * @since 1.0.0
169: */
170: @XmlElement(name = "satellites")
171: Integer getSatellites();
172:
173: /**
174: * Sets the satellites count
175: *
176: * @param satellites The satellites count.
177: * @since 1.0.0
178: */
179: void setSatellites(Integer satellites);
180:
181: /**
182: * Gets the GPS status
183: *
184: * @return The GPS status
185: * @since 1.0.0
186: */
187: @XmlElement(name = "status")
188: Integer getStatus();
189:
190: /**
191: * Sets the GPS status
192: *
193: * @param status The GPS status
194: * @since 1.0.0
195: */
196: void setStatus(Integer status);
197:
198: /**
199: * Converts the {@link KapuaPosition} attributes to a displayable {@link String}
200: *
201: * @return The displayable {@link String}
202: * @since 1.0.0
203: */
204: default String toDisplayString() {
205:
206: Map<String, Object> properties = new HashMap<>();
207:
208: properties.put("latitude", getLatitude());
209: properties.put("longitude", getLongitude());
210: properties.put("altitude", getAltitude());
211: properties.put("precision", getPrecision());
212: properties.put("heading", getHeading());
213: properties.put("speed", getSpeed());
214: properties.put("timestamp", getTimestamp());
215: properties.put("satellites", getSatellites());
216: properties.put("status", getStatus());
217:
218: String displayString = Payloads.toDisplayString(properties);
219:
220:• return displayString.isEmpty() ? null : displayString;
221: }
222: }