Sleuth Kit Java Bindings (JNI)  4.8.0
Java bindings for using The Sleuth Kit
TskGeoTrackpointsUtil.java
Go to the documentation of this file.
1 /*
2  * Sleuth Kit Data Model
3  *
4  * Copyright 2020 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.datamodel.blackboardutils.attributes;
20 
21 import com.google.gson.Gson;
22 import com.google.gson.annotations.SerializedName;
23 import java.util.ArrayList;
24 import java.util.Iterator;
25 import java.util.List;
26 import java.util.stream.Collectors;
30 
41 public final class TskGeoTrackpointsUtil implements BlackboardAttributeUtil<GeoTrackPointList> {
42 
43  @Override
44  public BlackboardAttribute toAttribute(String moduleName, GeoTrackPointList value) {
45  if (value == null) {
46  throw new IllegalArgumentException("toAttribute was passed a null list");
47  }
48 
49  return new BlackboardAttribute(
51  moduleName,
52  toJSON(value));
53  }
54 
55  @Override
57  if (attribute == null) {
58  throw new IllegalArgumentException("fromAttribute was passed a null attribute");
59  }
60 
63  throw new IllegalArgumentException(String.format("Invalid attribute of type %s passed to fromAttribute method. Attribute of type TSK_GEO_TRACKPOINTS is required", type.getDisplayName()));
64  }
65 
66  return fromJSON(attribute.getValueString());
67  }
68 
76  private static GeoTrackPointList fromJSON(String json) {
77  if (json == null || json.isEmpty()) {
78  throw new IllegalArgumentException("fromJSON was passed a empty or null JSON string");
79  }
80 
81  return (new Gson()).fromJson(json, GeoTrackPointList.class);
82  }
83 
91  private static String toJSON(GeoTrackPointList trackPoints) {
92  if (trackPoints == null) {
93  throw new IllegalArgumentException("toJSON was passed a null track points list");
94  }
95 
96  Gson gson = new Gson();
97  return gson.toJson(trackPoints);
98  }
99 
105  public static class GeoTrackPointList implements Iterable<GeoTrackPointList.GeoTrackPoint> {
106 
107  private final List<GeoTrackPoint> pointList;
108 
112  public GeoTrackPointList() {
113  pointList = new ArrayList<>();
114  }
115 
121  public void addPoint(GeoTrackPoint trackPoint) {
122  if (trackPoint == null) {
123  throw new IllegalArgumentException("addPoint was passed a null track point");
124  }
125 
126  pointList.add(trackPoint);
127  }
128 
129  @Override
130  public Iterator<GeoTrackPoint> iterator() {
131  return pointList.iterator();
132  }
133 
139  public boolean isEmpty() {
140  return pointList.isEmpty();
141  }
142 
150  public Long getStartTime() {
151  List<GeoTrackPoint> orderedPoints = getTimeOrderedPoints();
152  if (orderedPoints != null) {
153  for (GeoTrackPoint point : orderedPoints) {
154  if (point.getTimeStamp() != null) {
155  return point.getTimeStamp();
156  }
157  }
158  }
159  return null;
160  }
161 
169  public Long getEndTime() {
170  List<GeoTrackPoint> orderedPoints = getTimeOrderedPoints();
171  if (orderedPoints != null) {
172  for (int index = orderedPoints.size() - 1; index >= 0; index--) {
173  GeoTrackPoint point = orderedPoints.get(index);
174  if (point.getTimeStamp() != null) {
175  return point.getTimeStamp();
176  }
177  }
178  }
179  return null;
180  }
181 
188  private List<GeoTrackPoint> getTimeOrderedPoints() {
189  return pointList.stream().sorted().collect(Collectors.toCollection(ArrayList::new));
190  }
191 
197  public final static class GeoTrackPoint extends TskGeoWaypointsUtil.GeoWaypointList.GeoWaypoint implements Comparable<GeoTrackPoint> {
198 
199  @SerializedName("TSK_GEO_VELOCITY")
200  private final Double velocity;
201  @SerializedName("TSK_DISTANCE_FROM_HOMEPOINT")
202  private final Double distanceFromHomePoint;
203  @SerializedName("TSK_DISTANCE_TRAVELED")
204  private final Double distanceTraveled;
205  @SerializedName("TSK_DATETIME")
206  private final Long timestamp;
207 
232  public GeoTrackPoint(Double latitude,
233  Double longitude,
234  Double altitude,
235  String name,
236  Double velocity,
237  Double distanceFromHomePoint,
238  Double distanceTraveled,
239  Long timestamp) {
240  super(latitude, longitude, altitude, name);
241  this.velocity = velocity;
242  this.distanceFromHomePoint = distanceFromHomePoint;
243  this.distanceTraveled = distanceTraveled;
244  this.timestamp = timestamp;
245  }
246 
253  public Double getVelocity() {
254  return velocity;
255  }
256 
263  public Double getDistanceFromHomePoint() {
264  return distanceFromHomePoint;
265  }
266 
273  public Double getDistanceTraveled() {
274  return distanceTraveled;
275  }
276 
283  public Long getTimeStamp() {
284  return timestamp;
285  }
286 
287  @Override
288  public int compareTo(GeoTrackPoint otherTP) {
289  Long otherTimeStamp = otherTP.getTimeStamp();
290 
291  if (timestamp == null && otherTimeStamp != null) {
292  return -1;
293  } else if (timestamp != null && otherTimeStamp == null) {
294  return 1;
295  } else {
296  return timestamp.compareTo(otherTP.getTimeStamp());
297  }
298  }
299  }
300  }
301 }
GeoTrackPoint(Double latitude, Double longitude, Double altitude, String name, Double velocity, Double distanceFromHomePoint, Double distanceTraveled, Long timestamp)
BlackboardAttribute toAttribute(String moduleName, GeoTrackPointList value)

Copyright © 2011-2020 Brian Carrier. (carrier -at- sleuthkit -dot- org)
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.