Skip to content

Commit e840c1a

Browse files
committed
fix: address lint issues in Java and Kotlin files
1 parent 36e27de commit e840c1a

18 files changed

Lines changed: 124 additions & 110 deletions

File tree

clustering/src/main/java/com/google/maps/android/clustering/ClusterManager.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package com.google.maps.android.clustering
1717

1818
import android.content.Context
19-
import android.os.AsyncTask
2019
import com.google.android.gms.maps.GoogleMap
2120
import com.google.android.gms.maps.GoogleMap.OnCameraIdleListener
2221
import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener

clustering/src/main/java/com/google/maps/android/clustering/algo/NonHierarchicalDistanceBasedAlgorithm.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import com.google.maps.android.geometry.Bounds
2222
import com.google.maps.android.geometry.Point
2323
import com.google.maps.android.projection.SphericalMercatorProjection
2424
import com.google.maps.android.quadtree.PointQuadTree
25-
import java.util.ArrayList
2625
import java.util.Collections
2726
import java.util.HashMap
2827
import java.util.HashSet

clustering/src/main/java/com/google/maps/android/clustering/algo/PreCachingAlgorithmDecorator.kt

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import java.util.concurrent.Executor
2222
import java.util.concurrent.Executors
2323
import java.util.concurrent.locks.ReadWriteLock
2424
import java.util.concurrent.locks.ReentrantReadWriteLock
25+
import kotlin.concurrent.withLock
2526

