Package org.geotools.mbstyle.expression
Class MBTypes
- All Implemented Interfaces:
Expression
,Function
The expressions in this section are provided for the purpose of testing for and converting between different data
types like strings, numbers, and boolean values.
Often, such tests and conversions are unnecessary, but they may be necessary in some expressions where the type of a certain sub-expression is ambiguous. They can also be useful in cases where your feature data has inconsistent types; for example, you could use to-number to make sure that values like ""1.5"" (instead of 1.5) are treated as numeric
-
Field Summary
Fields inherited from class MBExpression
colors, decisions, featureData, ff, heatMap, json, lookUp, math, name, parse, ramps, string, transformer, types, variableBindings, zoom
Fields inherited from class FunctionImpl
functionName
Fields inherited from interface Expression
NIL
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionDetermines which expression to use.Asserts that the input is an array (optionally with a specific item type and length).Asserts that the input value is a boolean.Asserts that the input value is a number.Asserts that the input value is an object.Asserts that the input value is a string.Converts the input value to a boolean.Converts the input value to a color.Converts the input value to a number, if possible.Converts the input value to a string.Returns a string describing the type of the given value.Methods inherited from class MBExpression
canCreate, create, getName, throwInsufficientArgumentCount, throwUnexpectedArgumentCount, transformExpression, transformLiteral
Methods inherited from class FunctionImpl
accept, dispatchArguments, equals, evaluate, functionName, getFallbackValue, getFunctionName, getParameters, getParameterValue, getParameterValue, hashCode, setFallbackValue, setName, setParameters, toString
Methods inherited from class ExpressionAbstract
evaluate
Methods inherited from interface Expression
evaluate
-
Constructor Details
-
MBTypes
public MBTypes(JSONArray json)
-
-
Method Details
-
typesArray
Asserts that the input is an array (optionally with a specific item type and length). If, when the input expression is evaluated, it is not of the asserted type, then this assertion will cause the whole expression to be aborted. Example: ["array", value]: array ["array", type: "string" | "number" | "boolean", value]: array<type> ["array", type: "string" | "number" | "boolean", N: number (literal), value ]: array<type, N>- Returns:
- array expression
-
typesBoolean
Asserts that the input value is a boolean. If multiple values are provided, each one is evaluated in order until a boolean is obtained. If none of the inputs are booleans, the expression is an error. Example: ["boolean", value]: boolean ["boolean", value, fallback: value, fallback: value, ...]: boolean- Returns:
- boolean expression
-
typesNumber
Asserts that the input value is a number. If multiple values are provided, each one is evaluated in order until a number is obtained. If none of the inputs are numbers, the expression is an error. Example: ["number", value]: number ["number", value, fallback: value, fallback: value, ...]: number- Returns:
- number expression
-
typesObject
Asserts that the input value is an object. If multiple values are provided, each one is evaluated in order until an object is obtained. If none of the inputs are objects, the expression is an error. Example: ["object", value]: object ["object", value, fallback: value, fallback: value, ...]: object- Returns:
- object expression
-
typesString
Asserts that the input value is a string. If multiple values are provided, each one is evaluated in order until a string is obtained. If none of the inputs are strings, the expression is an error. Example: ["string", value]: string ["string", value, fallback: value, fallback: value, ...]: string- Returns:
- string expression
-
typesToBoolean
Converts the input value to a boolean. The result is false when then input is an empty string, 0, false, null, or NaN; otherwise it is true. Example: ["to-boolean", value]: boolean- Returns:
- convert to boolean expression
-
typesToColor
Converts the input value to a color. If multiple values are provided, each one is evaluated in order until the first successful conversion is obtained. If none of the inputs can be converted, the expression is an error. Example: ["to-color", value, fallback: value, fallback: value, ...]: color- Returns:
- convert to color expression
-
typesToNumber
Converts the input value to a number, if possible. If the input is null or false, the result is 0. If the input is true, the result is 1. If the input is a string, it is converted to a number as specified by the "ToNumber Applied to the String Type" algorithm of the ECMAScript Language Specification. If multiple values are provided, each one is evaluated in order until the first successful conversion is obtained. If none of the inputs can be converted, the expression is an error. Example: ["to-number", value, fallback: value, fallback: value, ...]: number- Returns:
- convert to number expression
-
typesToString
Converts the input value to a string. If the input is null, the result is "null". If the input is a boolean, the result is "true" or "false". If the input is a number, it is converted to a string as specified by the "NumberToString" algorithm of the ECMAScript Language Specification. If the input is a color, it is converted to a string of the form "rgba(r,g,b,a)", where r, g, and b are numerals ranging from 0 to 255, and a ranges from 0 to 1. Otherwise, the input is converted to a string in the format specified by the JSON.stringify function of the ECMAScript Language Specification. Example: ["to-string", value]: string- Returns:
- convert to string expression
-
typesTypeOf
Returns a string describing the type of the given value. Example: ["typeof", value]: string- Returns:
- type of content as a string expression
-
getExpression
Description copied from class:MBExpression
Determines which expression to use.- Specified by:
getExpression
in classMBExpression
- Throws:
MBFormatException
-