[android] - move match stops conversion to Stop.toExpressionArray

This commit is contained in:
tobrun
2018-06-12 00:12:31 +02:00
committed by Tobrun
parent 0ecdbebb09
commit aa16b90e2b
2 changed files with 21 additions and 12 deletions

View File

@@ -1017,12 +1017,7 @@ public class Expression {
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-match">Style specification</a>
*/
public static Expression match(@NonNull Expression input, @NonNull Expression defaultOutput, @NonNull Stop... stops) {
Expression[] expressionStops = new Expression[stops.length * 2];
for (int i = 0; i < stops.length; i++) {
expressionStops[i * 2] = literal(stops[i].value);
expressionStops[i * 2 + 1] = literal(stops[i].output);
}
return match(join(join(new Expression[] {input}, expressionStops), new Expression[] {defaultOutput}));
return match(join(join(new Expression[] {input}, Stop.toExpressionArray(stops)), new Expression[] {defaultOutput}));
}
/**
@@ -3449,8 +3444,6 @@ public class Expression {
throw new IllegalArgumentException("PropertyValue are not allowed as an expression literal, use value instead.");
} else if (value instanceof Expression.ExpressionLiteral) {
return toValue((ExpressionLiteral) value);
} else if (value instanceof Expression) {
return ((Expression) value).toArray();
}
return value;
}

View File

@@ -2,7 +2,6 @@ package com.mapbox.mapboxsdk.testapp.style;
import android.graphics.Color;
import android.support.test.runner.AndroidJUnit4;
import com.mapbox.mapboxsdk.style.expressions.Expression;
import com.mapbox.mapboxsdk.style.layers.FillLayer;
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
@@ -11,14 +10,12 @@ import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import timber.log.Timber;
import java.io.IOException;
import timber.log.Timber;
import static com.mapbox.mapboxsdk.style.expressions.Expression.exponential;
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
import static com.mapbox.mapboxsdk.style.expressions.Expression.interpolate;
@@ -188,6 +185,25 @@ public class ExpressionTest extends BaseActivityTest {
});
}
@Test
public void testLiteralMatchExpression() {
validateTestSetup();
setupStyle();
invoke(mapboxMap, (uiController, mapboxMap) -> {
Expression expression = match(literal("something"), literal(0f),
stop("1", get("1")),
stop("2", get("2")),
stop("3", get("3")),
stop("4", get("4"))
);
layer.setProperties(
fillColor(expression)
);
expression.toArray();
});
}
private void setupStyle() {
invoke(mapboxMap, (uiController, mapboxMap) -> {
// Add a source