Sleuth Kit Java Bindings (JNI)  4.8.0
Java bindings for using The Sleuth Kit
TskGeoWaypointsUtil.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;
29 
42 public final class TskGeoWaypointsUtil implements BlackboardAttributeUtil<GeoWaypointList> {
43 
44  @Override
45  public BlackboardAttribute toAttribute(String moduleName, GeoWaypointList value) {
46  if (value == null) {
47  throw new IllegalArgumentException("toAttribute was pass a null list");
48  }
49 
50  return new BlackboardAttribute(
52  moduleName,
53  toJSON(value));
54  }
55 
56  @Override
58  if (attribute == null) {
59  throw new IllegalArgumentException("fromAttribute was pass a null list");
60  }
61 
64  throw new IllegalArgumentException(String.format("Invalid attribute of type %s passed to fromAttribute method. Attribute of type TSK_GEO_WAYPOINTS is required", type.getDisplayName()));
65  }
66 
67  return fromJSON(attribute.getValueString());
68  }
69 
77  private static GeoWaypointList fromJSON(String json) {
78  if (json == null || json.isEmpty()) {
79  return null;
80  }
81 
82  return (new Gson()).fromJson(json, GeoWaypointList.class);
83  }
84 
92  private static String toJSON(GeoWaypointList waypoints) {
93  Gson gson = new Gson();
94  return gson.toJson(waypoints);
95  }
96 
102  public static final class GeoWaypointList implements Iterable<GeoWaypointList.GeoWaypoint> {
103 
104  private final List<GeoWaypoint> points;
105 
109  public GeoWaypointList() {
110  points = new ArrayList<>();
111  }
112 
118  public void addPoint(GeoWaypoint wayPoint) {
119  if (wayPoint == null) {
120  throw new IllegalArgumentException("addPoint was passed a null waypoint");
121  }
122 
123  points.add(wayPoint);
124  }
125 
131  public boolean isEmpty() {
132  return points.isEmpty();
133  }
134 
135  @Override
136  public Iterator<GeoWaypointList.GeoWaypoint> iterator() {
137  return points.iterator();
138  }
139 
145  public static class GeoWaypoint {
146 
147  @SerializedName("TSK_GEO_LATITUDE")
148  private final Double latitude;
149  @SerializedName("TSK_GEO_LONGITUDE")
150  private final Double longitude;
151  @SerializedName("TSK_GEO_ALTITUDE")
152  private final Double altitude;
153  @SerializedName("TSK_NAME")
154  private final String name;
155 
166  public GeoWaypoint(Double latitude, Double longitude, Double altitude, String name) {
167  if (latitude == null) {
168  throw new IllegalArgumentException("Constructor was passed null latitude");
169  }
170 
171  if (longitude == null) {
172  throw new IllegalArgumentException("Constructor was passed null longitude");
173  }
174 
175  this.latitude = latitude;
176  this.longitude = longitude;
177  this.altitude = altitude;
178  this.name = name;
179  }
180 
186  public Double getLatitude() {
187  return latitude;
188  }
189 
195  public Double getLongitude() {
196  return longitude;
197  }
198 
204  public Double getAltitude() {
205  return altitude;
206  }
207 
213  public String getName() {
214  return name;
215  }
216  }
217  }
218 }
BlackboardAttribute toAttribute(String moduleName, GeoWaypointList 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.