/**
* *****************************************************************************
* Copyright 2013 Johannes Mitlmeier
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
* ****************************************************************************
*/
package de.fub.agg2graph.structs;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.logging.Logger;
/**
* A gps segment as found in gpx files. It is a list of {@link GPSPoint}s.
*
* @author Johannes Mitlmeier
*
*/
public class GPSSegment extends LinkedList<GPSPoint> {
private static final long serialVersionUID = -124779073052348850L;
private static final Logger LOG = Logger.getLogger(GPSSegment.class.getName());
public GPSSegment() {
}
public GPSSegment(List<? extends ILocation> list) {
this();
GPSPoint point;
for (ILocation loc : list) {
point = new GPSPoint(loc);
if (loc.getID() == null) {
point.setID(UUID.randomUUID().toString());
LOG.fine(point.toString());
} else {
point.setID(loc.getID());
}
add(point);
}
}
public void addIDs(String prefix) {
addIDs(prefix, 1, true);
}
public void addIDs(String prefix, int start) {
addIDs(prefix, start, false);
}
public void addIDs(String prefix, int start, boolean keepIDs) {
for (int i = 0; i < size(); i++) {
if (keepIDs && get(i).getID() != null) {
get(i).setID(String.format("%s-%s", prefix, get(i).getID()));
} else {
get(i).setID(String.format("%s-%d", prefix, start + i));
}
}
}
}