com.javadocmd.simplelatlng.window
Class LatLngWindow<T extends LatLngWindow<T>>

java.lang.Object
  extended by com.javadocmd.simplelatlng.window.LatLngWindow<T>
Direct Known Subclasses:
CircularWindow, RectangularWindow

public abstract class LatLngWindow<T extends LatLngWindow<T>>
extends Object

An interface specifying a region in the latitude/longitude space. Implementations will decide upon the shape of this region. LatLngWindow implementations are inclusive of their edges.

Author:
Tyler Coles

Constructor Summary
LatLngWindow()
           
 
Method Summary
abstract  boolean contains(LatLng point)
          Tests to see if the given point falls within this window.
<E> void
filter(Collection<E> collection, FilterHelper<E> helper)
          Goes through the given collection removing items whose LatLng point does not fall within this window.
<E> void
filterCopy(Collection<E> source, Collection<E> destination, FilterHelper<E> helper)
          Goes through the source collection copying items whose LatLng point falls within this window to the destination collection.
abstract  LatLng getCenter()
          Returns the center point of the window.
static double latitudeDeltaToLength(double deltaLat, LengthUnit unit)
          Converts a latitude degree arc to the length of that arc.
static double lengthToLatitudeDelta(double length, LengthUnit unit)
          Converts a length measurement into the latitude that that length spans.
static double lengthToLongitudeDelta(double length, LengthUnit unit, double latitude)
          Converts a length measurement into the longitude that that length spans at the given latitude.
static double longitudeDeltaToLength(double deltaLng, LengthUnit unit, double latitude)
          Converts a longitude degree arc at a specific latitude to the length of the arc.
abstract  boolean overlaps(T window)
          Test if this window overlaps the given window.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LatLngWindow

public LatLngWindow()
Method Detail

lengthToLatitudeDelta

public static double lengthToLatitudeDelta(double length,
                                           LengthUnit unit)
Converts a length measurement into the latitude that that length spans. (This method can also be used for arcs measured along any great circle.)

Parameters:
length - the length of the arc.
unit - the units for length.
Returns:
the degrees of equivalent latitude.

latitudeDeltaToLength

public static double latitudeDeltaToLength(double deltaLat,
                                           LengthUnit unit)
Converts a latitude degree arc to the length of that arc. This is the opposite operation to lengthToLatitudeDelta(double, LengthUnit)

Parameters:
deltaLat - the latitude arc degrees.
unit - the desired length units.
Returns:
the arc length.

lengthToLongitudeDelta

public static double lengthToLongitudeDelta(double length,
                                            LengthUnit unit,
                                            double latitude)
Converts a length measurement into the longitude that that length spans at the given latitude. This method is required because the length of an arc covering X-degrees longitude changes as latitude changes.

Parameters:
length - the length of the arc.
unit - the units for length.
latitude - the latitude at which this result applies.
Returns:
the degrees of equivalent longitude.

longitudeDeltaToLength

public static double longitudeDeltaToLength(double deltaLng,
                                            LengthUnit unit,
                                            double latitude)
Converts a longitude degree arc at a specific latitude to the length of the arc. This is the opposite operation to lengthToLongitudeDelta(double, LengthUnit, double)

Parameters:
deltaLng - the longitude arc degrees.
unit - the desired length units.
latitude - the latitude at which this arc lies.
Returns:
the arc length.

getCenter

public abstract LatLng getCenter()
Returns the center point of the window.

Returns:
the window's center point.

contains

public abstract boolean contains(LatLng point)
Tests to see if the given point falls within this window.

Parameters:
point - the point to test.
Returns:
true if the window contains the point, false otherwise or if we cannot determine because the point is ill-defined.

overlaps

public abstract boolean overlaps(T window)
Test if this window overlaps the given window.

Parameters:
window - the window to test against this one.
Returns:
true if the windows overlap.

filter

public <E> void filter(Collection<E> collection,
                       FilterHelper<E> helper)
Goes through the given collection removing items whose LatLng point does not fall within this window. The LatLng point used in this collection traversal is accessed via the FilterHelper instance passed in.

Type Parameters:
E - the type of elements in the collection.
Parameters:
collection - the collection of elements.
helper - the instance of FilterHelper that gives this method access to E's LatLng value that we will test against this window.

filterCopy

public <E> void filterCopy(Collection<E> source,
                           Collection<E> destination,
                           FilterHelper<E> helper)

Goes through the source collection copying items whose LatLng point falls within this window to the destination collection. The LatLng point used in this collection traversal is accessed via the FilterHelper instance passed in.

This should save you from copying an entire collection and then filtering it when you want to leave the first collection intact. This is a shallow copy, meaning changes made to objects within the copied collection will be reflected in the original, so beware.

Type Parameters:
E - the type of elements in the collection.
Parameters:
source - the source collection of elements.
destination - the destination collection; after this method runs, destination contains all items that fit within this window.
helper - the instance of FilterHelper that gives this method access to E's LatLng value that we will test against this window.


Copyright © 2010-2011. All Rights Reserved.