Class NonHierarchicalDistanceBasedAlgorithm<T extends ClusterItem>
- java.lang.Object
-
- com.google.maps.android.clustering.algo.AbstractAlgorithm<T>
-
- com.google.maps.android.clustering.algo.NonHierarchicalDistanceBasedAlgorithm<T>
-
- All Implemented Interfaces:
Algorithm<T>
- Direct Known Subclasses:
NonHierarchicalViewBasedAlgorithm
public class NonHierarchicalDistanceBasedAlgorithm<T extends ClusterItem> extends AbstractAlgorithm<T>
A simple clustering algorithm with O(nlog n) performance. Resulting clusters are not hierarchical.High level algorithm:
1. Iterate over items in the order they were added (candidate clusters).
2. Create a cluster with the center of the item.
3. Add all items that are within a certain distance to the cluster.
4. Move any items out of an existing cluster if they are closer to another cluster.
5. Remove those items from the list of candidate clusters.Clusters have the center of the first element (not the centroid of the items within it).
-
-
Constructor Summary
Constructors Constructor Description NonHierarchicalDistanceBasedAlgorithm()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addItem(T item)
Adds an item to the algorithmboolean
addItems(java.util.Collection<T> items)
Adds a collection of items to the algorithmvoid
clearItems()
java.util.Set<? extends Cluster<T>>
getClusters(float zoom)
java.util.Collection<T>
getItems()
int
getMaxDistanceBetweenClusteredItems()
boolean
removeItem(T item)
Removes an item from the algorithmboolean
removeItems(java.util.Collection<T> items)
Removes a collection of items from the algorithmvoid
setMaxDistanceBetweenClusteredItems(int maxDistance)
boolean
updateItem(T item)
Updates the provided item in the algorithm-
Methods inherited from class com.google.maps.android.clustering.algo.AbstractAlgorithm
lock, unlock
-
-
-
-
Method Detail
-
addItem
public boolean addItem(T item)
Adds an item to the algorithm- Parameters:
item
- the item to be added- Returns:
- true if the algorithm contents changed as a result of the call
-
addItems
public boolean addItems(java.util.Collection<T> items)
Adds a collection of items to the algorithm- Parameters:
items
- the items to be added- Returns:
- true if the algorithm contents changed as a result of the call
-
clearItems
public void clearItems()
-
removeItem
public boolean removeItem(T item)
Removes an item from the algorithm- Parameters:
item
- the item to be removed- Returns:
- true if this algorithm contained the specified element (or equivalently, if this algorithm changed as a result of the call).
-
removeItems
public boolean removeItems(java.util.Collection<T> items)
Removes a collection of items from the algorithm- Parameters:
items
- the items to be removed- Returns:
- true if this algorithm contents changed as a result of the call
-
updateItem
public boolean updateItem(T item)
Updates the provided item in the algorithm- Parameters:
item
- the item to be updated- Returns:
- true if the item existed in the algorithm and was updated, or false if the item did not exist in the algorithm and the algorithm contents remain unchanged.
-
getItems
public java.util.Collection<T> getItems()
-
setMaxDistanceBetweenClusteredItems
public void setMaxDistanceBetweenClusteredItems(int maxDistance)
-
getMaxDistanceBetweenClusteredItems
public int getMaxDistanceBetweenClusteredItems()
-
-