2627
/**
2728
* Optimistically fetch clusters for adjacent zoom levels, caching them as necessary.
@@ -107,24 +108,18 @@ class PreCachingAlgorithmDecorator<T : ClusterItem>(
107108
}
108109

109110
private fun getClustersInternal(discreteZoom: Int): Set<Cluster<T>> {
110-
var results: Set<Cluster<T>>?
111-
mCacheLock.readLock().lock()
112-
results = mCache.get(discreteZoom)
113-
mCacheLock.readLock().unlock()
111+
val cached = mCacheLock.readLock().withLock {
112+
mCache.get(discreteZoom)
113+
}
114+
if (cached != null) {
115+
return cached
116+
}
114117

115-
if (results == null) {
116-
mCacheLock.writeLock().lock()
117-
try {
118-
results = mCache.get(discreteZoom)
119-
if (results == null) {
120-
results = algorithm.getClusters(discreteZoom.toFloat())
121-
mCache.put(discreteZoom, results)
122-
}
123-
} finally {
124-
mCacheLock.writeLock().unlock()
118+
return mCacheLock.writeLock().withLock {
119+
mCache.get(discreteZoom) ?: algorithm.getClusters(discreteZoom.toFloat()).also {
120+
mCache.put(discreteZoom, it)
125121
}
126122
}
127-
return results!!
128123
}
129124

130125
private inner class PrecacheRunnable(

clustering/src/main/java/com/google/maps/android/clustering/view/ClusterRenderer.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package com.google.maps.android.clustering.view
1818
import androidx.annotation.StyleRes
1919
import com.google.maps.android.clustering.Cluster
2020
import com.google.maps.android.clustering.ClusterItem
21-
import com.google.maps.android.clustering.ClusterManager
2221
import com.google.maps.android.clustering.ClusterManager.OnClusterClickListener
2322
import com.google.maps.android.clustering.ClusterManager.OnClusterInfoWindowClickListener
2423
import com.google.maps.android.clustering.ClusterManager.OnClusterInfoWindowLongClickListener

clustering/src/main/java/com/google/maps/android/clustering/view/ClusterRendererMultipleItems.kt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ import java.util.Queue
6363
import java.util.concurrent.ConcurrentHashMap
6464
import java.util.concurrent.Executor
6565
import java.util.concurrent.Executors
66-
import java.util.concurrent.locks.Condition
6766
import java.util.concurrent.locks.Lock
6867
import java.util.concurrent.locks.ReentrantLock
6968
import kotlin.math.abs
@@ -325,17 +324,19 @@ open class ClusterRendererMultipleItems<T : ClusterItem> @JvmOverloads construct
325324
}
326325
val projection = mMap.projection
327326

328-
var renderTask: RenderTask?
329-
synchronized(this) {
330-
renderTask = mNextClusters
327+
val renderTask = synchronized(this) {
328+
val task = mNextClusters
331329
mNextClusters = null
332330
mViewModificationInProgress = true
331+
task
333332
}
334333

335-
renderTask!!.setCallback { sendEmptyMessage(TASK_FINISHED) }
336-
renderTask!!.setProjection(projection)
337-
renderTask!!.setMapZoom(mMap.cameraPosition.zoom)
338-
mExecutor.execute(renderTask)
334+
renderTask?.let {
335+
it.setCallback { sendEmptyMessage(TASK_FINISHED) }
336+
it.setProjection(projection)
337+
it.setMapZoom(mMap.cameraPosition.zoom)
338+
mExecutor.execute(it)
339+
}
339340
}
340341

341342
fun queue(clusters: Set<Cluster<T>>) {
@@ -475,14 +476,15 @@ open class ClusterRendererMultipleItems<T : ClusterItem> @JvmOverloads construct
475476
}
476477

477478
for (marker in markersToRemove) {
478-
val onScreen = marker.position?.let { visibleBounds.contains(it) } ?: false
479+
val position = marker.position
480+
val onScreen = position?.let { visibleBounds.contains(it) } ?: false
479481

480482
if (onScreen && mAnimate) {
481-
val point = mSphericalMercatorProjection!!.toPoint(marker.position!!)
483+
val point = mSphericalMercatorProjection!!.toPoint(position)
482484
val closest = findClosestCluster(newClustersOnScreen, point)
483485
if (closest != null) {
484486
val animateTo = mSphericalMercatorProjection!!.toLatLng(closest)
485-
markerModifier.animateThenRemove(marker, marker.position!!, animateTo!!)
487+
markerModifier.animateThenRemove(marker, position, animateTo)
486488
RendererLogger.d("ClusterRenderer", "Animating then removing marker at position: " + marker.position)
487489
} else if (mClusterMarkerCache.mCache.keys
488490
.iterator()
@@ -1143,7 +1145,7 @@ open class ClusterRendererMultipleItems<T : ClusterItem> @JvmOverloads construct
11431145
val markerWithPosition: MarkerWithPosition<T>
11441146
if (marker == null) {
11451147
RendererLogger.d("ClusterRenderer", "Creating new cluster marker")
1146-
val markerOptions = MarkerOptions().position(if (animateFrom == null) cluster.position else animateFrom)
1148+
val markerOptions = MarkerOptions().position(animateFrom ?: cluster.position)
11471149
onBeforeClusterRendered(cluster, markerOptions)
11481150
marker = mClusterManager.clusterMarkerCollection.addMarker(markerOptions)
11491151
mClusterMarkerCache.put(cluster, marker)

clustering/src/main/java/com/google/maps/android/clustering/view/DefaultAdvancedMarkersClusterRenderer.kt

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ import java.util.Queue
6060
import java.util.concurrent.ConcurrentHashMap
6161
import java.util.concurrent.Executor
6262
import java.util.concurrent.Executors
63-
import java.util.concurrent.locks.Condition
6463
import java.util.concurrent.locks.ReentrantLock
6564
import kotlin.math.abs
6665
import kotlin.math.min
@@ -269,17 +268,19 @@ open class DefaultAdvancedMarkersClusterRenderer<T : ClusterItem> @JvmOverloads
269268
}
270269
val projection = mMap.projection
271270

272-
var renderTask: RenderTask?
273-
synchronized(this) {
274-
renderTask = mNextClusters
271+
val renderTask = synchronized(this) {
272+
val task = mNextClusters
275273
mNextClusters = null
276274
mViewModificationInProgress = true
275+
task
277276
}
278277

279-
renderTask!!.setCallback { sendEmptyMessage(TASK_FINISHED) }
280-
renderTask!!.setProjection(projection)
281-
renderTask!!.setMapZoom(mMap.cameraPosition.zoom)
282-
mExecutor.execute(renderTask)
278+
renderTask?.let {
279+
it.setCallback { sendEmptyMessage(TASK_FINISHED) }
280+
it.setProjection(projection)
281+
it.setMapZoom(mMap.cameraPosition.zoom)
282+
mExecutor.execute(it)
283+
}
283284
}
284285

285286
fun queue(clusters: Set<Cluster<T>>) {
@@ -473,7 +474,7 @@ open class DefaultAdvancedMarkersClusterRenderer<T : ClusterItem> @JvmOverloads
473474
val closest = findClosestCluster(newClustersOnScreen, point)
474475
if (closest != null) {
475476
val animateTo = mSphericalMercatorProjection!!.toLatLng(closest)
476-
markerModifier.animateThenRemove(marker, marker.position, animateTo!!)
477+
markerModifier.animateThenRemove(marker, marker.position, animateTo)
477478
} else {
478479
markerModifier.remove(true, marker.marker)
479480
}
@@ -1004,7 +1005,7 @@ open class DefaultAdvancedMarkersClusterRenderer<T : ClusterItem> @JvmOverloads
10041005
if (!shouldRenderAsCluster(cluster)) {
10051006
for (item in cluster.items) {
10061007
var marker = mMarkerCache[item] as AdvancedMarker?
1007-
var markerWithPosition: MarkerWithPosition
1008+
val markerWithPosition: MarkerWithPosition
10081009
if (marker == null) {
10091010
val advancedMarkerOptions = AdvancedMarkerOptions()
10101011
if (animateFrom != null) {
@@ -1016,9 +1017,10 @@ open class DefaultAdvancedMarkersClusterRenderer<T : ClusterItem> @JvmOverloads
10161017
}
10171018
}
10181019
onBeforeClusterItemRendered(item, advancedMarkerOptions)
1019-
marker = mClusterManager.markerCollection.addMarker(advancedMarkerOptions) as AdvancedMarker?
1020-
markerWithPosition = MarkerWithPosition(marker!!)
1021-
mMarkerCache.put(item, marker!!)
1020+
val newMarker = mClusterManager.markerCollection.addMarker(advancedMarkerOptions) as AdvancedMarker
1021+
marker = newMarker
1022+
markerWithPosition = MarkerWithPosition(newMarker)
1023+
mMarkerCache.put(item, newMarker)
10221024
if (animateFrom != null) {
10231025
markerModifier.animate(markerWithPosition, animateFrom, item.position)
10241026
}
@@ -1033,22 +1035,22 @@ open class DefaultAdvancedMarkersClusterRenderer<T : ClusterItem> @JvmOverloads
10331035
}
10341036

10351037
var marker = mClusterMarkerCache[cluster] as AdvancedMarker?
1036-
var markerWithPosition: MarkerWithPosition
1038+
val markerWithPosition: MarkerWithPosition
10371039
if (marker == null) {
1038-
val advancedMarkerOptions = AdvancedMarkerOptions().position(if (animateFrom == null) cluster.position else animateFrom)
1040+
val advancedMarkerOptions = AdvancedMarkerOptions().position(animateFrom ?: cluster.position)
10391041
onBeforeClusterRendered(cluster, advancedMarkerOptions)
1040-
val `object` = mClusterManager.clusterMarkerCollection.addMarker(advancedMarkerOptions)
1041-
marker = `object` as AdvancedMarker?
1042-
mClusterMarkerCache.put(cluster, marker!!)
1043-
markerWithPosition = MarkerWithPosition(marker)
1042+
val newMarker = mClusterManager.clusterMarkerCollection.addMarker(advancedMarkerOptions) as AdvancedMarker
1043+
marker = newMarker
1044+
mClusterMarkerCache.put(cluster, newMarker)
1045+
markerWithPosition = MarkerWithPosition(newMarker)
10441046
if (animateFrom != null) {
10451047
markerModifier.animate(markerWithPosition, animateFrom, cluster.position)
10461048
}
10471049
} else {
10481050
markerWithPosition = MarkerWithPosition(marker)
10491051
onClusterUpdated(cluster, marker)
10501052
}
1051-
onClusterRendered(cluster, marker!!)
1053+
onClusterRendered(cluster, marker)
10521054
newMarkers.add(markerWithPosition)
10531055
}
10541056
}

clustering/src/main/java/com/google/maps/android/clustering/view/DefaultClusterRenderer.kt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ import java.util.Queue
5959
import java.util.concurrent.ConcurrentHashMap
6060
import java.util.concurrent.Executor
6161
import java.util.concurrent.Executors
62-
import java.util.concurrent.locks.Condition
6362
import java.util.concurrent.locks.ReentrantLock
6463
import kotlin.math.abs
6564
import kotlin.math.min
@@ -268,17 +267,19 @@ open class DefaultClusterRenderer<T : ClusterItem> @JvmOverloads constructor(
268267
}
269268
val projection = mMap.projection
270269

271-
var renderTask: RenderTask?
272-
synchronized(this) {
273-
renderTask = mNextClusters
270+
val renderTask = synchronized(this) {
271+
val task = mNextClusters
274272
mNextClusters = null
275273
mViewModificationInProgress = true
274+
task
276275
}
277276

278-
renderTask!!.setCallback { sendEmptyMessage(TASK_FINISHED) }
279-
renderTask!!.setProjection(projection)
280-
renderTask!!.setMapZoom(mMap.cameraPosition.zoom)
281-
mExecutor.execute(renderTask)
277+
renderTask?.let {
278+
it.setCallback { sendEmptyMessage(TASK_FINISHED) }
279+
it.setProjection(projection)
280+
it.setMapZoom(mMap.cameraPosition.zoom)
281+
mExecutor.execute(it)
282+
}
282283
}
283284

284285
fun queue(clusters: Set<Cluster<T>>) {
@@ -472,7 +473,7 @@ open class DefaultClusterRenderer<T : ClusterItem> @JvmOverloads constructor(
472473
val closest = findClosestCluster(newClustersOnScreen, point)
473474
if (closest != null) {
474475
val animateTo = mSphericalMercatorProjection!!.toLatLng(closest)
475-
markerModifier.animateThenRemove(marker, marker.position, animateTo!!)
476+
markerModifier.animateThenRemove(marker, marker.position, animateTo)
476477
} else {
477478
markerModifier.remove(true, marker.marker)
478479
}
@@ -1013,7 +1014,7 @@ open class DefaultClusterRenderer<T : ClusterItem> @JvmOverloads constructor(
10131014
if (!shouldRenderAsCluster(cluster)) {
10141015
for (item in cluster.items) {
10151016
var marker = mMarkerCache[item]
1016-
var markerWithPosition: MarkerWithPosition
1017+
val markerWithPosition: MarkerWithPosition
10171018
if (marker == null) {
10181019
val markerOptions = MarkerOptions()
10191020
if (animateFrom != null) {
@@ -1042,9 +1043,9 @@ open class DefaultClusterRenderer<T : ClusterItem> @JvmOverloads constructor(
10421043
}
10431044

10441045
var marker = mClusterMarkerCache[cluster]
1045-
var markerWithPosition: MarkerWithPosition
1046+
val markerWithPosition: MarkerWithPosition
10461047
if (marker == null) {
1047-
val markerOptions = MarkerOptions().position(if (animateFrom == null) cluster.position else animateFrom)
1048+
val markerOptions = MarkerOptions().position(animateFrom ?: cluster.position)
10481049
onBeforeClusterRendered(cluster, markerOptions)
10491050
marker = mClusterManager.clusterMarkerCollection.addMarker(markerOptions)
10501051
mClusterMarkerCache.put(cluster, marker)

clustering/src/main/java/com/google/maps/android/projection/SphericalMercatorProjection.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ import kotlin.math.*
2121
class SphericalMercatorProjection(
2222
private val worldWidth: Double,
2323
) {
24-
fun toPoint(latLng: LatLng): Point {
24+
fun toPoint(latLng: LatLng): com.google.maps.android.geometry.Point {
2525
val x = latLng.longitude / 360 + .5
2626
val siny = sin(Math.toRadians(latLng.latitude))
2727
val y = 0.5 * ln((1 + siny) / (1 - siny)) / -(2 * PI) + .5
2828

29-
return Point(x * worldWidth, y * worldWidth)
29+
return com.google.maps.android.geometry.Point(x * worldWidth, y * worldWidth)
3030
}
3131

3232
fun toLatLng(point: com.google.maps.android.geometry.Point): LatLng {

data/src/main/java/com/google/maps/android/renderer/GoogleMapRenderer.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,17 @@ class GoogleMapRenderer(
4040

4141
override fun addLayer(layer: Layer) {
4242
if (layers.add(layer)) {
43-
layer.mapObjects.forEach { renderObject(it) }
43+
for (mapObject in layer.mapObjects) {
44+
renderObject(mapObject)
45+
}
4446
}
4547
}
4648

4749
override fun removeLayer(layer: Layer): Boolean {
4850
if (layers.remove(layer)) {
49-
layer.mapObjects.forEach { removeRenderedObject(it) }
51+
for (mapObject in layer.mapObjects) {
52+
removeRenderedObject(mapObject)
53+
}
5054
return true
5155
}
5256
return false
@@ -55,8 +59,10 @@ class GoogleMapRenderer(
5559
override fun getLayers(): Collection<Layer> = layers
5660

5761
override fun clear() {
58-
layers.forEach { layer ->
59-
layer.mapObjects.forEach { removeRenderedObject(it) }
62+
for (layer in layers) {
63+
for (mapObject in layer.mapObjects) {
64+
removeRenderedObject(mapObject)
65+
}
6066
}
6167
layers.clear()
6268
}
@@ -135,7 +141,9 @@ class GoogleMapRenderer(
135141
visible(polygon.isVisible)
136142
zIndex(polygon.zIndex)
137143
strokeJointType(polygon.strokeJointType)
138-
polygon.holes.forEach { addHole(it) }
144+
for (hole in polygon.holes) {
145+
addHole(hole)
146+
}
139147
polygon.strokePattern?.let { strokePattern(it) }
140148
}
141149
val sdkPolygon = map.addPolygon(options)

0 commit comments

Comments
 (0)