Class NonHierarchicalDistanceBasedAlgorithm
-
- All Implemented Interfaces:
-
com.google.maps.android.clustering.algo.Algorithm
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:
Iterate over items in the order they were added (candidate clusters).
Create a cluster with the center of the item.
Add all items that are within a certain distance to the cluster.
Move any items out of an existing cluster if they are closer to another cluster.
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).
-
-
Field Summary
Fields Modifier and Type Field Description private IntegermaxDistanceBetweenClusteredItemsprivate final Collection<T>items
-
Constructor Summary
Constructors Constructor Description NonHierarchicalDistanceBasedAlgorithm()
-
Method Summary
Modifier and Type Method Description IntegergetMaxDistanceBetweenClusteredItems()UnitsetMaxDistanceBetweenClusteredItems(Integer maxDistanceBetweenClusteredItems)Collection<T>getItems()BooleanaddItem(T item)Adds an item to the algorithm BooleanaddItems(Collection<T> items)Adds a collection of items to the algorithm UnitclearItems()BooleanremoveItem(T item)Removes an item from the algorithm BooleanremoveItems(Collection<T> items)Removes a collection of items from the algorithm BooleanupdateItem(T item)Updates the provided item in the algorithm Set<Cluster<T>>getClusters(Float zoom)-
-
Method Detail
-
getMaxDistanceBetweenClusteredItems
Integer getMaxDistanceBetweenClusteredItems()
-
setMaxDistanceBetweenClusteredItems
Unit setMaxDistanceBetweenClusteredItems(Integer maxDistanceBetweenClusteredItems)
-
getItems
Collection<T> getItems()
-
addItem
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
Boolean addItems(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
Unit clearItems()
-
removeItem
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
Boolean removeItems(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
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.
-
getClusters
Set<Cluster<T>> getClusters(Float zoom)
-
-
-
-