@Test public void numericIntervalFunctionTest() throws Exception { String jsonStr = "{'property': 'temperature', 'default':0, 'type': 'interval','stops': [[0, 2],[100, 4],[1000, 6]]}"; MBFunction function = new MBFunction(MapboxTestUtils.object(jsonStr)); assertThat(function, categories(containsInAnyOrder(MBFunction.FunctionCategory.PROPERTY))); assertThat(function, hasProperty("type", is(MBFunction.FunctionType.INTERVAL))); Expression outputExpression = function.numeric(); final SimpleFeatureType SAMPLE = DataUtilities.createType("SAMPLE", "id:\"\",temperature,location=4326"); java.util.function.Function<Long, SimpleFeature> features = (temp) -> DataUtilities.createFeature(SAMPLE, "measure1=A|" + temp + "|POINT(0,0)"); assertThat(outputExpression, evaluatesTo(features.apply(-1L), Number.class, equalInt(0))); assertThat(outputExpression, evaluatesTo(features.apply(0L), Number.class, equalInt(2))); assertThat(outputExpression, evaluatesTo(features.apply(20L), Number.class, equalInt(2))); assertThat(outputExpression, evaluatesTo(features.apply(100L), Number.class, equalInt(4))); assertThat(outputExpression, evaluatesTo(features.apply(200L), Number.class, equalInt(4))); assertThat(outputExpression, evaluatesTo(features.apply(1000L), Number.class, equalInt(6))); assertThat(outputExpression, evaluatesTo(features.apply(2000L), Number.class, equalInt(6))); }
public Expression numeric() { Expression input = input(); FunctionType type = getTypeWithDefault(Number.class); if (type == FunctionType.EXPONENTIAL) { double base = parse.optional(Double.class, json, "base", 1.0); if (base == 1.0) { return numericGenerateInterpolation(input); } else { return numericGenerateExponential(input, base); } } if (type == FunctionType.CATEGORICAL) { return generateRecode(input); } else if (type == FunctionType.INTERVAL) { return generateCategorize(input); } else if (type == FunctionType.IDENTITY) { return withFallback(input); } throw new UnsupportedOperationException("Numeric unavailable for '" + type + "' function"); }
MBFunction { public Expression numeric() { Expression input = input(); FunctionType type = getTypeWithDefault(Number.class); if (type == FunctionType.EXPONENTIAL) { double base = parse.optional(Double.class, json, "base", 1.0); if (base == 1.0) { return numericGenerateInterpolation(input); } else { return numericGenerateExponential(input, base); } } if (type == FunctionType.CATEGORICAL) { return generateRecode(input); } else if (type == FunctionType.INTERVAL) { return generateCategorize(input); } else if (type == FunctionType.IDENTITY) { return withFallback(input); } throw new UnsupportedOperationException("Numeric unavailable for '" + type + "' function"); } }
MBFunction { public Expression numeric() { Expression input = input(); FunctionType type = getTypeWithDefault(Number.class); if (type == FunctionType.EXPONENTIAL) { double base = parse.optional(Double.class, json, "base", 1.0); if (base == 1.0) { return numericGenerateInterpolation(input); } else { return numericGenerateExponential(input, base); } } if (type == FunctionType.CATEGORICAL) { return generateRecode(input); } else if (type == FunctionType.INTERVAL) { return generateCategorize(input); } else if (type == FunctionType.IDENTITY) { return withFallback(input); } throw new UnsupportedOperationException("Numeric unavailable for '" + type + "' function"); } MBFunction(JSONObject json);  MBFunction(MBObjectParser parse, JSONObject json); }
MBFunction { public Expression numeric() { Expression input = input(); FunctionType type = getTypeWithDefault(Number.class); if (type == FunctionType.EXPONENTIAL) { double base = parse.optional(Double.class, json, "base", 1.0); if (base == 1.0) { return numericGenerateInterpolation(input); } else { return numericGenerateExponential(input, base); } } if (type == FunctionType.CATEGORICAL) { return generateRecode(input); } else if (type == FunctionType.INTERVAL) { return generateCategorize(input); } else if (type == FunctionType.IDENTITY) { return withFallback(input); } throw new UnsupportedOperationException("Numeric unavailable for '" + type + "' function"); } MBFunction(JSONObject json);  MBFunction(MBObjectParser parse, JSONObject json); FunctionType getType(); Object getDefault(); FunctionType getTypeWithDefault(Class<?> clazz); String getProperty(); EnumSet<FunctionCategory> category(); JSONArray getStops(); Number getBase(); static MBFunction create(JSONObject json); Expression color(); Expression font(); Expression numeric(); @SuppressWarnings("unchecked") Expression function(Class<?> clazz); Expression enumeration(Class<? extends Enum<?>> enumeration); boolean isArrayFunction(); List<MBFunction> splitArrayFunction(); }
MBFunction { public Expression numeric() { Expression input = input(); FunctionType type = getTypeWithDefault(Number.class); if (type == FunctionType.EXPONENTIAL) { double base = parse.optional(Double.class, json, "base", 1.0); if (base == 1.0) { return numericGenerateInterpolation(input); } else { return numericGenerateExponential(input, base); } } if (type == FunctionType.CATEGORICAL) { return generateRecode(input); } else if (type == FunctionType.INTERVAL) { return generateCategorize(input); } else if (type == FunctionType.IDENTITY) { return withFallback(input); } throw new UnsupportedOperationException("Numeric unavailable for '" + type + "' function"); } MBFunction(JSONObject json);  MBFunction(MBObjectParser parse, JSONObject json); FunctionType getType(); Object getDefault(); FunctionType getTypeWithDefault(Class<?> clazz); String getProperty(); EnumSet<FunctionCategory> category(); JSONArray getStops(); Number getBase(); static MBFunction create(JSONObject json); Expression color(); Expression font(); Expression numeric(); @SuppressWarnings("unchecked") Expression function(Class<?> clazz); Expression enumeration(Class<? extends Enum<?>> enumeration); boolean isArrayFunction(); List<MBFunction> splitArrayFunction();  }