diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CompositeFunction.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CompositeFunction.java index 1ed43580c..1db14afc5 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CompositeFunction.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CompositeFunction.java @@ -3,7 +3,10 @@ package com.mapbox.mapboxsdk.style.functions; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import com.mapbox.mapboxsdk.style.functions.stops.CompositeStops; +import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops; +import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; +import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops; +import com.mapbox.mapboxsdk.style.functions.stops.Stop; import com.mapbox.mapboxsdk.style.functions.stops.Stops; import java.util.Map; @@ -21,13 +24,23 @@ import java.util.Map; * @param the output type (the property type) * @see Function#composite */ -public class CompositeFunction extends Function { +public class CompositeFunction extends Function, O> { private final String property; private O defaultValue; CompositeFunction(@NonNull String property, - @NonNull CompositeStops> stops) { + @NonNull CategoricalStops, O> stops) { + this(null, property, stops); + } + + CompositeFunction(@NonNull String property, + @NonNull ExponentialStops, O> stops) { + this(null, property, stops); + } + + CompositeFunction(@NonNull String property, + @NonNull IntervalStops, O> stops) { this(null, property, stops); } @@ -36,7 +49,7 @@ public class CompositeFunction extends Function { * JNI Constructor */ private CompositeFunction(@Nullable O defaultValue, @NonNull String property, - @NonNull CompositeStops> stops) { + @NonNull Stops, O> stops) { super(stops); this.defaultValue = defaultValue; this.property = property; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/Function.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/Function.java index 8c5186b99..c45f4b6ca 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/Function.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/Function.java @@ -4,7 +4,6 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops; -import com.mapbox.mapboxsdk.style.functions.stops.CompositeStops; import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops; import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops; @@ -193,7 +192,7 @@ public class Function { @NonNull String property, @NonNull CategoricalStops, O> stops) { - return new CompositeFunction<>(property, new CompositeStops<>(stops)); + return new CompositeFunction<>(property, stops); } /** @@ -219,7 +218,7 @@ public class Function { @NonNull String property, @NonNull ExponentialStops, O> stops) { - return new CompositeFunction<>(property, new CompositeStops<>(stops)); + return new CompositeFunction<>(property, stops); } /** @@ -245,7 +244,7 @@ public class Function { @NonNull String property, @NonNull IntervalStops, O> stops) { - return new CompositeFunction<>(property, new CompositeStops<>(stops)); + return new CompositeFunction<>(property, stops); } // Class definition // @@ -257,7 +256,7 @@ public class Function { * * @param stops the stops */ - Function(@NonNull Stops stops) { + Function(@NonNull Stops stops) { this.stops = stops; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/CompositeStops.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/CompositeStops.java deleted file mode 100644 index 7e2ce94fe..000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/CompositeStops.java +++ /dev/null @@ -1,151 +0,0 @@ -package com.mapbox.mapboxsdk.style.functions.stops; - -import android.support.annotation.Keep; -import android.support.annotation.NonNull; -import android.support.annotation.Size; - -import com.mapbox.mapboxsdk.style.functions.stops.Stop.CompositeValue; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -/** - * The {@link Stops} implementation for composite functions - * - * @param the zoom type (usually Float) - * @param the input type (the feature property type) - * @param the output type (the property type) - * @param the {@link Stops} implementation (eg CategoricalStops, {@link ExponentialStops} or {@link IntervalStops}) - */ -public class CompositeStops>> - extends IterableStops, O, Map.Entry> { - - private final Map stops; - - /** - * JNI Constructor - * - * @param stops the stops {@link Map} - */ - @Keep - private CompositeStops(@NonNull @Size(min = 1) Map stops) { - this.stops = stops; - } - - /** - * Create composite stops for {@link ExponentialStops}. Use - * {@link com.mapbox.mapboxsdk.style.functions.Function#composite(String, ExponentialStops)} - * - * @param stops the stops - */ - public CompositeStops(@NonNull ExponentialStops, O> stops) { - this.stops = new HashMap<>(); - - for (Map.Entry>> entry : collect(stops).entrySet()) { - // noinspection unchecked - this.stops.put(entry.getKey(), - (S) new ExponentialStops<>(stops.getBase(), entry.getValue().toArray(new Stop[0]))); - } - } - - /** - * Create composite stops for {@link IntervalStops}. - * Use {@link com.mapbox.mapboxsdk.style.functions.Function#composite(String, IntervalStops)} - * - * @param stops the stops - */ - public CompositeStops(@NonNull IntervalStops, O> stops) { - this.stops = new HashMap<>(); - - for (Map.Entry>> entry : collect(stops).entrySet()) { - // noinspection unchecked - this.stops.put(entry.getKey(), (S) new IntervalStops<>(entry.getValue().toArray(new Stop[0]))); - } - } - - /** - * Create composite stops for {@link CategoricalStops}. - * Use {@link com.mapbox.mapboxsdk.style.functions.Function#composite(String, CategoricalStops)} - * - * @param stops the stops - */ - public CompositeStops(@NonNull CategoricalStops, O> stops) { - this.stops = new HashMap<>(); - - for (Map.Entry>> entry : collect(stops).entrySet()) { - // noinspection unchecked - this.stops.put(entry.getKey(), (S) new CategoricalStops<>(entry.getValue().toArray(new Stop[0]))); - } - } - - /** - * {@inheritDoc} - */ - @Override - protected String getTypeName() { - return stops.values().iterator().next().getTypeName(); - } - - /** - * {@inheritDoc} - */ - @Override - public Map toValueObject() { - Map map = super.toValueObject(); - - // Flatten and toValueObjects stops - // noinspection unchecked - map.put("stops", toValueObjects(flatten(this.stops).toArray(new Stop[0]))); - - return map; - } - - @NonNull - private List, O>> flatten(Map stops) { - List, O>> flattenedStops = new ArrayList<>(); - for (Map.Entry entry : stops.entrySet()) { - for (Stop stop : entry.getValue()) { - flattenedStops.add(new Stop<>(new CompositeValue<>(entry.getKey(), stop.in), stop.out)); - } - } - return flattenedStops; - } - - @NonNull - private Map>> collect( - @NonNull IterableStops, O, Stop, O>> stops) { - Map>> converted = new HashMap<>(); - - for (Stop, O> stop : stops) { - List> stopsForZ = converted.get(stop.in.zoom); - if (stopsForZ == null) { - stopsForZ = new ArrayList<>(); - converted.put(stop.in.zoom, stopsForZ); - } - - stopsForZ.add(new Stop<>(stop.in.value, stop.out)); - } - - return converted; - } - - /** - * {@inheritDoc} - */ - @Override - public Iterator> iterator() { - return stops.entrySet().iterator(); - } - - /** - * {@inheritDoc} - */ - @Override - public int size() { - return stops.size(); - } - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stop.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stop.java index 80825ccf6..72164f4c4 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stop.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stop.java @@ -52,8 +52,8 @@ public class Stop { * @param the feature property input type */ public static class CompositeValue { - Z zoom; - V value; + public final Z zoom; + public final V value; CompositeValue(Z zoom, V value) { this.zoom = zoom; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stops.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stops.java index a9d805508..af4f53c07 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stops.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stops.java @@ -1,5 +1,6 @@ package com.mapbox.mapboxsdk.style.functions.stops; +import android.support.annotation.CallSuper; import android.support.annotation.NonNull; import android.support.annotation.Size; @@ -77,6 +78,7 @@ public abstract class Stops { * * @return the value object representation for conversion to core */ + @CallSuper public Map toValueObject() { HashMap map = new HashMap<>(); map.put("type", getTypeName()); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java index 4637989dd..510f477bc 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java @@ -13,10 +13,10 @@ import com.mapbox.mapboxsdk.style.functions.CompositeFunction; import com.mapbox.mapboxsdk.style.functions.CameraFunction; import com.mapbox.mapboxsdk.style.functions.SourceFunction; import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops; -import com.mapbox.mapboxsdk.style.functions.stops.CompositeStops; import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops; import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops; +import com.mapbox.mapboxsdk.style.functions.stops.Stop; import com.mapbox.mapboxsdk.style.functions.stops.Stops; import com.mapbox.mapboxsdk.style.layers.BackgroundLayer; import com.mapbox.mapboxsdk.testapp.R; @@ -29,8 +29,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import java.util.Map; - import static com.mapbox.mapboxsdk.style.functions.Function.*; import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop; import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*; diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerTest.java index db64246f7..c48a6f1d6 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerTest.java @@ -13,10 +13,10 @@ import com.mapbox.mapboxsdk.style.functions.CompositeFunction; import com.mapbox.mapboxsdk.style.functions.CameraFunction; import com.mapbox.mapboxsdk.style.functions.SourceFunction; import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops; -import com.mapbox.mapboxsdk.style.functions.stops.CompositeStops; import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops; import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops; +import com.mapbox.mapboxsdk.style.functions.stops.Stop; import com.mapbox.mapboxsdk.style.functions.stops.Stops; import com.mapbox.mapboxsdk.style.layers.CircleLayer; import com.mapbox.mapboxsdk.testapp.R; @@ -29,8 +29,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import java.util.Map; - import static com.mapbox.mapboxsdk.style.functions.Function.*; import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop; import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*; @@ -215,17 +213,15 @@ public class CircleLayerTest extends BaseStyleTest { assertNotNull(layer.getCircleRadius().getFunction()); assertEquals(CompositeFunction.class, layer.getCircleRadius().getFunction().getClass()); assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getCircleRadius().getFunction()).getProperty()); - assertEquals(CompositeStops.class, layer.getCircleRadius().getFunction().getStops().getClass()); - assertEquals(1, ((CompositeStops) layer.getCircleRadius().getFunction().getStops()).size()); + assertEquals(ExponentialStops.class, layer.getCircleRadius().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getCircleRadius().getFunction().getStops()).size()); - CompositeStops> stops = - (CompositeStops>) layer.getCircleRadius().getFunction().getStops(); - Map.Entry> stop = stops.iterator().next(); - assertEquals(ExponentialStops.class, stop.getValue().getClass()); - assertEquals(0f, stop.getKey(), 0.001); - assertEquals(1, stop.getValue().size()); - assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); - assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + ExponentialStops, Float> stops = + (ExponentialStops, Float>) layer.getCircleRadius().getFunction().getStops(); + Stop, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); } @Test @@ -479,17 +475,15 @@ public class CircleLayerTest extends BaseStyleTest { assertNotNull(layer.getCircleBlur().getFunction()); assertEquals(CompositeFunction.class, layer.getCircleBlur().getFunction().getClass()); assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getCircleBlur().getFunction()).getProperty()); - assertEquals(CompositeStops.class, layer.getCircleBlur().getFunction().getStops().getClass()); - assertEquals(1, ((CompositeStops) layer.getCircleBlur().getFunction().getStops()).size()); + assertEquals(ExponentialStops.class, layer.getCircleBlur().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getCircleBlur().getFunction().getStops()).size()); - CompositeStops> stops = - (CompositeStops>) layer.getCircleBlur().getFunction().getStops(); - Map.Entry> stop = stops.iterator().next(); - assertEquals(ExponentialStops.class, stop.getValue().getClass()); - assertEquals(0f, stop.getKey(), 0.001); - assertEquals(1, stop.getValue().size()); - assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); - assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + ExponentialStops, Float> stops = + (ExponentialStops, Float>) layer.getCircleBlur().getFunction().getStops(); + Stop, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); } @Test @@ -624,17 +618,15 @@ public class CircleLayerTest extends BaseStyleTest { assertNotNull(layer.getCircleOpacity().getFunction()); assertEquals(CompositeFunction.class, layer.getCircleOpacity().getFunction().getClass()); assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getCircleOpacity().getFunction()).getProperty()); - assertEquals(CompositeStops.class, layer.getCircleOpacity().getFunction().getStops().getClass()); - assertEquals(1, ((CompositeStops) layer.getCircleOpacity().getFunction().getStops()).size()); + assertEquals(ExponentialStops.class, layer.getCircleOpacity().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getCircleOpacity().getFunction().getStops()).size()); - CompositeStops> stops = - (CompositeStops>) layer.getCircleOpacity().getFunction().getStops(); - Map.Entry> stop = stops.iterator().next(); - assertEquals(ExponentialStops.class, stop.getValue().getClass()); - assertEquals(0f, stop.getKey(), 0.001); - assertEquals(1, stop.getValue().size()); - assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); - assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + ExponentialStops, Float> stops = + (ExponentialStops, Float>) layer.getCircleOpacity().getFunction().getStops(); + Stop, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); } @Test @@ -878,17 +870,15 @@ public class CircleLayerTest extends BaseStyleTest { assertNotNull(layer.getCircleStrokeWidth().getFunction()); assertEquals(CompositeFunction.class, layer.getCircleStrokeWidth().getFunction().getClass()); assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getCircleStrokeWidth().getFunction()).getProperty()); - assertEquals(CompositeStops.class, layer.getCircleStrokeWidth().getFunction().getStops().getClass()); - assertEquals(1, ((CompositeStops) layer.getCircleStrokeWidth().getFunction().getStops()).size()); + assertEquals(ExponentialStops.class, layer.getCircleStrokeWidth().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getCircleStrokeWidth().getFunction().getStops()).size()); - CompositeStops> stops = - (CompositeStops>) layer.getCircleStrokeWidth().getFunction().getStops(); - Map.Entry> stop = stops.iterator().next(); - assertEquals(ExponentialStops.class, stop.getValue().getClass()); - assertEquals(0f, stop.getKey(), 0.001); - assertEquals(1, stop.getValue().size()); - assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); - assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + ExponentialStops, Float> stops = + (ExponentialStops, Float>) layer.getCircleStrokeWidth().getFunction().getStops(); + Stop, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); } @Test @@ -1142,17 +1132,15 @@ public class CircleLayerTest extends BaseStyleTest { assertNotNull(layer.getCircleStrokeOpacity().getFunction()); assertEquals(CompositeFunction.class, layer.getCircleStrokeOpacity().getFunction().getClass()); assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getCircleStrokeOpacity().getFunction()).getProperty()); - assertEquals(CompositeStops.class, layer.getCircleStrokeOpacity().getFunction().getStops().getClass()); - assertEquals(1, ((CompositeStops) layer.getCircleStrokeOpacity().getFunction().getStops()).size()); + assertEquals(ExponentialStops.class, layer.getCircleStrokeOpacity().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getCircleStrokeOpacity().getFunction().getStops()).size()); - CompositeStops> stops = - (CompositeStops>) layer.getCircleStrokeOpacity().getFunction().getStops(); - Map.Entry> stop = stops.iterator().next(); - assertEquals(ExponentialStops.class, stop.getValue().getClass()); - assertEquals(0f, stop.getKey(), 0.001); - assertEquals(1, stop.getValue().size()); - assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); - assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + ExponentialStops, Float> stops = + (ExponentialStops, Float>) layer.getCircleStrokeOpacity().getFunction().getStops(); + Stop, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerTest.java index 40a9ddec5..dd59b9752 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerTest.java @@ -13,10 +13,10 @@ import com.mapbox.mapboxsdk.style.functions.CompositeFunction; import com.mapbox.mapboxsdk.style.functions.CameraFunction; import com.mapbox.mapboxsdk.style.functions.SourceFunction; import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops; -import com.mapbox.mapboxsdk.style.functions.stops.CompositeStops; import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops; import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops; +import com.mapbox.mapboxsdk.style.functions.stops.Stop; import com.mapbox.mapboxsdk.style.functions.stops.Stops; import com.mapbox.mapboxsdk.style.layers.FillLayer; import com.mapbox.mapboxsdk.testapp.R; @@ -29,8 +29,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import java.util.Map; - import static com.mapbox.mapboxsdk.style.functions.Function.*; import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop; import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*; @@ -251,17 +249,15 @@ public class FillLayerTest extends BaseStyleTest { assertNotNull(layer.getFillOpacity().getFunction()); assertEquals(CompositeFunction.class, layer.getFillOpacity().getFunction().getClass()); assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getFillOpacity().getFunction()).getProperty()); - assertEquals(CompositeStops.class, layer.getFillOpacity().getFunction().getStops().getClass()); - assertEquals(1, ((CompositeStops) layer.getFillOpacity().getFunction().getStops()).size()); + assertEquals(ExponentialStops.class, layer.getFillOpacity().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getFillOpacity().getFunction().getStops()).size()); - CompositeStops> stops = - (CompositeStops>) layer.getFillOpacity().getFunction().getStops(); - Map.Entry> stop = stops.iterator().next(); - assertEquals(ExponentialStops.class, stop.getValue().getClass()); - assertEquals(0f, stop.getKey(), 0.001); - assertEquals(1, stop.getValue().size()); - assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); - assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + ExponentialStops, Float> stops = + (ExponentialStops, Float>) layer.getFillOpacity().getFunction().getStops(); + Stop, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); } @Test diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerTest.java index 7ac23daa6..740393ad3 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerTest.java @@ -13,10 +13,10 @@ import com.mapbox.mapboxsdk.style.functions.CompositeFunction; import com.mapbox.mapboxsdk.style.functions.CameraFunction; import com.mapbox.mapboxsdk.style.functions.SourceFunction; import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops; -import com.mapbox.mapboxsdk.style.functions.stops.CompositeStops; import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops; import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops; +import com.mapbox.mapboxsdk.style.functions.stops.Stop; import com.mapbox.mapboxsdk.style.functions.stops.Stops; import com.mapbox.mapboxsdk.style.layers.LineLayer; import com.mapbox.mapboxsdk.testapp.R; @@ -29,8 +29,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import java.util.Map; - import static com.mapbox.mapboxsdk.style.functions.Function.*; import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop; import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*; @@ -361,17 +359,15 @@ public class LineLayerTest extends BaseStyleTest { assertNotNull(layer.getLineOpacity().getFunction()); assertEquals(CompositeFunction.class, layer.getLineOpacity().getFunction().getClass()); assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getLineOpacity().getFunction()).getProperty()); - assertEquals(CompositeStops.class, layer.getLineOpacity().getFunction().getStops().getClass()); - assertEquals(1, ((CompositeStops) layer.getLineOpacity().getFunction().getStops()).size()); + assertEquals(ExponentialStops.class, layer.getLineOpacity().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getLineOpacity().getFunction().getStops()).size()); - CompositeStops> stops = - (CompositeStops>) layer.getLineOpacity().getFunction().getStops(); - Map.Entry> stop = stops.iterator().next(); - assertEquals(ExponentialStops.class, stop.getValue().getClass()); - assertEquals(0f, stop.getKey(), 0.001); - assertEquals(1, stop.getValue().size()); - assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); - assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + ExponentialStops, Float> stops = + (ExponentialStops, Float>) layer.getLineOpacity().getFunction().getStops(); + Stop, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); } @Test @@ -735,17 +731,15 @@ public class LineLayerTest extends BaseStyleTest { assertNotNull(layer.getLineGapWidth().getFunction()); assertEquals(CompositeFunction.class, layer.getLineGapWidth().getFunction().getClass()); assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getLineGapWidth().getFunction()).getProperty()); - assertEquals(CompositeStops.class, layer.getLineGapWidth().getFunction().getStops().getClass()); - assertEquals(1, ((CompositeStops) layer.getLineGapWidth().getFunction().getStops()).size()); + assertEquals(ExponentialStops.class, layer.getLineGapWidth().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getLineGapWidth().getFunction().getStops()).size()); - CompositeStops> stops = - (CompositeStops>) layer.getLineGapWidth().getFunction().getStops(); - Map.Entry> stop = stops.iterator().next(); - assertEquals(ExponentialStops.class, stop.getValue().getClass()); - assertEquals(0f, stop.getKey(), 0.001); - assertEquals(1, stop.getValue().size()); - assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); - assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + ExponentialStops, Float> stops = + (ExponentialStops, Float>) layer.getLineGapWidth().getFunction().getStops(); + Stop, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); } @Test @@ -880,17 +874,15 @@ public class LineLayerTest extends BaseStyleTest { assertNotNull(layer.getLineOffset().getFunction()); assertEquals(CompositeFunction.class, layer.getLineOffset().getFunction().getClass()); assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getLineOffset().getFunction()).getProperty()); - assertEquals(CompositeStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(1, ((CompositeStops) layer.getLineOffset().getFunction().getStops()).size()); + assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); - CompositeStops> stops = - (CompositeStops>) layer.getLineOffset().getFunction().getStops(); - Map.Entry> stop = stops.iterator().next(); - assertEquals(ExponentialStops.class, stop.getValue().getClass()); - assertEquals(0f, stop.getKey(), 0.001); - assertEquals(1, stop.getValue().size()); - assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); - assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + ExponentialStops, Float> stops = + (ExponentialStops, Float>) layer.getLineOffset().getFunction().getStops(); + Stop, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); } @Test @@ -1025,17 +1017,15 @@ public class LineLayerTest extends BaseStyleTest { assertNotNull(layer.getLineBlur().getFunction()); assertEquals(CompositeFunction.class, layer.getLineBlur().getFunction().getClass()); assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getLineBlur().getFunction()).getProperty()); - assertEquals(CompositeStops.class, layer.getLineBlur().getFunction().getStops().getClass()); - assertEquals(1, ((CompositeStops) layer.getLineBlur().getFunction().getStops()).size()); + assertEquals(ExponentialStops.class, layer.getLineBlur().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getLineBlur().getFunction().getStops()).size()); - CompositeStops> stops = - (CompositeStops>) layer.getLineBlur().getFunction().getStops(); - Map.Entry> stop = stops.iterator().next(); - assertEquals(ExponentialStops.class, stop.getValue().getClass()); - assertEquals(0f, stop.getKey(), 0.001); - assertEquals(1, stop.getValue().size()); - assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); - assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + ExponentialStops, Float> stops = + (ExponentialStops, Float>) layer.getLineBlur().getFunction().getStops(); + Stop, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); } @Test diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerTest.java index cc9597ab7..eb2155f54 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerTest.java @@ -13,10 +13,10 @@ import com.mapbox.mapboxsdk.style.functions.CompositeFunction; import com.mapbox.mapboxsdk.style.functions.CameraFunction; import com.mapbox.mapboxsdk.style.functions.SourceFunction; import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops; -import com.mapbox.mapboxsdk.style.functions.stops.CompositeStops; import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops; import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops; +import com.mapbox.mapboxsdk.style.functions.stops.Stop; import com.mapbox.mapboxsdk.style.functions.stops.Stops; import com.mapbox.mapboxsdk.style.layers.RasterLayer; import com.mapbox.mapboxsdk.testapp.R; @@ -29,8 +29,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import java.util.Map; - import static com.mapbox.mapboxsdk.style.functions.Function.*; import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop; import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*; diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java index 63bfaa8c8..b4af1a1b1 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java @@ -13,10 +13,10 @@ import com.mapbox.mapboxsdk.style.functions.CompositeFunction; import com.mapbox.mapboxsdk.style.functions.CameraFunction; import com.mapbox.mapboxsdk.style.functions.SourceFunction; import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops; -import com.mapbox.mapboxsdk.style.functions.stops.CompositeStops; import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops; import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops; +import com.mapbox.mapboxsdk.style.functions.stops.Stop; import com.mapbox.mapboxsdk.style.functions.stops.Stops; import com.mapbox.mapboxsdk.style.layers.SymbolLayer; import com.mapbox.mapboxsdk.testapp.R; @@ -29,8 +29,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import java.util.Map; - import static com.mapbox.mapboxsdk.style.functions.Function.*; import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop; import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*; @@ -614,17 +612,15 @@ public class SymbolLayerTest extends BaseStyleTest { assertNotNull(layer.getIconRotate().getFunction()); assertEquals(CompositeFunction.class, layer.getIconRotate().getFunction().getClass()); assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getIconRotate().getFunction()).getProperty()); - assertEquals(CompositeStops.class, layer.getIconRotate().getFunction().getStops().getClass()); - assertEquals(1, ((CompositeStops) layer.getIconRotate().getFunction().getStops()).size()); + assertEquals(ExponentialStops.class, layer.getIconRotate().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getIconRotate().getFunction().getStops()).size()); - CompositeStops> stops = - (CompositeStops>) layer.getIconRotate().getFunction().getStops(); - Map.Entry> stop = stops.iterator().next(); - assertEquals(ExponentialStops.class, stop.getValue().getClass()); - assertEquals(0f, stop.getKey(), 0.001); - assertEquals(1, stop.getValue().size()); - assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); - assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + ExponentialStops, Float> stops = + (ExponentialStops, Float>) layer.getIconRotate().getFunction().getStops(); + Stop, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); } @Test diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs index 03499be39..4d2aec9dd 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs @@ -17,10 +17,10 @@ import com.mapbox.mapboxsdk.style.functions.CompositeFunction; import com.mapbox.mapboxsdk.style.functions.CameraFunction; import com.mapbox.mapboxsdk.style.functions.SourceFunction; import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops; -import com.mapbox.mapboxsdk.style.functions.stops.CompositeStops; import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops; import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops; +import com.mapbox.mapboxsdk.style.functions.stops.Stop; import com.mapbox.mapboxsdk.style.functions.stops.Stops; import com.mapbox.mapboxsdk.style.layers.<%- camelize(type) %>Layer; import com.mapbox.mapboxsdk.testapp.R; @@ -33,8 +33,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import java.util.Map; - import static com.mapbox.mapboxsdk.style.functions.Function.*; import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop; import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*; @@ -319,17 +317,15 @@ public class <%- camelize(type) %>LayerTest extends BaseStyleTest { assertNotNull(layer.get<%- camelize(property.name) %>().getFunction()); assertEquals(CompositeFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass()); assertEquals("FeaturePropertyA", ((CompositeFunction) layer.get<%- camelize(property.name) %>().getFunction()).getProperty()); - assertEquals(CompositeStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass()); - assertEquals(1, ((CompositeStops) layer.get<%- camelize(property.name) %>().getFunction().getStops()).size()); + assertEquals(ExponentialStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.get<%- camelize(property.name) %>().getFunction().getStops()).size()); - CompositeStops, <%- propertyType(property) %>, ExponentialStops<<%- propertyType(property) %>, <%- propertyType(property) %>>> stops = - (CompositeStops, <%- propertyType(property) %>, ExponentialStops<<%- propertyType(property) %>, <%- propertyType(property) %>>>) layer.get<%- camelize(property.name) %>().getFunction().getStops(); - Map.Entry, <%- propertyType(property) %>>> stop = stops.iterator().next(); - assertEquals(ExponentialStops.class, stop.getValue().getClass()); - assertEquals(0f, stop.getKey(), 0.001); - assertEquals(1, stop.getValue().size()); - assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); - assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + ExponentialStops>, <%- propertyType(property) %>> stops = + (ExponentialStops>, <%- propertyType(property) %>>) layer.get<%- camelize(property.name) %>().getFunction().getStops(); + Stop>, <%- propertyType(property) %>> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); } <% } -%> <% } -%> diff --git a/platform/android/config.cmake b/platform/android/config.cmake index cfd6a3cdb..9491071f2 100644 --- a/platform/android/config.cmake +++ b/platform/android/config.cmake @@ -118,6 +118,16 @@ macro(mbgl_platform_core) platform/android/src/style/sources/raster_source.hpp platform/android/src/style/sources/vector_source.cpp platform/android/src/style/sources/vector_source.hpp + platform/android/src/style/functions/stop.cpp + platform/android/src/style/functions/stop.hpp + platform/android/src/style/functions/categorical_stops.cpp + platform/android/src/style/functions/categorical_stops.hpp + platform/android/src/style/functions/exponential_stops.cpp + platform/android/src/style/functions/exponential_stops.hpp + platform/android/src/style/functions/identity_stops.cpp + platform/android/src/style/functions/identity_stops.hpp + platform/android/src/style/functions/interval_stops.cpp + platform/android/src/style/functions/interval_stops.hpp # Connectivity platform/android/src/connectivity_listener.cpp diff --git a/platform/android/src/java/lang.hpp b/platform/android/src/java/lang.hpp new file mode 100644 index 000000000..dcf81a9d0 --- /dev/null +++ b/platform/android/src/java/lang.hpp @@ -0,0 +1,21 @@ +#pragma once + +namespace mbgl { +namespace android { +namespace java { +namespace lang { + +class Float { +public: + static constexpr auto Name() { return "java/lang/Float"; }; +}; + +class Number { +public: + static constexpr auto Name() { return "java/lang/Number"; }; +}; + +} // namespace lang +} // namespace java +} // namespace android +} // namespace mbgl diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp index 31fe2394f..b6113e1d3 100755 --- a/platform/android/src/jni.cpp +++ b/platform/android/src/jni.cpp @@ -14,6 +14,11 @@ #include "bitmap.hpp" #include "bitmap_factory.hpp" #include "connectivity_listener.hpp" +#include "style/functions/categorical_stops.hpp" +#include "style/functions/exponential_stops.hpp" +#include "style/functions/identity_stops.hpp" +#include "style/functions/interval_stops.hpp" +#include "style/functions/stop.hpp" #include "style/layers/layers.hpp" #include "style/sources/sources.hpp" @@ -1780,6 +1785,11 @@ void registerNatives(JavaVM *vm) { BitmapFactory::registerNative(env); registerNativeLayers(env); registerNativeSources(env); + Stop::registerNative(env); + CategoricalStops::registerNative(env); + ExponentialStops::registerNative(env); + IdentityStops::registerNative(env); + IntervalStops::registerNative(env); ConnectivityListener::registerNative(env); latLngClass = &jni::FindClass(env, "com/mapbox/mapboxsdk/geometry/LatLng"); diff --git a/platform/android/src/style/conversion/function.hpp b/platform/android/src/style/conversion/function.hpp index 104530cfe..ad01a7afc 100644 --- a/platform/android/src/style/conversion/function.hpp +++ b/platform/android/src/style/conversion/function.hpp @@ -4,6 +4,12 @@ #include "../../conversion/conversion.hpp" #include "../../conversion/constant.hpp" #include "types.hpp" +#include "../../java/lang.hpp" +#include "../functions/stop.hpp" +#include "../functions/categorical_stops.hpp" +#include "../functions/exponential_stops.hpp" +#include "../functions/identity_stops.hpp" +#include "../functions/interval_stops.hpp" #include @@ -44,7 +50,59 @@ struct Converter { }; template -inline jni::jobject* toFunctionStopJavaArray(jni::JNIEnv& env, std::map value) { +jni::Array> toFunctionStopJavaArray(jni::JNIEnv& env, std::map value) { + + auto jarray = jni::Array>::New(env, value.size(), Stop::javaClass); + + size_t i = 0; + for (auto const& stop : value) { + jni::jobject* in = *convert(env, stop.first); + jni::jobject* out = *convert(env, stop.second); + + auto jstop = Stop::New(env, jni::Object<>(in), jni::Object<>(out)); + jarray.Set(env, i, jstop); + + jni::DeleteLocalRef(env, in); + jni::DeleteLocalRef(env, out); + jni::DeleteLocalRef(env, jstop); + + i++; + } + + return jarray; +} + +template +jni::Array> toFunctionStopJavaArray(jni::JNIEnv& env, std::map> value) { + + auto jarray = jni::Array>::New(env, value.size(), Stop::javaClass); + + for (auto const& zoomLevelMap : value) { + size_t i = 0; + for (auto const& stop: zoomLevelMap.second) { + auto zoom = jni::Object(*convert(env, zoomLevelMap.first)); + auto in = jni::Object<>(*convert(env, stop.first)); + auto out = jni::Object<>(*convert(env, stop.second)); + auto compositeValue = Stop::CompositeValue::New(env, zoom, in); + + auto jstop = Stop::New(env, compositeValue, out); + jarray.Set(env, i, jstop); + + jni::DeleteLocalRef(env, zoom); + jni::DeleteLocalRef(env, in); + jni::DeleteLocalRef(env, out); + jni::DeleteLocalRef(env, compositeValue); + jni::DeleteLocalRef(env, jstop); + + i++; + } + } + + return jarray; +} + +template +inline jni::jobject* convertCompositeStopsArray(jni::JNIEnv& env, std::map> value) { static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/functions/stops/Stop")).release(); static jni::jmethodID* constructor = &jni::GetMethodID(env, *javaClass, "", "(Ljava/lang/Object;Ljava/lang/Object;)V"); @@ -73,85 +131,31 @@ public: StopsEvaluator(jni::JNIEnv& _env) : env(_env) {} jni::jobject* operator()(const mbgl::style::CategoricalStops &value) const { - static jni::jclass* clazz = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/functions/stops/CategoricalStops")).release(); - static jni::jmethodID* constructor = &jni::GetMethodID(env, *clazz, "", "([Lcom/mapbox/mapboxsdk/style/functions/stops/Stop;)V"); + return CategoricalStops::New(env, toFunctionStopJavaArray(env, value.stops)).Get(); + } - return &jni::NewObject(env, *clazz, *constructor, toFunctionStopJavaArray(env, value.stops)); + jni::jobject* operator()(const mbgl::style::CompositeCategoricalStops &value) const { + return CategoricalStops::New(env, toFunctionStopJavaArray(env, value.stops)).Get(); } jni::jobject* operator()(const mbgl::style::ExponentialStops &value) const { - static jni::jclass* clazz = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/functions/stops/ExponentialStops")).release(); - static jni::jmethodID* constructor = &jni::GetMethodID(env, *clazz, "", "(Ljava/lang/Float;[Lcom/mapbox/mapboxsdk/style/functions/stops/Stop;)V"); + return ExponentialStops::New(env, jni::Object(*convert(env, value.base)), toFunctionStopJavaArray(env, value.stops)).Get(); + } - return &jni::NewObject(env, *clazz, *constructor, - *convert(env, value.base), - toFunctionStopJavaArray(env, value.stops)); + jni::jobject* operator()(const mbgl::style::CompositeExponentialStops &value) const { + return ExponentialStops::New(env, jni::Object(*convert(env, value.base)), toFunctionStopJavaArray(env, value.stops)).Get(); } jni::jobject* operator()(const mbgl::style::IdentityStops &) const { - static jni::jclass* clazz = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/functions/stops/IdentityStops")).release(); - static jni::jmethodID* constructor = &jni::GetMethodID(env, *clazz, "", "()V"); - - return &jni::NewObject(env, *clazz, *constructor); + return IdentityStops::New(env).Get(); } jni::jobject* operator()(const mbgl::style::IntervalStops &value) const { - static jni::jclass* clazz = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/functions/stops/IntervalStops")).release(); - static jni::jmethodID* constructor = &jni::GetMethodID(env, *clazz, "", "([Lcom/mapbox/mapboxsdk/style/functions/stops/Stop;)V"); - - return &jni::NewObject(env, *clazz, *constructor, toFunctionStopJavaArray(env, value.stops)); + return IntervalStops::New(env, toFunctionStopJavaArray(env, value.stops)).Get(); } -private: - jni::JNIEnv& env; -}; - -template -inline jni::jobject* convertCompositeStopsArray(jni::JNIEnv& env, std::map value) { - // Create Java Map - static jni::jclass* mapClass = jni::NewGlobalRef(env, &jni::FindClass(env, "java/util/HashMap")).release(); - static jni::jmethodID* mapConstructor = &jni::GetMethodID(env, *mapClass, "", "()V"); - static jni::jmethodID* mapPutMethod = &jni::GetMethodID(env, *mapClass, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); - jni::jobject& map = jni::NewObject(env, *mapClass, *mapConstructor); - - // Add converted Stops for each zoom value - StopsEvaluator evaluator(env); - for (auto const& entry : value) { - jni::jobject* zoom = *convert(env, entry.first); - jni::jobject* stops = evaluator(entry.second); - jni::CallMethod(env, &map, *mapPutMethod, zoom, stops); - jni::DeleteLocalRef(env, zoom); - jni::DeleteLocalRef(env, stops); - } - - // Create CompositeStops from Java Map - static jni::jclass* compositeStopsClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/functions/stops/CompositeStops")).release(); - static jni::jmethodID* compositeStopsConstructor = &jni::GetMethodID(env, *compositeStopsClass, "", "(Ljava/util/Map;)V"); - jni::jobject& compositeStops = jni::NewObject(env, *compositeStopsClass, *compositeStopsConstructor, &map); - jni::DeleteLocalRef(env, &map); - - return &compositeStops; -} - -/** - * Conversion from core composite function stops to CompositeFunctionStops java type - */ -template -class CompositeStopsEvaluator { -public: - - CompositeStopsEvaluator(jni::JNIEnv& _env) : env(_env) {} - - jni::jobject* operator()(const std::map> &value) const { - return convertCompositeStopsArray, T>(env, value); - } - - jni::jobject* operator()(const std::map> &value) const { - return convertCompositeStopsArray, T>(env, value); - } - - jni::jobject* operator()(const std::map> &value) const { - return convertCompositeStopsArray, T>(env, value); + jni::jobject* operator()(const mbgl::style::CompositeIntervalStops &value) const { + return IntervalStops::New(env, toFunctionStopJavaArray(env, value.stops)).Get(); } private: @@ -201,10 +205,10 @@ struct Converter> { Result operator()(jni::JNIEnv& env, const mbgl::style::CompositeFunction& value) const { static jni::jclass* clazz = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/functions/CompositeFunction")).release(); static jni::jmethodID* constructor = &jni::GetMethodID(env, *clazz, "", - "(Ljava/lang/Object;Ljava/lang/String;Lcom/mapbox/mapboxsdk/style/functions/stops/CompositeStops;)V"); + "(Ljava/lang/Object;Ljava/lang/String;Lcom/mapbox/mapboxsdk/style/functions/stops/Stops;)V"); // Convert stops - CompositeStopsEvaluator evaluator(env); + StopsEvaluator evaluator(env); jni::jobject* stops = apply_visitor(evaluator, value.stops); diff --git a/platform/android/src/style/functions/categorical_stops.cpp b/platform/android/src/style/functions/categorical_stops.cpp new file mode 100644 index 000000000..2aff9730a --- /dev/null +++ b/platform/android/src/style/functions/categorical_stops.cpp @@ -0,0 +1,18 @@ +#include "categorical_stops.hpp" + +namespace mbgl { +namespace android { + +jni::Object CategoricalStops::New(jni::JNIEnv& env, jni::Array> stops) { + static auto constructor = CategoricalStops::javaClass.GetConstructor>>(env); + return CategoricalStops::javaClass.New(env, constructor, stops); +} + +jni::Class CategoricalStops::javaClass; + +void CategoricalStops::registerNative(jni::JNIEnv& env) { + CategoricalStops::javaClass = *jni::Class::Find(env).NewGlobalRef(env).release(); +} + +} // namespace android +} // namespace mbgl diff --git a/platform/android/src/style/functions/categorical_stops.hpp b/platform/android/src/style/functions/categorical_stops.hpp new file mode 100644 index 000000000..a198c8d5c --- /dev/null +++ b/platform/android/src/style/functions/categorical_stops.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include +#include + +#include "stop.hpp" + +namespace mbgl { +namespace android { + +class CategoricalStops : private mbgl::util::noncopyable { +public: + static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/functions/stops/CategoricalStops"; }; + + static jni::Object New(jni::JNIEnv&, jni::Array>); + + static jni::Class javaClass; + + static void registerNative(jni::JNIEnv&); +}; + +} // namespace android +} // namespace mbgl diff --git a/platform/android/src/style/functions/exponential_stops.cpp b/platform/android/src/style/functions/exponential_stops.cpp new file mode 100644 index 000000000..6390a0ec3 --- /dev/null +++ b/platform/android/src/style/functions/exponential_stops.cpp @@ -0,0 +1,18 @@ +#include "exponential_stops.hpp" + +namespace mbgl { +namespace android { + +jni::Object ExponentialStops::New(jni::JNIEnv& env, jni::Object base, jni::Array> stops) { + static auto constructor = ExponentialStops::javaClass.GetConstructor, jni::Array>>(env); + return ExponentialStops::javaClass.New(env, constructor, base, stops); +} + +jni::Class ExponentialStops::javaClass; + +void ExponentialStops::registerNative(jni::JNIEnv& env) { + ExponentialStops::javaClass = *jni::Class::Find(env).NewGlobalRef(env).release(); +} + +} // namespace android +} // namespace mbgl diff --git a/platform/android/src/style/functions/exponential_stops.hpp b/platform/android/src/style/functions/exponential_stops.hpp new file mode 100644 index 000000000..391d723ce --- /dev/null +++ b/platform/android/src/style/functions/exponential_stops.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include +#include + +#include "../../java/lang.hpp" +#include "stop.hpp" + +namespace mbgl { +namespace android { + +class ExponentialStops : private mbgl::util::noncopyable { +public: + static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/functions/stops/ExponentialStops"; }; + + static jni::Object New(jni::JNIEnv&, jni::Object, jni::Array>); + + static jni::Class javaClass; + + static void registerNative(jni::JNIEnv&); +}; + +} // namespace android +} // namespace mbgl diff --git a/platform/android/src/style/functions/identity_stops.cpp b/platform/android/src/style/functions/identity_stops.cpp new file mode 100644 index 000000000..239b0ddb8 --- /dev/null +++ b/platform/android/src/style/functions/identity_stops.cpp @@ -0,0 +1,18 @@ +#include "identity_stops.hpp" + +namespace mbgl { +namespace android { + +jni::Object IdentityStops::New(jni::JNIEnv& env) { + static auto constructor = IdentityStops::javaClass.GetConstructor<>(env); + return IdentityStops::javaClass.New(env, constructor); +} + +jni::Class IdentityStops::javaClass; + +void IdentityStops::registerNative(jni::JNIEnv& env) { + IdentityStops::javaClass = *jni::Class::Find(env).NewGlobalRef(env).release(); +} + +} // namespace android +} // namespace mbgl diff --git a/platform/android/src/style/functions/identity_stops.hpp b/platform/android/src/style/functions/identity_stops.hpp new file mode 100644 index 000000000..150b2135f --- /dev/null +++ b/platform/android/src/style/functions/identity_stops.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include +#include + +namespace mbgl { +namespace android { + +class IdentityStops : private mbgl::util::noncopyable { +public: + static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/functions/stops/IdentityStops"; }; + + static jni::Object New(jni::JNIEnv&); + + static jni::Class javaClass; + + static void registerNative(jni::JNIEnv&); +}; + +} // namespace android +} // namespace mbgl diff --git a/platform/android/src/style/functions/interval_stops.cpp b/platform/android/src/style/functions/interval_stops.cpp new file mode 100644 index 000000000..c3d9b6513 --- /dev/null +++ b/platform/android/src/style/functions/interval_stops.cpp @@ -0,0 +1,18 @@ +#include "interval_stops.hpp" + +namespace mbgl { +namespace android { + +jni::Object IntervalStops::New(jni::JNIEnv& env, jni::Array> stops) { + static auto constructor = IntervalStops::javaClass.GetConstructor>>(env); + return IntervalStops::javaClass.New(env, constructor, stops); +} + +jni::Class IntervalStops::javaClass; + +void IntervalStops::registerNative(jni::JNIEnv& env) { + IntervalStops::javaClass = *jni::Class::Find(env).NewGlobalRef(env).release(); +} + +} // namespace android +} // namespace mbgl diff --git a/platform/android/src/style/functions/interval_stops.hpp b/platform/android/src/style/functions/interval_stops.hpp new file mode 100644 index 000000000..e3f75159c --- /dev/null +++ b/platform/android/src/style/functions/interval_stops.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include +#include + +#include "stop.hpp" + +namespace mbgl { +namespace android { + +class IntervalStops : private mbgl::util::noncopyable { +public: + static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/functions/stops/IntervalStops"; }; + + static jni::Object New(jni::JNIEnv&, jni::Array>); + + static jni::Class javaClass; + + static void registerNative(jni::JNIEnv&); +}; + +} // namespace android +} // namespace mbgl diff --git a/platform/android/src/style/functions/stop.cpp b/platform/android/src/style/functions/stop.cpp new file mode 100644 index 000000000..f9ed4b736 --- /dev/null +++ b/platform/android/src/style/functions/stop.cpp @@ -0,0 +1,21 @@ +#include "interval_stops.hpp" + +namespace mbgl { +namespace android { + +jni::Object Stop::CompositeValue::New(jni::JNIEnv& env, jni::Object zoom, jni::Object<> value) { + static auto constructor = Stop::CompositeValue::javaClass.GetConstructor, jni::Object<>>(env); + return Stop::CompositeValue::javaClass.New(env, constructor, zoom, value); +} + +jni::Class Stop::javaClass; + +jni::Class Stop::CompositeValue::javaClass; + +void Stop::registerNative(jni::JNIEnv& env) { + Stop::javaClass = *jni::Class::Find(env).NewGlobalRef(env).release(); + Stop::CompositeValue::javaClass = *jni::Class::Find(env).NewGlobalRef(env).release(); +} + +} // namespace android +} // namespace mbgl diff --git a/platform/android/src/style/functions/stop.hpp b/platform/android/src/style/functions/stop.hpp new file mode 100644 index 000000000..7c697db65 --- /dev/null +++ b/platform/android/src/style/functions/stop.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include +#include + +#include "../../java/lang.hpp" + +namespace mbgl { +namespace android { + +class Stop : private mbgl::util::noncopyable { +public: + static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/functions/stops/Stop"; }; + + template + static jni::Object New(jni::JNIEnv& env, jni::Object in, jni::Object out) { + static auto constructor = Stop::javaClass.GetConstructor, jni::Object<>>(env); + return Stop::javaClass.New(env, constructor, (jni::Object<>) in, (jni::Object<>) out); + } + + static jni::Class javaClass; + + static void registerNative(jni::JNIEnv&); + + class CompositeValue : private mbgl::util::noncopyable { + public: + static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/functions/stops/Stop$CompositeValue"; }; + + static jni::Object New(jni::JNIEnv&, jni::Object, jni::Object<>); + + static jni::Class javaClass; + }; +}; + +} // namespace android +} // namespace mbgl