In my Android application, I have to delete and re-add a cluster item in my GoogleMap, that represents my current location. But when I run this code:
cluster
Here is how I did it:
@Override
public void removeItem(T item) {
final QuadItem quadItem = new QuadItem(item);
synchronized (mQuadTree) {
mItems.remove(quadItem);
mQuadTree.remove(quadItem);
}
}
I also implemented equals()
and hashCode()
in QuadItem
as it is recommended in the TODO of the NonHierarchicalDistanceBasedAlgorithm
source code:
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof QuadItem)) {
return false;
}
QuadItem quadItem = (QuadItem) o;
return mClusterItem.equals(quadItem.mClusterItem);
}
@Override
public int hashCode() {
return mClusterItem.hashCode();
}
Finally, I implemented equals()
and hashCode()
in my ClusterItem
's descendant class.