Initial version -- added millennium read funcionality
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package com.google.maps.android.clustering.algo;
|
||||
|
||||
import com.google.maps.android.clustering.ClusterItem;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
/* JADX INFO: loaded from: classes2.dex */
|
||||
public abstract class AbstractAlgorithm<T extends ClusterItem> implements Algorithm<T> {
|
||||
private final ReadWriteLock mLock = new ReentrantReadWriteLock();
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public void lock() {
|
||||
this.mLock.writeLock().lock();
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public void unlock() {
|
||||
this.mLock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.google.maps.android.clustering.algo;
|
||||
|
||||
import com.google.maps.android.clustering.Cluster;
|
||||
import com.google.maps.android.clustering.ClusterItem;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
/* JADX INFO: loaded from: classes2.dex */
|
||||
public interface Algorithm<T extends ClusterItem> {
|
||||
boolean addItem(T t);
|
||||
|
||||
boolean addItems(Collection<T> collection);
|
||||
|
||||
void clearItems();
|
||||
|
||||
Set<? extends Cluster<T>> getClusters(float f);
|
||||
|
||||
Collection<T> getItems();
|
||||
|
||||
int getMaxDistanceBetweenClusteredItems();
|
||||
|
||||
void lock();
|
||||
|
||||
boolean removeItem(T t);
|
||||
|
||||
boolean removeItems(Collection<T> collection);
|
||||
|
||||
void setMaxDistanceBetweenClusteredItems(int i);
|
||||
|
||||
void unlock();
|
||||
|
||||
boolean updateItem(T t);
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.google.maps.android.clustering.algo;
|
||||
|
||||
import androidx.collection.LongSparseArray;
|
||||
import com.google.maps.android.clustering.Cluster;
|
||||
import com.google.maps.android.clustering.ClusterItem;
|
||||
import com.google.maps.android.projection.Point;
|
||||
import com.google.maps.android.projection.SphericalMercatorProjection;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/* JADX INFO: loaded from: classes2.dex */
|
||||
public class GridBasedAlgorithm<T extends ClusterItem> extends AbstractAlgorithm<T> {
|
||||
private static final int DEFAULT_GRID_SIZE = 100;
|
||||
private int mGridSize = 100;
|
||||
private final Set<T> mItems = Collections.synchronizedSet(new HashSet());
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public boolean addItem(T t) {
|
||||
return this.mItems.add(t);
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public boolean addItems(Collection<T> collection) {
|
||||
return this.mItems.addAll(collection);
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public void clearItems() {
|
||||
this.mItems.clear();
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public boolean removeItem(T t) {
|
||||
return this.mItems.remove(t);
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public boolean removeItems(Collection<T> collection) {
|
||||
return this.mItems.removeAll(collection);
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public boolean updateItem(T t) {
|
||||
boolean zRemoveItem;
|
||||
synchronized (this.mItems) {
|
||||
zRemoveItem = removeItem(t);
|
||||
if (zRemoveItem) {
|
||||
zRemoveItem = addItem(t);
|
||||
}
|
||||
}
|
||||
return zRemoveItem;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public void setMaxDistanceBetweenClusteredItems(int i) {
|
||||
this.mGridSize = i;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public int getMaxDistanceBetweenClusteredItems() {
|
||||
return this.mGridSize;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public Set<? extends Cluster<T>> getClusters(float f) {
|
||||
long j;
|
||||
long jCeil = (long) Math.ceil((Math.pow(2.0d, f) * 256.0d) / ((double) this.mGridSize));
|
||||
SphericalMercatorProjection sphericalMercatorProjection = new SphericalMercatorProjection(jCeil);
|
||||
HashSet hashSet = new HashSet();
|
||||
LongSparseArray longSparseArray = new LongSparseArray();
|
||||
synchronized (this.mItems) {
|
||||
for (T t : this.mItems) {
|
||||
Point point = sphericalMercatorProjection.toPoint(t.getPosition());
|
||||
long coord = getCoord(jCeil, point.x, point.y);
|
||||
StaticCluster staticCluster = (StaticCluster) longSparseArray.get(coord);
|
||||
if (staticCluster == null) {
|
||||
j = jCeil;
|
||||
staticCluster = new StaticCluster(sphericalMercatorProjection.toLatLng(new com.google.maps.android.geometry.Point(Math.floor(point.x) + 0.5d, Math.floor(point.y) + 0.5d)));
|
||||
longSparseArray.put(coord, staticCluster);
|
||||
hashSet.add(staticCluster);
|
||||
} else {
|
||||
j = jCeil;
|
||||
}
|
||||
staticCluster.add(t);
|
||||
jCeil = j;
|
||||
}
|
||||
}
|
||||
return hashSet;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public Collection<T> getItems() {
|
||||
return this.mItems;
|
||||
}
|
||||
|
||||
private static long getCoord(long j, double d, double d2) {
|
||||
return (long) ((j * Math.floor(d)) + Math.floor(d2));
|
||||
}
|
||||
}
|
||||
+227
@@ -0,0 +1,227 @@
|
||||
package com.google.maps.android.clustering.algo;
|
||||
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.maps.android.clustering.Cluster;
|
||||
import com.google.maps.android.clustering.ClusterItem;
|
||||
import com.google.maps.android.geometry.Bounds;
|
||||
import com.google.maps.android.geometry.Point;
|
||||
import com.google.maps.android.projection.SphericalMercatorProjection;
|
||||
import com.google.maps.android.quadtree.PointQuadTree;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/* JADX INFO: loaded from: classes2.dex */
|
||||
public class NonHierarchicalDistanceBasedAlgorithm<T extends ClusterItem> extends AbstractAlgorithm<T> {
|
||||
private static final int DEFAULT_MAX_DISTANCE_AT_ZOOM = 100;
|
||||
private static final SphericalMercatorProjection PROJECTION = new SphericalMercatorProjection(1.0d);
|
||||
private int mMaxDistance = 100;
|
||||
private final Collection<QuadItem<T>> mItems = new LinkedHashSet();
|
||||
private final PointQuadTree<QuadItem<T>> mQuadTree = new PointQuadTree<>(0.0d, 1.0d, 0.0d, 1.0d);
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public boolean addItem(T t) {
|
||||
boolean zAdd;
|
||||
QuadItem<T> quadItem = new QuadItem<>(t);
|
||||
synchronized (this.mQuadTree) {
|
||||
zAdd = this.mItems.add(quadItem);
|
||||
if (zAdd) {
|
||||
this.mQuadTree.add(quadItem);
|
||||
}
|
||||
}
|
||||
return zAdd;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public boolean addItems(Collection<T> collection) {
|
||||
Iterator<T> it = collection.iterator();
|
||||
boolean z = false;
|
||||
while (it.hasNext()) {
|
||||
if (addItem(it.next())) {
|
||||
z = true;
|
||||
}
|
||||
}
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public void clearItems() {
|
||||
synchronized (this.mQuadTree) {
|
||||
this.mItems.clear();
|
||||
this.mQuadTree.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public boolean removeItem(T t) {
|
||||
boolean zRemove;
|
||||
QuadItem quadItem = new QuadItem(t);
|
||||
synchronized (this.mQuadTree) {
|
||||
zRemove = this.mItems.remove(quadItem);
|
||||
if (zRemove) {
|
||||
this.mQuadTree.remove(quadItem);
|
||||
}
|
||||
}
|
||||
return zRemove;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public boolean removeItems(Collection<T> collection) {
|
||||
boolean z;
|
||||
synchronized (this.mQuadTree) {
|
||||
Iterator<T> it = collection.iterator();
|
||||
z = false;
|
||||
while (it.hasNext()) {
|
||||
QuadItem quadItem = new QuadItem(it.next());
|
||||
if (this.mItems.remove(quadItem)) {
|
||||
this.mQuadTree.remove(quadItem);
|
||||
z = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public boolean updateItem(T t) {
|
||||
boolean zRemoveItem;
|
||||
synchronized (this.mQuadTree) {
|
||||
zRemoveItem = removeItem(t);
|
||||
if (zRemoveItem) {
|
||||
zRemoveItem = addItem(t);
|
||||
}
|
||||
}
|
||||
return zRemoveItem;
|
||||
}
|
||||
|
||||
/* JADX WARN: Multi-variable type inference failed */
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public Set<? extends Cluster<T>> getClusters(float f) {
|
||||
double dPow = (((double) this.mMaxDistance) / Math.pow(2.0d, (int) f)) / 256.0d;
|
||||
HashSet hashSet = new HashSet();
|
||||
HashSet hashSet2 = new HashSet();
|
||||
HashMap map = new HashMap();
|
||||
HashMap map2 = new HashMap();
|
||||
synchronized (this.mQuadTree) {
|
||||
Iterator<QuadItem<T>> it = getClusteringItems(this.mQuadTree, f).iterator();
|
||||
while (it.hasNext()) {
|
||||
QuadItem<T> next = it.next();
|
||||
if (!hashSet.contains(next)) {
|
||||
Collection<T> collectionSearch = this.mQuadTree.search(createBoundsFromSpan(next.getPoint(), dPow));
|
||||
if (collectionSearch.size() == 1) {
|
||||
hashSet2.add(next);
|
||||
hashSet.add(next);
|
||||
map.put(next, Double.valueOf(0.0d));
|
||||
} else {
|
||||
StaticCluster staticCluster = new StaticCluster(((QuadItem) next).mClusterItem.getPosition());
|
||||
hashSet2.add(staticCluster);
|
||||
for (T t : collectionSearch) {
|
||||
Double d = (Double) map.get(t);
|
||||
Iterator<QuadItem<T>> it2 = it;
|
||||
double dDistanceSquared = distanceSquared(t.getPoint(), next.getPoint());
|
||||
if (d == null) {
|
||||
map.put(t, Double.valueOf(dDistanceSquared));
|
||||
staticCluster.add(t.mClusterItem);
|
||||
map2.put(t, staticCluster);
|
||||
} else if (d.doubleValue() >= dDistanceSquared) {
|
||||
((StaticCluster) map2.get(t)).remove(t.mClusterItem);
|
||||
map.put(t, Double.valueOf(dDistanceSquared));
|
||||
staticCluster.add(t.mClusterItem);
|
||||
map2.put(t, staticCluster);
|
||||
}
|
||||
it = it2;
|
||||
}
|
||||
hashSet.addAll(collectionSearch);
|
||||
it = it;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return hashSet2;
|
||||
}
|
||||
|
||||
protected Collection<QuadItem<T>> getClusteringItems(PointQuadTree<QuadItem<T>> pointQuadTree, float f) {
|
||||
return this.mItems;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public Collection<T> getItems() {
|
||||
LinkedHashSet linkedHashSet = new LinkedHashSet();
|
||||
synchronized (this.mQuadTree) {
|
||||
Iterator<QuadItem<T>> it = this.mItems.iterator();
|
||||
while (it.hasNext()) {
|
||||
linkedHashSet.add(((QuadItem) it.next()).mClusterItem);
|
||||
}
|
||||
}
|
||||
return linkedHashSet;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public void setMaxDistanceBetweenClusteredItems(int i) {
|
||||
this.mMaxDistance = i;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public int getMaxDistanceBetweenClusteredItems() {
|
||||
return this.mMaxDistance;
|
||||
}
|
||||
|
||||
private double distanceSquared(Point point, Point point2) {
|
||||
return ((point.x - point2.x) * (point.x - point2.x)) + ((point.y - point2.y) * (point.y - point2.y));
|
||||
}
|
||||
|
||||
private Bounds createBoundsFromSpan(Point point, double d) {
|
||||
double d2 = d / 2.0d;
|
||||
return new Bounds(point.x - d2, point.x + d2, point.y - d2, point.y + d2);
|
||||
}
|
||||
|
||||
protected static class QuadItem<T extends ClusterItem> implements PointQuadTree.Item, Cluster<T> {
|
||||
private final T mClusterItem;
|
||||
private final Point mPoint;
|
||||
private final LatLng mPosition;
|
||||
private Set<T> singletonSet;
|
||||
|
||||
@Override // com.google.maps.android.clustering.Cluster
|
||||
public int getSize() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
private QuadItem(T t) {
|
||||
this.mClusterItem = t;
|
||||
LatLng position = t.getPosition();
|
||||
this.mPosition = position;
|
||||
this.mPoint = NonHierarchicalDistanceBasedAlgorithm.PROJECTION.toPoint(position);
|
||||
this.singletonSet = Collections.singleton(t);
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.quadtree.PointQuadTree.Item
|
||||
public Point getPoint() {
|
||||
return this.mPoint;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.Cluster
|
||||
public LatLng getPosition() {
|
||||
return this.mPosition;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.Cluster
|
||||
public Set<T> getItems() {
|
||||
return this.singletonSet;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.mClusterItem.hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof QuadItem) {
|
||||
return ((QuadItem) obj).mClusterItem.equals(this.mClusterItem);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package com.google.maps.android.clustering.algo;
|
||||
|
||||
import com.google.android.gms.maps.model.CameraPosition;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.maps.android.clustering.ClusterItem;
|
||||
import com.google.maps.android.clustering.algo.NonHierarchicalDistanceBasedAlgorithm;
|
||||
import com.google.maps.android.geometry.Bounds;
|
||||
import com.google.maps.android.projection.Point;
|
||||
import com.google.maps.android.projection.SphericalMercatorProjection;
|
||||
import com.google.maps.android.quadtree.PointQuadTree;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
/* JADX INFO: loaded from: classes2.dex */
|
||||
public class NonHierarchicalViewBasedAlgorithm<T extends ClusterItem> extends NonHierarchicalDistanceBasedAlgorithm<T> implements ScreenBasedAlgorithm<T> {
|
||||
private static final SphericalMercatorProjection PROJECTION = new SphericalMercatorProjection(1.0d);
|
||||
private LatLng mMapCenter;
|
||||
private int mViewHeight;
|
||||
private int mViewWidth;
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.ScreenBasedAlgorithm
|
||||
public boolean shouldReclusterOnMapMovement() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public NonHierarchicalViewBasedAlgorithm(int i, int i2) {
|
||||
this.mViewWidth = i;
|
||||
this.mViewHeight = i2;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.ScreenBasedAlgorithm
|
||||
public void onCameraChange(CameraPosition cameraPosition) {
|
||||
this.mMapCenter = cameraPosition.target;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.NonHierarchicalDistanceBasedAlgorithm
|
||||
protected Collection<NonHierarchicalDistanceBasedAlgorithm.QuadItem<T>> getClusteringItems(PointQuadTree<NonHierarchicalDistanceBasedAlgorithm.QuadItem<T>> pointQuadTree, float f) {
|
||||
Bounds visibleBounds = getVisibleBounds(f);
|
||||
ArrayList arrayList = new ArrayList();
|
||||
if (visibleBounds.minX < 0.0d) {
|
||||
arrayList.addAll(pointQuadTree.search(new Bounds(visibleBounds.minX + 1.0d, 1.0d, visibleBounds.minY, visibleBounds.maxY)));
|
||||
visibleBounds = new Bounds(0.0d, visibleBounds.maxX, visibleBounds.minY, visibleBounds.maxY);
|
||||
}
|
||||
if (visibleBounds.maxX > 1.0d) {
|
||||
arrayList.addAll(pointQuadTree.search(new Bounds(0.0d, visibleBounds.maxX - 1.0d, visibleBounds.minY, visibleBounds.maxY)));
|
||||
visibleBounds = new Bounds(visibleBounds.minX, 1.0d, visibleBounds.minY, visibleBounds.maxY);
|
||||
}
|
||||
arrayList.addAll(pointQuadTree.search(visibleBounds));
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
public void updateViewSize(int i, int i2) {
|
||||
this.mViewWidth = i;
|
||||
this.mViewHeight = i2;
|
||||
}
|
||||
|
||||
private Bounds getVisibleBounds(float f) {
|
||||
LatLng latLng = this.mMapCenter;
|
||||
if (latLng == null) {
|
||||
return new Bounds(0.0d, 0.0d, 0.0d, 0.0d);
|
||||
}
|
||||
Point point = PROJECTION.toPoint(latLng);
|
||||
double d = f;
|
||||
double dPow = ((((double) this.mViewWidth) / Math.pow(2.0d, d)) / 256.0d) / 2.0d;
|
||||
double dPow2 = ((((double) this.mViewHeight) / Math.pow(2.0d, d)) / 256.0d) / 2.0d;
|
||||
return new Bounds(point.x - dPow, point.x + dPow, point.y - dPow2, point.y + dPow2);
|
||||
}
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
package com.google.maps.android.clustering.algo;
|
||||
|
||||
import androidx.collection.LruCache;
|
||||
import com.google.maps.android.clustering.Cluster;
|
||||
import com.google.maps.android.clustering.ClusterItem;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
/* JADX INFO: loaded from: classes2.dex */
|
||||
public class PreCachingAlgorithmDecorator<T extends ClusterItem> extends AbstractAlgorithm<T> {
|
||||
private final Algorithm<T> mAlgorithm;
|
||||
private final LruCache<Integer, Set<? extends Cluster<T>>> mCache = new LruCache<>(5);
|
||||
private final ReadWriteLock mCacheLock = new ReentrantReadWriteLock();
|
||||
private final Executor mExecutor = Executors.newCachedThreadPool();
|
||||
|
||||
public PreCachingAlgorithmDecorator(Algorithm<T> algorithm) {
|
||||
this.mAlgorithm = algorithm;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public boolean addItem(T t) {
|
||||
boolean zAddItem = this.mAlgorithm.addItem(t);
|
||||
if (zAddItem) {
|
||||
clearCache();
|
||||
}
|
||||
return zAddItem;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public boolean addItems(Collection<T> collection) {
|
||||
boolean zAddItems = this.mAlgorithm.addItems(collection);
|
||||
if (zAddItems) {
|
||||
clearCache();
|
||||
}
|
||||
return zAddItems;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public void clearItems() {
|
||||
this.mAlgorithm.clearItems();
|
||||
clearCache();
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public boolean removeItem(T t) {
|
||||
boolean zRemoveItem = this.mAlgorithm.removeItem(t);
|
||||
if (zRemoveItem) {
|
||||
clearCache();
|
||||
}
|
||||
return zRemoveItem;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public boolean removeItems(Collection<T> collection) {
|
||||
boolean zRemoveItems = this.mAlgorithm.removeItems(collection);
|
||||
if (zRemoveItems) {
|
||||
clearCache();
|
||||
}
|
||||
return zRemoveItems;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public boolean updateItem(T t) {
|
||||
boolean zUpdateItem = this.mAlgorithm.updateItem(t);
|
||||
if (zUpdateItem) {
|
||||
clearCache();
|
||||
}
|
||||
return zUpdateItem;
|
||||
}
|
||||
|
||||
private void clearCache() {
|
||||
this.mCache.evictAll();
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public Set<? extends Cluster<T>> getClusters(float f) {
|
||||
int i = (int) f;
|
||||
Set<? extends Cluster<T>> clustersInternal = getClustersInternal(i);
|
||||
int i2 = i + 1;
|
||||
if (this.mCache.get(Integer.valueOf(i2)) == null) {
|
||||
this.mExecutor.execute(new PrecacheRunnable(i2));
|
||||
}
|
||||
int i3 = i - 1;
|
||||
if (this.mCache.get(Integer.valueOf(i3)) == null) {
|
||||
this.mExecutor.execute(new PrecacheRunnable(i3));
|
||||
}
|
||||
return clustersInternal;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public Collection<T> getItems() {
|
||||
return this.mAlgorithm.getItems();
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public void setMaxDistanceBetweenClusteredItems(int i) {
|
||||
this.mAlgorithm.setMaxDistanceBetweenClusteredItems(i);
|
||||
clearCache();
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public int getMaxDistanceBetweenClusteredItems() {
|
||||
return this.mAlgorithm.getMaxDistanceBetweenClusteredItems();
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public Set<? extends Cluster<T>> getClustersInternal(int i) {
|
||||
this.mCacheLock.readLock().lock();
|
||||
Set<? extends Cluster<T>> clusters = this.mCache.get(Integer.valueOf(i));
|
||||
this.mCacheLock.readLock().unlock();
|
||||
if (clusters == null) {
|
||||
this.mCacheLock.writeLock().lock();
|
||||
clusters = this.mCache.get(Integer.valueOf(i));
|
||||
if (clusters == null) {
|
||||
clusters = this.mAlgorithm.getClusters(i);
|
||||
this.mCache.put(Integer.valueOf(i), clusters);
|
||||
}
|
||||
this.mCacheLock.writeLock().unlock();
|
||||
}
|
||||
return clusters;
|
||||
}
|
||||
|
||||
private class PrecacheRunnable implements Runnable {
|
||||
private final int mZoom;
|
||||
|
||||
public PrecacheRunnable(int i) {
|
||||
this.mZoom = i;
|
||||
}
|
||||
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep((long) ((Math.random() * 500.0d) + 500.0d));
|
||||
} catch (InterruptedException unused) {
|
||||
}
|
||||
PreCachingAlgorithmDecorator.this.getClustersInternal(this.mZoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.google.maps.android.clustering.algo;
|
||||
|
||||
import com.google.android.gms.maps.model.CameraPosition;
|
||||
import com.google.maps.android.clustering.ClusterItem;
|
||||
|
||||
/* JADX INFO: loaded from: classes2.dex */
|
||||
public interface ScreenBasedAlgorithm<T extends ClusterItem> extends Algorithm<T> {
|
||||
void onCameraChange(CameraPosition cameraPosition);
|
||||
|
||||
boolean shouldReclusterOnMapMovement();
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package com.google.maps.android.clustering.algo;
|
||||
|
||||
import com.google.android.gms.maps.model.CameraPosition;
|
||||
import com.google.maps.android.clustering.Cluster;
|
||||
import com.google.maps.android.clustering.ClusterItem;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
/* JADX INFO: loaded from: classes2.dex */
|
||||
public class ScreenBasedAlgorithmAdapter<T extends ClusterItem> extends AbstractAlgorithm<T> implements ScreenBasedAlgorithm<T> {
|
||||
private Algorithm<T> mAlgorithm;
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.ScreenBasedAlgorithm
|
||||
public void onCameraChange(CameraPosition cameraPosition) {
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.ScreenBasedAlgorithm
|
||||
public boolean shouldReclusterOnMapMovement() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ScreenBasedAlgorithmAdapter(Algorithm<T> algorithm) {
|
||||
this.mAlgorithm = algorithm;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public boolean addItem(T t) {
|
||||
return this.mAlgorithm.addItem(t);
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public boolean addItems(Collection<T> collection) {
|
||||
return this.mAlgorithm.addItems(collection);
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public void clearItems() {
|
||||
this.mAlgorithm.clearItems();
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public boolean removeItem(T t) {
|
||||
return this.mAlgorithm.removeItem(t);
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public boolean removeItems(Collection<T> collection) {
|
||||
return this.mAlgorithm.removeItems(collection);
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public boolean updateItem(T t) {
|
||||
return this.mAlgorithm.updateItem(t);
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public Set<? extends Cluster<T>> getClusters(float f) {
|
||||
return this.mAlgorithm.getClusters(f);
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public Collection<T> getItems() {
|
||||
return this.mAlgorithm.getItems();
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public void setMaxDistanceBetweenClusteredItems(int i) {
|
||||
this.mAlgorithm.setMaxDistanceBetweenClusteredItems(i);
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.algo.Algorithm
|
||||
public int getMaxDistanceBetweenClusteredItems() {
|
||||
return this.mAlgorithm.getMaxDistanceBetweenClusteredItems();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.google.maps.android.clustering.algo;
|
||||
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.maps.android.clustering.Cluster;
|
||||
import com.google.maps.android.clustering.ClusterItem;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import kotlinx.serialization.json.internal.AbstractJsonLexerKt;
|
||||
|
||||
/* JADX INFO: loaded from: classes2.dex */
|
||||
public class StaticCluster<T extends ClusterItem> implements Cluster<T> {
|
||||
private final LatLng mCenter;
|
||||
private final Collection<T> mItems = new LinkedHashSet();
|
||||
|
||||
public StaticCluster(LatLng latLng) {
|
||||
this.mCenter = latLng;
|
||||
}
|
||||
|
||||
public boolean add(T t) {
|
||||
return this.mItems.add(t);
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.Cluster
|
||||
public LatLng getPosition() {
|
||||
return this.mCenter;
|
||||
}
|
||||
|
||||
public boolean remove(T t) {
|
||||
return this.mItems.remove(t);
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.Cluster
|
||||
public Collection<T> getItems() {
|
||||
return this.mItems;
|
||||
}
|
||||
|
||||
@Override // com.google.maps.android.clustering.Cluster
|
||||
public int getSize() {
|
||||
return this.mItems.size();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "StaticCluster{mCenter=" + this.mCenter + ", mItems.size=" + this.mItems.size() + AbstractJsonLexerKt.END_OBJ;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.mCenter.hashCode() + this.mItems.hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof StaticCluster)) {
|
||||
return false;
|
||||
}
|
||||
StaticCluster staticCluster = (StaticCluster) obj;
|
||||
return staticCluster.mCenter.equals(this.mCenter) && staticCluster.mItems.equals(this.mItems);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user