public abstract class LocationList extends Object implements Iterable<Location>
Locations.
A LocationList must contain at least 1 Location and does
not permit null elements. LocationList instances are
immutable and calls to remove() when iterating will throw an
UnsupportedOperationException. A variety of methods exist to simplify
the creation of new lists via modification (e.g. resample(double) ,
reverse(), and translate(LocationVector).
Consider using a LocationList.Builder (via builder()) if
a list is being compiled from numerous Locations that are not known
in advance.
Note: Although this class is not final, it cannot be subclassed outside its package as it has no public or protected constructors. Thus, instances of this type are guaranteed to be immutable.
| Modifier and Type | Class and Description |
|---|---|
static class |
LocationList.Builder
A reusable builder of
LocationLists. |
| Modifier and Type | Method and Description |
|---|---|
Bounds |
bounds()
Lazily compute the bounds of the
Locations in this list. |
static LocationList.Builder |
builder()
Return a new
LocationList builder. |
static LocationList |
create(Iterable<Location> locs)
Create a new
LocationList containing all Locations in
locs. |
static LocationList |
create(Location... locs)
Create a new
LocationList containing all Locations in
locs. |
double |
depth()
Lazily compute the average depth of the
Locations in this list. |
boolean |
equals(Object obj) |
Location |
first()
Return the first
Location in this list. |
static LocationList |
fromString(String s)
Create a new
LocationList from the supplied String. |
abstract Location |
get(int index)
Return the location at
index. |
int |
hashCode() |
Location |
last()
Return the last
Location in this list. |
double |
length()
Lazily compute the horizontal length of this
LocationList in km. |
List<LocationList> |
partition(double length)
Partition this
LocationList into sub-lists of desired
length. |
LocationList |
resample(double spacing)
Return a new
LocationList created by resampling this with
the desired maximum spacing. |
LocationList |
reverse()
Return a new
LocationList with Locations in reverse order. |
abstract int |
size()
Return the number of locations in this list.
|
String |
toString() |
LocationList |
translate(LocationVector vector)
Return a new
LocationList with each Location translated
according to the supplied vector. |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitforEach, iterator, spliteratorpublic static LocationList create(Location... locs)
LocationList containing all Locations in
locs.locs - to populate list withIllegalArgumentException - if locs is emptypublic static LocationList create(Iterable<Location> locs)
LocationList containing all Locations in
locs. This method avoids copying the supplied iterable if it is
safe to do so.locs - to populate list withIllegalArgumentException - if locs is emptypublic static LocationList fromString(String s)
LocationList from the supplied String. This
method assumes that s is formatted as one or more space-delimited
[lat,lon,depth] tuples (comma-delimited); see
Location.fromString(String).s - String to readLocationListLocation.fromString(String)public abstract int size()
public abstract Location get(int index)
index.index - of Location to returnIndexOutOfBoundsException - if the index is out of range (
index < 0 || index >= size())public Location first()
Location in this list.public Location last()
Location in this list.public double length()
LocationList in km.
Method uses the Locations.horzDistanceFast(Location, Location)
algorithm and ignores depth variation between locations. That is, it
computes length as though all locations in the list have a depth of 0.0 km.
Repeat calls to this method will recalculate the length each time.Locations in this
list, ignoring depth variations, or 0.0 if list only contains 1
locationpublic double depth()
Locations in this list.public Bounds bounds()
Locations in this list. Method
delegates to Locations.bounds(Iterable).public LocationList resample(double spacing)
LocationList created by resampling this with
the desired maximum spacing. The actual spacing of the returned list will
likely differ, as spacing is adjusted down to maintain uniform divisions.
The original vertices are also not preserved such that some corners might
be adversely clipped if spacing is large. Buyer beware.
If the length of this list is less than the desired spacing, this list is returned.
spacing - resample intervalpublic List<LocationList> partition(double length)
LocationList into sub-lists of desired
length. The actual length of the returned lists will likely differ,
as the lengths of the sub-lists are adjusted up or down to a value closest
to the target length that yields sub-lists of equal length.
If this list is shorter than the sub-list target length, the method will
return this.
length - target length of sub-listspublic LocationList reverse()
LocationList with Locations in reverse order.public LocationList translate(LocationVector vector)
LocationList with each Location translated
according to the supplied vector.vector - to translate list bypublic static LocationList.Builder builder()
LocationList builder.