Skip to content

Commit

Permalink
feat: Add nullability annotations to ClusterItem (#687)
Browse files Browse the repository at this point in the history
* feat: Add nullability annotations to ClusterItem

* Adding nullability info to protected methods.
  • Loading branch information
arriolac authored Apr 13, 2020
1 parent 18cc7bf commit 741f832
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.google.maps.android.clustering;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.android.gms.maps.model.LatLng;

/**
Expand All @@ -26,15 +29,15 @@ public interface ClusterItem {
/**
* The position of this marker. This must always return the same value.
*/
LatLng getPosition();
@NonNull LatLng getPosition();

/**
* The title of this marker.
*/
String getTitle();
@Nullable String getTitle();

/**
* The description of this marker.
*/
String getSnippet();
@Nullable String getSnippet();
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;

import androidx.annotation.NonNull;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.Projection;
import com.google.android.gms.maps.model.BitmapDescriptor;
Expand Down Expand Up @@ -208,7 +210,7 @@ protected int getColor(int clusterSize) {
});
}

protected String getClusterText(int bucket) {
@NonNull protected String getClusterText(int bucket) {
if (bucket < BUCKETS[0]) {
return String.valueOf(bucket);
}
Expand All @@ -219,7 +221,7 @@ protected String getClusterText(int bucket) {
* Gets the "bucket" for a particular cluster. By default, uses the number of points within the
* cluster, bucketed to some set points.
*/
protected int getBucket(Cluster<T> cluster) {
protected int getBucket(@NonNull Cluster<T> cluster) {
int size = cluster.getSize();
if (size <= BUCKETS[0]) {
return size;
Expand Down Expand Up @@ -305,7 +307,7 @@ public void queue(Set<? extends Cluster<T>> clusters) {
/**
* Determine whether the cluster should be rendered as individual markers or a cluster.
*/
protected boolean shouldRenderAsCluster(Cluster<T> cluster) {
protected boolean shouldRenderAsCluster(@NonNull Cluster<T> cluster) {
return cluster.getSize() > mMinClusterSize;
}

Expand Down Expand Up @@ -749,7 +751,7 @@ public void remove(Marker m) {
* @param item item to be rendered
* @param markerOptions the markerOptions representing the provided item
*/
protected void onBeforeClusterItemRendered(T item, MarkerOptions markerOptions) {
protected void onBeforeClusterItemRendered(@NonNull T item, @NonNull MarkerOptions markerOptions) {
if (item.getTitle() != null && item.getSnippet() != null) {
markerOptions.title(item.getTitle());
markerOptions.snippet(item.getSnippet());
Expand Down Expand Up @@ -778,7 +780,7 @@ protected void onBeforeClusterItemRendered(T item, MarkerOptions markerOptions)
* @param item item being updated
* @param marker cached marker that contains a potentially previous state of the item.
*/
protected void onClusterItemUpdated(T item, Marker marker) {
protected void onClusterItemUpdated(@NonNull T item, @NonNull Marker marker) {
boolean changed = false;
// Update marker text if the item text changed - same logic as adding marker in CreateMarkerTask.perform()
if (item.getTitle() != null && item.getSnippet() != null) {
Expand Down Expand Up @@ -822,7 +824,7 @@ protected void onClusterItemUpdated(T item, Marker marker) {
* @param cluster cluster to be rendered
* @param markerOptions markerOptions representing the provided cluster
*/
protected void onBeforeClusterRendered(Cluster<T> cluster, MarkerOptions markerOptions) {
protected void onBeforeClusterRendered(@NonNull Cluster<T> cluster, @NonNull MarkerOptions markerOptions) {
// TODO: consider adding anchor(.5, .5) (Individual markers will overlap more often)
markerOptions.icon(getDescriptorForCluster(cluster));
}
Expand All @@ -837,7 +839,8 @@ protected void onBeforeClusterRendered(Cluster<T> cluster, MarkerOptions markerO
* @return a BitmapDescriptor for the marker icon for the given cluster that contains a rough
* count of the number of items.
*/
protected BitmapDescriptor getDescriptorForCluster(Cluster<T> cluster) {
@NonNull
protected BitmapDescriptor getDescriptorForCluster(@NonNull Cluster<T> cluster) {
int bucket = getBucket(cluster);
BitmapDescriptor descriptor = mIcons.get(bucket);
if (descriptor == null) {
Expand All @@ -854,7 +857,7 @@ protected BitmapDescriptor getDescriptorForCluster(Cluster<T> cluster) {
* @param cluster the cluster that was just added to the map
* @param marker the marker representing the cluster that was just added to the map
*/
protected void onClusterRendered(Cluster<T> cluster, Marker marker) {
protected void onClusterRendered(@NonNull Cluster<T> cluster, @NonNull Marker marker) {
}

/**
Expand All @@ -874,7 +877,7 @@ protected void onClusterRendered(Cluster<T> cluster, Marker marker) {
* @param cluster cluster being updated
* @param marker cached marker that contains a potentially previous state of the cluster
*/
protected void onClusterUpdated(Cluster<T> cluster, Marker marker) {
protected void onClusterUpdated(@NonNull Cluster<T> cluster, @NonNull Marker marker) {
// TODO: consider adding anchor(.5, .5) (Individual markers will overlap more often)
marker.setIcon(getDescriptorForCluster(cluster));
}
Expand All @@ -885,7 +888,7 @@ protected void onClusterUpdated(Cluster<T> cluster, Marker marker) {
* @param clusterItem the item that was just added to the map
* @param marker the marker representing the item that was just added to the map
*/
protected void onClusterItemRendered(T clusterItem, Marker marker) {
protected void onClusterItemRendered(@NonNull T clusterItem, @NonNull Marker marker) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.google.maps.android.clustering;

import androidx.annotation.NonNull;

import com.google.android.gms.maps.model.LatLng;
import com.google.maps.android.clustering.algo.NonHierarchicalDistanceBasedAlgorithm;

Expand Down Expand Up @@ -112,6 +114,7 @@ private class TestingItem implements ClusterItem {
mPosition = new LatLng(lat, lng);
}

@NonNull
@Override
public LatLng getPosition() {
return mPosition;
Expand Down

0 comments on commit 741f832

Please sign in to comment.