Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Rework logical condition convenience expressions #11555

Merged
merged 2 commits into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -236,36 +236,36 @@ public static Expression eq(@NonNull Expression compareOne, @NonNull Expression
/**
* Returns true if the input values are equal, false otherwise.
*
* @param compareOne the first boolean
* @param compareOne the first expression
* @param compareTwo the second boolean
* @return expression
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-==">Style specification</a>
*/
public static Expression eq(boolean compareOne, boolean compareTwo) {
return eq(literal(compareOne), literal(compareTwo));
public static Expression eq(Expression compareOne, boolean compareTwo) {
return eq(compareOne, literal(compareTwo));
}

/**
* Returns true if the input values are equal, false otherwise.
*
* @param compareOne the first number
* @param compareOne the first expression
* @param compareTwo the second number
* @return expression
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-==">Style specification</a>
*/
public static Expression eq(@NonNull String compareOne, @NonNull String compareTwo) {
public static Expression eq(@NonNull Expression compareOne, @NonNull String compareTwo) {
return eq(literal(compareOne), literal(compareTwo));
}

/**
* Returns true if the input values are equal, false otherwise.
*
* @param compareOne the first number
* @param compareOne the first expression
* @param compareTwo the second number
* @return expression
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-==">Style specification</a>
*/
public static Expression eq(@NonNull Number compareOne, @NonNull Number compareTwo) {
public static Expression eq(@NonNull Expression compareOne, @NonNull Number compareTwo) {
return eq(literal(compareOne), literal(compareTwo));
}

Expand All @@ -285,36 +285,36 @@ public static Expression neq(@NonNull Expression compareOne, @NonNull Expression
/**
* Returns true if the input values are equal, false otherwise.
*
* @param compareOne the first boolean
* @param compareOne the first expression
* @param compareTwo the second boolean
* @return expression
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-!=">Style specification</a>
*/
public static Expression neq(boolean compareOne, boolean compareTwo) {
public static Expression neq(Expression compareOne, boolean compareTwo) {
return new Expression("!=", literal(compareOne), literal(compareTwo));
}

//fixme
/**
* Returns `true` if the input values are not equal, `false` otherwise.
*
* @param compareOne the first string
* @param compareOne the first expression
* @param compareTwo the second string
* @return expression
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-!=">Style specification</a>
*/
public static Expression neq(@NonNull String compareOne, @NonNull String compareTwo) {
public static Expression neq(@NonNull Expression compareOne, @NonNull String compareTwo) {
return new Expression("!=", literal(compareOne), literal(compareTwo));
}

/**
* Returns `true` if the input values are not equal, `false` otherwise.
*
* @param compareOne the first number
* @param compareOne the first expression
* @param compareTwo the second number
* @return expression
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-!=">Style specification</a>
*/
public static Expression neq(@NonNull Number compareOne, @NonNull Number compareTwo) {
public static Expression neq(@NonNull Expression compareOne, @NonNull Number compareTwo) {
return new Expression("!=", literal(compareOne), literal(compareTwo));
}

Expand All @@ -334,32 +334,32 @@ public static Expression gt(@NonNull Expression compareOne, @NonNull Expression
/**
* Returns true if the first input is strictly greater than the second, false otherwise.
*
* @param compareOne the first number
* @param compareOne the first expression
* @param compareTwo the second number
* @return expression
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions->">Style specification</a>
*/
public static Expression gt(@NonNull Number compareOne, @NonNull Number compareTwo) {
public static Expression gt(@NonNull Expression compareOne, @NonNull Number compareTwo) {
return new Expression(">", literal(compareOne), literal(compareTwo));
}

/**
* Returns true if the first input is strictly greater than the second, false otherwise.
*
* @param compareOne the first string
* @param compareOne the first expression
* @param compareTwo the second string
* @return expression
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions->">Style specification</a>
*/
public static Expression gt(@NonNull String compareOne, @NonNull String compareTwo) {
public static Expression gt(@NonNull Expression compareOne, @NonNull String compareTwo) {
return new Expression(">", literal(compareOne), literal(compareTwo));
}

/**
* Returns true if the first input is strictly less than the second, false otherwise.
* The inputs must be numbers or strings, and both of the same type.
*
* @param compareOne the first number
* @param compareOne the first expression
* @param compareTwo the second number
* @return expression
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-<">Style specification</a>
Expand All @@ -371,24 +371,24 @@ public static Expression lt(@NonNull Expression compareOne, @NonNull Expression
/**
* Returns true if the first input is strictly less than the second, false otherwise.
*
* @param compareOne the first number
* @param compareOne the first expression
* @param compareTwo the second number
* @return expression
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-<">Style specification</a>
*/
public static Expression lt(@NonNull Number compareOne, @NonNull Number compareTwo) {
public static Expression lt(@NonNull Expression compareOne, @NonNull Number compareTwo) {
return new Expression("<", literal(compareOne), literal(compareTwo));
}

/**
* Returns true if the first input is strictly less than the second, false otherwise.
*
* @param compareOne the first string
* @param compareOne the first expression
* @param compareTwo the second string
* @return expression
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-<">Style specification</a>
*/
public static Expression lt(@NonNull String compareOne, @NonNull String compareTwo) {
public static Expression lt(@NonNull Expression compareOne, @NonNull String compareTwo) {
return new Expression("<", literal(compareOne), literal(compareTwo));
}

Expand All @@ -408,24 +408,24 @@ public static Expression gte(@NonNull Expression compareOne, @NonNull Expression
/**
* Returns true if the first input is greater than or equal to the second, false otherwise.
*
* @param compareOne the first number
* @param compareOne the first expression
* @param compareTwo the second number
* @return expression
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions->=">Style specification</a>
*/
public static Expression gte(@NonNull Number compareOne, @NonNull Number compareTwo) {
public static Expression gte(@NonNull Expression compareOne, @NonNull Number compareTwo) {
return new Expression(">=", literal(compareOne), literal(compareTwo));
}

/**
* Returns true if the first input is greater than or equal to the second, false otherwise.
*
* @param compareOne the first string
* @param compareOne the first expression
* @param compareTwo the second string
* @return expression
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions->=">Style specification</a>
*/
public static Expression gte(@NonNull String compareOne, @NonNull String compareTwo) {
public static Expression gte(@NonNull Expression compareOne, @NonNull String compareTwo) {
return new Expression(">=", literal(compareOne), literal(compareTwo));
}

Expand All @@ -445,24 +445,24 @@ public static Expression lte(@NonNull Expression compareOne, @NonNull Expression
/**
* Returns true if the first input is less than or equal to the second, false otherwise.
*
* @param compareOne the first number
* @param compareOne the first expression
* @param compareTwo the second number
* @return expression
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-<=">Style specification</a>
*/
public static Expression lte(@NonNull Number compareOne, @NonNull Number compareTwo) {
public static Expression lte(@NonNull Expression compareOne, @NonNull Number compareTwo) {
return new Expression("<=", literal(compareOne), literal(compareTwo));
}

/**
* Returns true if the first input is less than or equal to the second, false otherwise.
*
* @param compareOne the first string
* @param compareOne the first expression
* @param compareTwo the second string
* @return expression
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-<=">Style specification</a>
*/
public static Expression lte(@NonNull String compareOne, @NonNull String compareTwo) {
public static Expression lte(@NonNull Expression compareOne, @NonNull String compareTwo) {
return new Expression("<=", literal(compareOne), literal(compareTwo));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void testEq() throws Exception {
@Test
public void testEqLiteral() throws Exception {
Object[] expected = new Object[] {"==", 1, 1};
Object[] actual = eq(1, 1).toArray();
Object[] actual = eq(literal(1), 1).toArray();
assertTrue("expression should match", Arrays.deepEquals(expected, actual));
}

Expand All @@ -140,7 +140,7 @@ public void testNeq() throws Exception {
@Test
public void testNeqLiteral() throws Exception {
Object[] expected = new Object[] {"!=", 0, 1};
Object[] actual = neq(0, 1).toArray();
Object[] actual = neq(literal(0), 1).toArray();
assertTrue("expression should match", Arrays.deepEquals(expected, actual));
}

Expand All @@ -154,7 +154,7 @@ public void testGt() throws Exception {
@Test
public void testGtLiteral() throws Exception {
Object[] expected = new Object[] {">", 0, 1};
Object[] actual = gt(0, 1).toArray();
Object[] actual = gt(literal(0), 1).toArray();
assertTrue("expression should match", Arrays.deepEquals(expected, actual));
}

Expand All @@ -168,7 +168,7 @@ public void testLt() throws Exception {
@Test
public void testLtLiteral() throws Exception {
Object[] expected = new Object[] {"<", 1, 0};
Object[] actual = lt(1, 0).toArray();
Object[] actual = lt(literal(1), 0).toArray();
assertTrue("expression should match", Arrays.deepEquals(expected, actual));
}

Expand All @@ -182,7 +182,7 @@ public void testGte() throws Exception {
@Test
public void testGteLiteral() throws Exception {
Object[] expected = new Object[] {">=", 1, 1};
Object[] actual = gte(1, 1).toArray();
Object[] actual = gte(literal(1), 1).toArray();
assertTrue("expression should match", Arrays.deepEquals(expected, actual));
}

Expand All @@ -196,7 +196,7 @@ public void testLte() throws Exception {
@Test
public void testLteLiteral() throws Exception {
Object[] expected = new Object[] {"<=", 1, 1};
Object[] actual = lte(1, 1).toArray();
Object[] actual = lte(literal(1), 1).toArray();
assertTrue("expression should match", Arrays.deepEquals(expected, actual));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ private void styleLineFilterLayer() {
LineLayer counties = (LineLayer) mapboxMap.getLayer("counties");

if (counties != null) {
counties.setFilter(eq("NAME10", "Washington"));
counties.setFilter(eq(get("NAME10"), "Washington"));

counties.setProperties(
lineColor(Color.RED),
Expand Down