summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortobrun <tobrun.van.nuland@gmail.com>2018-05-29 13:10:16 +0200
committerTobrun <tobrun@mapbox.com>2018-05-29 15:53:38 +0200
commit83ebd5f6ff56fddd4a2923f6c082977476cddd99 (patch)
treeb56ab08a2490f100efc91ebae8d97c987dd0f775
parent2e2d5bf03c23b2ece3d977532c589275681973be (diff)
downloadqtlocation-mapboxgl-83ebd5f6ff56fddd4a2923f6c082977476cddd99.tar.gz
[android] - fix literal wrapping in comparission expressions
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java29
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java44
2 files changed, 57 insertions, 16 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java
index c8f848f4d7..eb9150ecbc 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java
@@ -4,7 +4,6 @@ import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.Size;
-
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
@@ -180,6 +179,8 @@ public class Expression {
public static Expression literal(@NonNull Object object) {
if (object.getClass().isArray()) {
return literal(ExpressionArray.toObjectArray(object));
+ } else if (object instanceof Expression) {
+ throw new RuntimeException("Can't convert an expression to a literal");
}
return new ExpressionLiteral(object);
}
@@ -426,7 +427,7 @@ public class Expression {
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-==">Style specification</a>
*/
public static Expression eq(@NonNull Expression compareOne, @NonNull String compareTwo) {
- return eq(literal(compareOne), literal(compareTwo));
+ return eq(compareOne, literal(compareTwo));
}
/**
@@ -449,7 +450,7 @@ public class Expression {
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-==">Style specification</a>
*/
public static Expression eq(@NonNull Expression compareOne, @NonNull Number compareTwo) {
- return eq(literal(compareOne), literal(compareTwo));
+ return eq(compareOne, literal(compareTwo));
}
/**
@@ -496,7 +497,7 @@ public class Expression {
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-!=">Style specification</a>
*/
public static Expression neq(Expression compareOne, boolean compareTwo) {
- return new Expression("!=", literal(compareOne), literal(compareTwo));
+ return new Expression("!=", compareOne, literal(compareTwo));
}
/**
@@ -519,7 +520,7 @@ public class Expression {
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-!=">Style specification</a>
*/
public static Expression neq(@NonNull Expression compareOne, @NonNull String compareTwo) {
- return new Expression("!=", literal(compareOne), literal(compareTwo));
+ return new Expression("!=", compareOne, literal(compareTwo));
}
/**
@@ -542,7 +543,7 @@ public class Expression {
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-!=">Style specification</a>
*/
public static Expression neq(@NonNull Expression compareOne, @NonNull Number compareTwo) {
- return new Expression("!=", literal(compareOne), literal(compareTwo));
+ return new Expression("!=", compareOne, literal(compareTwo));
}
/**
@@ -589,7 +590,7 @@ public class Expression {
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3E">Style specification</a>
*/
public static Expression gt(@NonNull Expression compareOne, @NonNull Number compareTwo) {
- return new Expression(">", literal(compareOne), literal(compareTwo));
+ return new Expression(">", compareOne, literal(compareTwo));
}
/**
@@ -612,7 +613,7 @@ public class Expression {
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3E">Style specification</a>
*/
public static Expression gt(@NonNull Expression compareOne, @NonNull String compareTwo) {
- return new Expression(">", literal(compareOne), literal(compareTwo));
+ return new Expression(">", compareOne, literal(compareTwo));
}
/**
@@ -659,7 +660,7 @@ public class Expression {
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3C">Style specification</a>
*/
public static Expression lt(@NonNull Expression compareOne, @NonNull Number compareTwo) {
- return new Expression("<", literal(compareOne), literal(compareTwo));
+ return new Expression("<", compareOne, literal(compareTwo));
}
/**
@@ -682,7 +683,7 @@ public class Expression {
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3C">Style specification</a>
*/
public static Expression lt(@NonNull Expression compareOne, @NonNull String compareTwo) {
- return new Expression("<", literal(compareOne), literal(compareTwo));
+ return new Expression("<", compareOne, literal(compareTwo));
}
/**
@@ -729,7 +730,7 @@ public class Expression {
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3E%3D">Style specification</a>
*/
public static Expression gte(@NonNull Expression compareOne, @NonNull Number compareTwo) {
- return new Expression(">=", literal(compareOne), literal(compareTwo));
+ return new Expression(">=", compareOne, literal(compareTwo));
}
/**
@@ -752,7 +753,7 @@ public class Expression {
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3E%3D">Style specification</a>
*/
public static Expression gte(@NonNull Expression compareOne, @NonNull String compareTwo) {
- return new Expression(">=", literal(compareOne), literal(compareTwo));
+ return new Expression(">=", compareOne, literal(compareTwo));
}
/**
@@ -799,7 +800,7 @@ public class Expression {
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3C%3D">Style specification</a>
*/
public static Expression lte(@NonNull Expression compareOne, @NonNull Number compareTwo) {
- return new Expression("<=", literal(compareOne), literal(compareTwo));
+ return new Expression("<=", compareOne, literal(compareTwo));
}
/**
@@ -822,7 +823,7 @@ public class Expression {
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3C%3D">Style specification</a>
*/
public static Expression lte(@NonNull Expression compareOne, @NonNull String compareTwo) {
- return new Expression("<=", literal(compareOne), literal(compareTwo));
+ return new Expression("<=", compareOne, literal(compareTwo));
}
/**
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java
index f87fd31172..1070a25f55 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java
@@ -1,9 +1,7 @@
package com.mapbox.mapboxsdk.style.expressions;
import android.graphics.Color;
-
import com.mapbox.mapboxsdk.style.layers.PropertyFactory;
-
import org.junit.Test;
import java.util.Arrays;
@@ -139,6 +137,13 @@ public class ExpressionTest {
}
@Test
+ public void testEqExpression() throws Exception {
+ Object[] expected = new Object[] {"==",new Object[]{"get", "hello"}, 1f};
+ Object[] actual = eq(get("hello"), 1).toArray();
+ assertTrue("expression should match", Arrays.deepEquals(expected, actual));
+ }
+
+ @Test
public void testNeq() throws Exception {
Object[] expected = new Object[] {"!=", 0f, 1f};
Object[] actual = neq(literal(0), literal(1)).toArray();
@@ -153,6 +158,13 @@ public class ExpressionTest {
}
@Test
+ public void testNeqExpression() throws Exception {
+ Object[] expected = new Object[] {"!=",new Object[]{"get", "hello"}, 1f};
+ Object[] actual = neq(get("hello"), 1).toArray();
+ assertTrue("expression should match", Arrays.deepEquals(expected, actual));
+ }
+
+ @Test
public void testGt() throws Exception {
Object[] expected = new Object[] {">", 0f, 1f};
Object[] actual = gt(literal(0), literal(1)).toArray();
@@ -167,6 +179,13 @@ public class ExpressionTest {
}
@Test
+ public void testGtExpression() throws Exception {
+ Object[] expected = new Object[] {">", new Object[] {"get", "hello"}, 1f};
+ Object[] actual = gt(get("hello"), 1).toArray();
+ assertTrue("expression should match", Arrays.deepEquals(expected, actual));
+ }
+
+ @Test
public void testLt() throws Exception {
Object[] expected = new Object[] {"<", 1f, 0f};
Object[] actual = lt(literal(1), literal(0)).toArray();
@@ -181,6 +200,13 @@ public class ExpressionTest {
}
@Test
+ public void testLtExpression() throws Exception {
+ Object[] expected = new Object[] {"<", new Object[] {"get", "hello"}, 1f};
+ Object[] actual = lt(get("hello"), 1).toArray();
+ assertTrue("expression should match", Arrays.deepEquals(expected, actual));
+ }
+
+ @Test
public void testGte() throws Exception {
Object[] expected = new Object[] {">=", 1f, 1f};
Object[] actual = gte(literal(1), literal(1)).toArray();
@@ -195,6 +221,13 @@ public class ExpressionTest {
}
@Test
+ public void testGteExpression() throws Exception {
+ Object[] expected = new Object[] {">=", new Object[] {"get", "hello"}, 1f};
+ Object[] actual = gte(get("hello"), 1).toArray();
+ assertTrue("expression should match", Arrays.deepEquals(expected, actual));
+ }
+
+ @Test
public void testLte() throws Exception {
Object[] expected = new Object[] {"<=", 1f, 1f};
Object[] actual = lte(literal(1), literal(1)).toArray();
@@ -202,6 +235,13 @@ public class ExpressionTest {
}
@Test
+ public void testLteExpression() throws Exception {
+ Object[] expected = new Object[] {"<=", new Object[] {"get", "hello"}, 1f};
+ Object[] actual = lte(get("hello"), 1).toArray();
+ assertTrue("expression should match", Arrays.deepEquals(expected, actual));
+ }
+
+ @Test
public void testLteLiteral() throws Exception {
Object[] expected = new Object[] {"<=", 1f, 1f};
Object[] actual = lte(literal(1), 1).toArray();