@Test public void propertyColorStopsDefaultValue() throws Exception { SimpleFeatureType SAMPLE = DataUtilities.createType("SAMPLE", "id:\"\",temperature:0.0,location=4326"); SimpleFeature feature = DataUtilities.createFeature(SAMPLE, "measure1=A|NOT_A_VALID_NUMBER|POINT(0,0)"); JSONObject json = MapboxTestUtils.object( "{'property':'temperature','type':'exponential','stops':[[0,'blue'],[100,'red']], 'default':'#000000'}"); MBFunction function = new MBFunction(json); Color result = function.color().evaluate(feature, Color.class); assertEquals(new Color(0, 0, 0), result); }
public Expression color() { Expression value = input(); FunctionType type = getTypeWithDefault(Color.class); if (type == FunctionType.EXPONENTIAL) { double base = parse.optional(Double.class, json, "base", 1.0); if (base == 1.0) { return colorGenerateInterpolation(value); } else { return colorGenerateExponential(value, base); } } if (type == null || type == FunctionType.CATEGORICAL) { return colorGenerateRecode(value); } else if (type == FunctionType.INTERVAL) { return colorGenerateCategorize(value); } else if (type == FunctionType.IDENTITY) { return withFallback(ff.function("css", value)); } throw new UnsupportedOperationException("Color unavailable for '" + type + "' function"); }
MBFunction { public Expression color() { Expression value = input(); FunctionType type = getTypeWithDefault(Color.class); if (type == FunctionType.EXPONENTIAL) { double base = parse.optional(Double.class, json, "base", 1.0); if (base == 1.0) { return colorGenerateInterpolation(value); } else { return colorGenerateExponential(value, base); } } if (type == null || type == FunctionType.CATEGORICAL) { return colorGenerateRecode(value); } else if (type == FunctionType.INTERVAL) { return colorGenerateCategorize(value); } else if (type == FunctionType.IDENTITY) { return withFallback(ff.function("css", value)); } throw new UnsupportedOperationException("Color unavailable for '" + type + "' function"); } }
MBFunction { public Expression color() { Expression value = input(); FunctionType type = getTypeWithDefault(Color.class); if (type == FunctionType.EXPONENTIAL) { double base = parse.optional(Double.class, json, "base", 1.0); if (base == 1.0) { return colorGenerateInterpolation(value); } else { return colorGenerateExponential(value, base); } } if (type == null || type == FunctionType.CATEGORICAL) { return colorGenerateRecode(value); } else if (type == FunctionType.INTERVAL) { return colorGenerateCategorize(value); } else if (type == FunctionType.IDENTITY) { return withFallback(ff.function("css", value)); } throw new UnsupportedOperationException("Color unavailable for '" + type + "' function"); } MBFunction(JSONObject json);  MBFunction(MBObjectParser parse, JSONObject json); }
MBFunction { public Expression color() { Expression value = input(); FunctionType type = getTypeWithDefault(Color.class); if (type == FunctionType.EXPONENTIAL) { double base = parse.optional(Double.class, json, "base", 1.0); if (base == 1.0) { return colorGenerateInterpolation(value); } else { return colorGenerateExponential(value, base); } } if (type == null || type == FunctionType.CATEGORICAL) { return colorGenerateRecode(value); } else if (type == FunctionType.INTERVAL) { return colorGenerateCategorize(value); } else if (type == FunctionType.IDENTITY) { return withFallback(ff.function("css", value)); } throw new UnsupportedOperationException("Color 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 color() { Expression value = input(); FunctionType type = getTypeWithDefault(Color.class); if (type == FunctionType.EXPONENTIAL) { double base = parse.optional(Double.class, json, "base", 1.0); if (base == 1.0) { return colorGenerateInterpolation(value); } else { return colorGenerateExponential(value, base); } } if (type == null || type == FunctionType.CATEGORICAL) { return colorGenerateRecode(value); } else if (type == FunctionType.INTERVAL) { return colorGenerateCategorize(value); } else if (type == FunctionType.IDENTITY) { return withFallback(ff.function("css", value)); } throw new UnsupportedOperationException("Color 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();  }