Class MBObjectParser


  • public class MBObjectParser
    extends Object
    Helper class used to perform JSON traversal of JSONObject and perform Expression and Filter conversions. These utilities are used by the MBStyle to convert JSON to simple Java objects, process functions and perform common JSON manipulation tasks.

    Access methods

    Example of transformation to Expression, using the fallback value if provided:
     MBObjectParser parse = new MBObjectParser( ff );
    
     Expression fillOpacity = parse.percent( json, "fill-opacity", 1.0 );
     Expression fillColor = parse.color( json, "fill-color", Color.BLACK );
     

    Get Methods

    Generic "get" methods are also available for safely accessing required fields. These methods will throw a validation error if the required tag was is not available.
     String id = parse.get("id");
     String visibility = parse.getBoolean("visibility");
     String source = parse.get("source");
     
    Non generic "get" methods, like paint(JSONObject), are in position to provide an appropriate default value.
     JSONObject paint = parse.paint( layer );
     
    Author:
    Torben Barsballe (Boundless)
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      <T> T[] array​(Class<T> type, JSONObject json, String name, T[] fallback)
      Lookup an array of the provided type in the provided JSONObject at 'tag', with a fallback if that tag is not found.
      double[] array​(JSONObject json, String name, double[] fallback)
      Convert to double[]
      int[] array​(JSONObject json, String name, int[] fallback)
      Convert to int[]
      Expression bool​(JSONObject json, String name, boolean fallback)
      Convert json to Expression boolean, or a function.
      Literal color​(String color)
      Handles literal color definitions supplied as a string, returning a Literal.
      Expression color​(JSONObject json, String name, Color fallback)
      Convert json to GeoTools Expression color, or a function.
      Literal constant​(Object value, Class<? extends Enum<?>> enumeration)
      Utility method used to convert enumerations to an appropriate GeoTools literal string.
      Color convertToColor​(String color)
      Converts color definitions supplied as a string to Color objects:
      Displacement displacement​(JSONObject json, String name, Displacement fallback)
      Maps a json value at 'tag' in the provided JSONObject to a Displacement.
      <T extends Enum<?>>
      Expression
      enumToExpression​(JSONObject json, String name, Class<T> enumeration, T fallback)
      Parse a Mapbox enumeration property to a GeoTools Expression that evaluates to a GeoTools constant (supports the property being specified as a mapbox function).
      Expression font​(JSONObject json, String name)
      Convert the provided object to a font Expression (or function).
      String get​(JSONArray json, int index)
      Quickly access required json index (as a String).
      String get​(JSONObject json, String name)
      Quickly access required json tag (as a String).
      String get​(JSONObject json, String name, String fallback)
      Quickly access optional json tag.
      Boolean getBoolean​(JSONArray json, int index)
      Look up a Boolean in the provided JSONArray at the provided index, or throw an MBFormatException.
      Boolean getBoolean​(JSONObject json, String name)
      Look up a Boolean in the provided JSONObject at the provided 'tag', or thrown an MBFormatException.
      Boolean getBoolean​(JSONObject json, String name, Boolean fallback)
      Look up a Boolean in the provided JSONObject at the provided 'tag', or thrown an MBFormatException, with a fallback if the json is null or contains no such 'tag'.
      <T extends Enum<?>>
      T
      getEnum​(JSONObject json, String name, Class<T> enumeration, T fallback)
      Convert a String value to an enum value, ignoring case, with the provided fallback.
      FilterFactory getFilterFactory()
      Shared FilterFactory
      JSONArray getJSONArray​(JSONObject json, String name)
      Access json contains a JSONArray for the indicated tag.
      JSONArray getJSONArray​(JSONObject json, String name, JSONArray fallback)
      Access a JSONArray at the provided tag in the provided JSONObject, with a fallback if no JSONArray is found at that tag.
      JSONObject getJSONObject​(JSONObject json, String name)
      Access JSONObject for the indicated tag.
      JSONObject getJSONObject​(JSONObject json, String name, JSONObject fallback)
      Access JSONObject for the indicated tag, with the provided fallback if the the json does not contain a JSONObject for that tag.
      double getNumeric​(JSONArray json, int index)
      Look up a double in the provided JSONArray at the provided index, or throw an MBFormatException.
      Double getNumeric​(JSONObject json, String name)
      Look up a Double in the provided JSONObject at the provided 'tag', or thrown an MBFormatException.
      StyleFactory getStyleFactory()
      Shared StyleFactory
      boolean isArray​(JSONArray json, int index)
      True if array has an array element at the provided index, False otherwise.
      boolean isArray​(JSONObject json, String name)
      True if json has an array value for the provided name, False otherwise.
      boolean isBoolean​(JSONArray json, int index)
      True if array has a boolean element at the provided index, False otherwise.
      boolean isBoolean​(JSONObject json, String name)
      True if json has a boolean value for the provided name, False otherwise.
      boolean isDefined​(JSONArray json, int index)
      True if array has an element at the provided index, False otherwise.
      boolean isDefined​(JSONObject json, String name)
      True if json has a value for the provided name, False otherwise.
      boolean isNumeric​(JSONArray json, int index)
      True if array has a numeric element at the provided index, False otherwise.
      boolean isNumeric​(JSONObject json, String name)
      True if json has a numeric value for the provided name, False otherwise.
      boolean isObject​(JSONArray json, int index)
      True if array has an object element at the provided index, False otherwise.
      boolean isObject​(JSONObject json, String name)
      True if json has an object value for the provided name, False otherwise.
      boolean isPropertyDefined​(JSONObject json, String propertyName)
      Deprecated.
      boolean isString​(JSONArray json, int index)
      True if array has a string element at the provided index, False otherwise.
      boolean isString​(JSONObject json, String name)
      True if json has a string value for the provided name, False otherwise.
      JSONArray jsonArray​(Object obj)
      Casts the provided obj to a JSONArray (otherwise throws an MBFormatException).
      JSONArray jsonArray​(Object obj, String message)
      Casts the provided obj to a JSONArray (otherwise throws an MBFormatException with the provided message).
      JSONObject jsonObect​(Object obj, String message)
      Casts the provided obj to a JSONObject (safely reporting format exception, with the provided message).
      JSONObject jsonObject​(Object obj)
      Casts the provided obj to a JSONObject (safely reporting format exception
      JSONObject layout​(JSONObject layer)
      Safely look up layout in provided layer json.
      Expression number​(JSONArray json, int index)
      Convert the value at 'index' in the provided JSONArray to a numeric Expression or a Function.
      Expression number​(JSONArray json, int index, Number fallback)
      Convert the value in the provided JSONArray at index to a numeric Expression, or a function, with a fallback if the json is null.
      Expression number​(JSONObject json, String name)
      Convert the value in the provided JSONObject at 'tag' to a numeric GeoTools Expression, or a Function.
      Expression number​(JSONObject json, String name, Number fallback)
      Convert the value in the provided JSONObject at 'tag' to a numeric Expression, or a function, with a fallback if the json is null.
      <T> T optional​(Class<T> type, JSONObject json, String name, T fallback)
      Optional lookup, will return fallback if not available.
      JSONObject paint​(JSONObject layer)
      Safely look up paint in provided layer json.
      Expression percentage​(JSONObject json, String name)
      Convert json to Expression number between 0 and 1, or a function.
      Expression percentage​(JSONObject json, String name, Number fallback)
      Convert json to Expression number between 0 and 1, or a function.
      <T> T require​(Class<T> type, JSONArray json, int index)
      Retrieve an object of the provided type in the JSONArray at this index, throwing an MBFormatException if no object of that type is found at that index of the array.
      <T> T require​(Class<T> type, JSONObject json, String name)
      Retrieve an object of the provided type in the JSONObject at this tag, throwing an MBFormatException if no object of that type is found at that tag in the object.
      Expression string​(JSONArray json, int index)
      Convert the value in the provided JSONArray at index to a string Literal, or a Function.
      Expression string​(JSONObject json, String name, String fallback)
      Convert json to GeoTools Expression string, or a function.
      Object value​(JSONArray json, int index)
      Access a literal value (string, numeric, or boolean).
      Object value​(JSONObject json, String name)
      Access a literal value (string, numeric, or boolean).
    • Constructor Detail

      • MBObjectParser

        public MBObjectParser​(Class<?> context)
        Parser used to in the provided context.
        Parameters:
        context - Context this parser is being used in (for better error reporting)
      • MBObjectParser

        public MBObjectParser​(Class<MBFilter> context,
                              MBObjectParser parse)
        Copy constructor allowing reuse of factories, while returning correct context.
        Parameters:
        context - Context this parser is being used in (for better error reporting)
        parse - Parent parser used to configure factories consistently
    • Method Detail

      • getFilterFactory

        public FilterFactory getFilterFactory()
        Shared FilterFactory
      • getStyleFactory

        public StyleFactory getStyleFactory()
        Shared StyleFactory
      • paint

        public JSONObject paint​(JSONObject layer)
        Safely look up paint in provided layer json.

        Paint is optional, returning an empty JSONObject (to prevent the need for null checks).

        Returns:
        paint definition, optional so may be an empty JSONObject
        Throws:
        MBFormatException - If paint is provided as an invalid type (such as boolean).
      • layout

        public JSONObject layout​(JSONObject layer)
        Safely look up layout in provided layer json.

        Layout is optional, returning an empty JSONObject (to prevent the need for null checks).

        Returns:
        layout definition, optional so may be an empty JSONObject
        Throws:
        MBFormatException - If layout is provided as an invalid type (such as boolean).
      • getJSONObject

        public JSONObject getJSONObject​(JSONObject json,
                                        String name)
        Access JSONObject for the indicated tag.

        Confirms json contains the provided tag as a JSONObject, correctly throwing MBFormatException if not available.

        Parameters:
        json - The JSONObject in which to lookup the provided tag and return a JSONObject
        name - The tag to look up in the provided JSONObject
        Returns:
        The JSONObject at the provided tag
        Throws:
        MBFormatException - If JSONObject not available for the provided tag
      • getJSONObject

        public JSONObject getJSONObject​(JSONObject json,
                                        String name,
                                        JSONObject fallback)
        Access JSONObject for the indicated tag, with the provided fallback if the the json does not contain a JSONObject for that tag.
        Parameters:
        json - The JSONObject in which to lookup the provided tag and return a JSONObject
        name - The tag to look up in the provided JSONObject
        fallback - The JSONObject to return if the provided json does not contain a JSONObject for that tag.
        Returns:
        The JSONObject at the provided tag, or the fallback object.
      • getJSONArray

        public JSONArray getJSONArray​(JSONObject json,
                                      String name)
        Access json contains a JSONArray for the indicated tag.

        Confirms json contains the provided tag as a JSONArray, correctly throwing MBFormatException if not available.

        Returns:
        JSONObject
        Throws:
        MBFormatException - If JSONObject not available for the provided tag
      • getJSONArray

        public JSONArray getJSONArray​(JSONObject json,
                                      String name,
                                      JSONArray fallback)
        Access a JSONArray at the provided tag in the provided JSONObject, with a fallback if no JSONArray is found at that tag.
        Parameters:
        json - The JSONObject in which to lookup the provided tag and return a JSONArray
        name - The tag to look up in the provided JSONObject
        fallback - The JSONArray to return if the provided json does not contain a JSONArray for that tag.
        Returns:
        The JSONArray at the provided tag, or the fallback JSONArray.
      • value

        public Object value​(JSONArray json,
                            int index)
        Access a literal value (string, numeric, or boolean).
        Parameters:
        json - JSONArray object to parse.
        index - position in the provided array for which to retrieve a value.
        Returns:
        required string, numeric or boolean
        Throws:
        MBFormatException - if required index not available.
      • value

        public Object value​(JSONObject json,
                            String name)
        Access a literal value (string, numeric, or boolean).
        Returns:
        required string, numeric or boolean
        Throws:
        MBFormatException - if required tag not available.
      • get

        public String get​(JSONArray json,
                          int index)
        Quickly access required json index (as a String).
        Returns:
        required string
        Throws:
        MBFormatException - if required index not available.
      • get

        public String get​(JSONObject json,
                          String name)
        Quickly access required json tag (as a String).
        Parameters:
        json - The object in which to look up the String
        name - Tag to lookup
        Returns:
        required string
        Throws:
        MBFormatException - if required tag not available.
      • get

        public String get​(JSONObject json,
                          String name,
                          String fallback)
        Quickly access optional json tag.
        Parameters:
        json - The object in which to look up the String
        name - Tag to lookup
        fallback - default string
        Returns:
        required string, or fallback if unavailable
      • getNumeric

        public double getNumeric​(JSONArray json,
                                 int index)
        Look up a double in the provided JSONArray at the provided index, or throw an MBFormatException.
        Parameters:
        json - The array in which to look up the double
        index - The index at which to look up the double
        Returns:
        The double from the array at index.
      • getNumeric

        public Double getNumeric​(JSONObject json,
                                 String name)
        Look up a Double in the provided JSONObject at the provided 'tag', or thrown an MBFormatException.
        Parameters:
        json - The object in which to look up the Double
        name - The tag at which to look up the Double
        Returns:
        The Double from the object at 'tag'
      • getBoolean

        public Boolean getBoolean​(JSONArray json,
                                  int index)
        Look up a Boolean in the provided JSONArray at the provided index, or throw an MBFormatException.
        Parameters:
        json - The array in which to look up the Boolean
        index - The index at which to look up the Boolean
        Returns:
        The Boolean from the array at index.
      • getBoolean

        public Boolean getBoolean​(JSONObject json,
                                  String name)
        Look up a Boolean in the provided JSONObject at the provided 'tag', or thrown an MBFormatException.
        Parameters:
        json - The object in which to look up the Boolean
        name - The tag at which to look up the Boolean
        Returns:
        The Boolean from the object at 'tag'
      • getBoolean

        public Boolean getBoolean​(JSONObject json,
                                  String name,
                                  Boolean fallback)
        Look up a Boolean in the provided JSONObject at the provided 'tag', or thrown an MBFormatException, with a fallback if the json is null or contains no such 'tag'.
        Parameters:
        json - The object in which to look up the Boolean
        name - The tag at which to look up the Boolean
        fallback - The value to return if the json is null or contains no such 'tag'.
        Returns:
        The Boolean from the object at 'tag', or the fallback value
      • require

        public <T> T require​(Class<T> type,
                             JSONArray json,
                             int index)
        Retrieve an object of the provided type in the JSONArray at this index, throwing an MBFormatException if no object of that type is found at that index of the array.
        Type Parameters:
        T - Class to return
        Parameters:
        type - The type of the object to retrieve.
        json - The JSONArray in which to retrieve the object.
        index - The index in the JSONArray at which to retrieve the object.
        Returns:
        The object of the required type in the array at index.
      • require

        public <T> T require​(Class<T> type,
                             JSONObject json,
                             String name)
        Retrieve an object of the provided type in the JSONObject at this tag, throwing an MBFormatException if no object of that type is found at that tag in the object.
        Type Parameters:
        T - Class to return
        Parameters:
        type - The type of the object to retrieve.
        json - The JSONObject in which to retrieve the object.
        name - The index in the JSONObject at which to retrieve the object.
        Returns:
        The object of the required type in the JSONObject at the tag.
      • optional

        public <T> T optional​(Class<T> type,
                              JSONObject json,
                              String name,
                              T fallback)
        Optional lookup, will return fallback if not available.
        Type Parameters:
        T - Class to return
        Parameters:
        type - Type to lookup
        json - The JSONObject in which to lookup the value
        name - The tag at which to lookupthe value in the JSONObject
        fallback - The fallback value to use if the JSONObject is null or does not contain the provided tag
        Returns:
        value for the provided tag, or fallback if not available
        Throws:
        MBFormatException - If value is found and is not the expected type
      • getEnum

        public <T extends Enum<?>> T getEnum​(JSONObject json,
                                             String name,
                                             Class<T> enumeration,
                                             T fallback)
        Convert a String value to an enum value, ignoring case, with the provided fallback.
        Type Parameters:
        T - Enumeration type to return
        Parameters:
        json - The json object to parse the value from
        name - The key used to retrieve the value from the json.
        enumeration - The enum to convert the value to.
        fallback - default value if json is null
        Returns:
        The enum value from the string, or the fallback value.
        Throws:
        MBFormatException - if the value is not a String, or it is not a valid value for the enumeration.
      • enumToExpression

        public <T extends Enum<?>> Expression enumToExpression​(JSONObject json,
                                                               String name,
                                                               Class<T> enumeration,
                                                               T fallback)
        Parse a Mapbox enumeration property to a GeoTools Expression that evaluates to a GeoTools constant (supports the property being specified as a mapbox function).

        For example, converts LineMBLayer.LineJoin.BEVEL to an expression that evaluates to the String value "bevel", or LineMBLayer.LineJoin.MITER to an expression that evaluates to "mitre".

        Parameters:
        json - The json object containing the property
        name - The json key corresponding to the property
        enumeration - The Mapbox enumeration that the value should be an instance of
        fallback - The fallback enumeration value, if the value is missing or invalid for the provided enumeration.
        Returns:
        A GeoTools expression corresponding to the Mapbox enumeration value, evaluating to a GeoTools constant.
      • constant

        public Literal constant​(Object value,
                                Class<? extends Enum<?>> enumeration)
        Utility method used to convert enumerations to an appropriate GeoTools literal string.

        Any conversion between mapbox constants and geotools constants will be done here.

        Parameters:
        value - The value to be converted to the appropriate GeoTools literal
        enumeration - The type of the mapbox enumeration
        Returns:
        Literal, or null if unavailable
      • jsonObject

        public JSONObject jsonObject​(Object obj)
                              throws MBFormatException
        Casts the provided obj to a JSONObject (safely reporting format exception
        Returns:
        JSONObject
        Throws:
        MBFormatException
      • jsonObect

        public JSONObject jsonObect​(Object obj,
                                    String message)
                             throws MBFormatException
        Casts the provided obj to a JSONObject (safely reporting format exception, with the provided message).
        Parameters:
        obj - The object to cast
        message - The message for the exception of the object is not a JSONObject
        Returns:
        The object, cast to JSONObject
        Throws:
        MBFormatException
      • jsonArray

        public JSONArray jsonArray​(Object obj,
                                   String message)
                            throws MBFormatException
        Casts the provided obj to a JSONArray (otherwise throws an MBFormatException with the provided message).
        Parameters:
        obj - The object to cast
        message - The message for the exception of the object is not a JSONArray
        Returns:
        The object, cast to JSONArray
        Throws:
        MBFormatException
      • array

        public <T> T[] array​(Class<T> type,
                             JSONObject json,
                             String name,
                             T[] fallback)
        Lookup an array of the provided type in the provided JSONObject at 'tag', with a fallback if that tag is not found. Throws an exception if that tag is something other than an array, or if its contents cannot be cast to type.
        Parameters:
        type - The type of the array
        json - The JSONObject in which to look up the array
        name - The tag at which to look up the array
        fallback - The fallback array
        Returns:
        An array of the provided type, or the fallback array.
      • array

        public int[] array​(JSONObject json,
                           String name,
                           int[] fallback)
        Convert to int[]
      • array

        public double[] array​(JSONObject json,
                              String name,
                              double[] fallback)
        Convert to double[]
      • percentage

        public Expression percentage​(JSONObject json,
                                     String name)
                              throws MBFormatException
        Convert json to Expression number between 0 and 1, or a function.
        Parameters:
        json - json representation
        Returns:
        Percentage GeoTools Expression based on provided json, or null if not provided
        Throws:
        MBFormatException
      • percentage

        public Expression percentage​(JSONObject json,
                                     String name,
                                     Number fallback)
                              throws MBFormatException
        Convert json to Expression number between 0 and 1, or a function.
        Parameters:
        json - json representation
        name - The tag at which to look up the percentage
        fallback - default value if json is null
        Returns:
        Percentage GeoTools Expression based on provided json, or literal if json was null.
        Throws:
        MBFormatException
      • font

        public Expression font​(JSONObject json,
                               String name)
                        throws MBFormatException
        Convert the provided object to a font Expression (or function).
        Parameters:
        json - The json context of the object, used for error messages.
        name - Tag used to lookup font value
        Returns:
        Font GeoTools Expression for the provided object
        Throws:
        MBFormatException
      • number

        public Expression number​(JSONArray json,
                                 int index)
                          throws MBFormatException
        Convert the value at 'index' in the provided JSONArray to a numeric Expression or a Function.
        Parameters:
        json - The JSONArray in which to look up a value
        index - The index in the JSONArray
        Returns:
        Numeric GeoTools Expression based on provided json, or null.
        Throws:
        MBFormatException
      • number

        public Expression number​(JSONArray json,
                                 int index,
                                 Number fallback)
                          throws MBFormatException
        Convert the value in the provided JSONArray at index to a numeric Expression, or a function, with a fallback if the json is null.
        Parameters:
        json - The JSONArray in which to look up the value
        index - The index in the JSONArray at which to look up the value
        fallback - default value if json is null
        Returns:
        Numeric GeoTools Expression based on provided json, or Literal if json was null.
        Throws:
        MBFormatException
      • number

        public Expression number​(JSONObject json,
                                 String name)
                          throws MBFormatException
        Convert the value in the provided JSONObject at 'tag' to a numeric GeoTools Expression, or a Function.
        Parameters:
        json - The JSONObject in which to look up the value
        name - The tag in the JSONObject at which to look up the value
        Returns:
        Numeric GeoTools Expression based on provided json, or null
        Throws:
        MBFormatException
      • number

        public Expression number​(JSONObject json,
                                 String name,
                                 Number fallback)
                          throws MBFormatException
        Convert the value in the provided JSONObject at 'tag' to a numeric Expression, or a function, with a fallback if the json is null.
        Parameters:
        json - The JSONObject in which to look up the value
        name - The tag in the JSONObject at which to look up the value
        fallback - default value if the JSONObject is null
        Returns:
        Numeric GeoTools Expression based on provided json, or fallback Literal if json was null.
        Throws:
        MBFormatException
      • string

        public Expression string​(JSONArray json,
                                 int index)
        Convert the value in the provided JSONArray at index to a string Literal, or a Function.
        Parameters:
        json - The JSONArray in which to look up the value
        index - The index in the JSONArray at which to look up the value
        Returns:
        String GeoTools Expression based on provided json, or literal if json was null.
      • string

        public Expression string​(JSONObject json,
                                 String name,
                                 String fallback)
                          throws MBFormatException
        Convert json to GeoTools Expression string, or a function.
        Parameters:
        json - json representation
        fallback - default value if json is null
        Returns:
        String GeoTools Expression based on provided json, or literal if json was null.
        Throws:
        MBFormatException
      • color

        public Expression color​(JSONObject json,
                                String name,
                                Color fallback)
                         throws MBFormatException
        Convert json to GeoTools Expression color, or a function.
        Parameters:
        json - json representation
        fallback - default value (string representation of color) if json is null
        Returns:
        String GeoTools Expression based on provided json, or literal if json was null.
        Throws:
        MBFormatException
      • color

        public Literal color​(String color)
        Handles literal color definitions supplied as a string, returning a Literal.
        • {"line-color": "yellow"
          named: a few have been put in pass test cases, prnding: plan to use Hints.COLOR_DEFINITION to allow for web colors.
        • {"line-color": "#ffff00"}
          hex: hex color conversion are supplied by ColorConverterFactory
        • {"line-color": "#ff0"}
          hex: we will need to special case this
        • {"line-color": "rgb(255, 255, 0)"}
          - we will need to special case this
        • {"line-color": "rgba(255, 255, 0, 1)"}
          - we will need to special case this
        • {"line-color": "hsl(100, 50%, 50%)"}
          - we will need to special case this
        • {"line-color": "hsla(100, 50%, 50%, 1)"}
          - we will need to special case this
        This method uses Hints.COLOR_DEFINITION "CSS" to support the use of web colors names.
        Parameters:
        color - name of color (CSS or "web" colors)
        Returns:
        appropriate java color, or null if not available.
      • convertToColor

        public Color convertToColor​(String color)
        Converts color definitions supplied as a string to Color objects:
        • {"line-color": "yellow"
          named: a few have been put in pass test cases, prnding: plan to use Hints.COLOR_DEFINITION to allow for web colors.
        • {"line-color": "#ffff00"}
          hex: hex color conversion are supplied by ColorConverterFactory
        • {"line-color": "#ff0"}
          hex: we will need to special case this
        • {"line-color": "rgb(255, 255, 0)"}
          - we will need to special case this
        • {"line-color": "rgba(255, 255, 0, 1)"}
          - we will need to special case this
        • {"line-color": "hsl(100, 50%, 50%)"}
          - we will need to special case this
        • {"line-color": "hsla(100, 50%, 50%, 1)"}
          - we will need to special case this
        This method uses Hints.COLOR_DEFINITION "CSS" to support the use of web colors names.
        Parameters:
        color - name of color (CSS or "web" colors)
        Returns:
        appropriate java color, or null if not available.
      • bool

        public Expression bool​(JSONObject json,
                               String name,
                               boolean fallback)
                        throws MBFormatException
        Convert json to Expression boolean, or a function.
        Parameters:
        json - json representation
        fallback - default value if json is null
        Returns:
        String GeoTools Expression based on provided json, or literal if json was null.
        Throws:
        MBFormatException
      • displacement

        public Displacement displacement​(JSONObject json,
                                         String name,
                                         Displacement fallback)
        Maps a json value at 'tag' in the provided JSONObject to a Displacement.
        Parameters:
        json - The JSONObject in which to look up a displacement value
        name - The tag in the JSONObject
        fallback - The fallback displacement, if no value is found at that tag.
        Returns:
        A displacement from the json
      • isDefined

        public boolean isDefined​(JSONObject json,
                                 String name)
                          throws MBFormatException
        True if json has a value for the provided name, False otherwise.
        Parameters:
        json - JSON object
        name - Name used to look up a value
        Returns:
        True if json has a value for the provided name, False otherwise.
        Throws:
        MBFormatException
      • isDefined

        public boolean isDefined​(JSONArray json,
                                 int index)
                          throws MBFormatException
        True if array has an element at the provided index, False otherwise.
        Parameters:
        json - JSON array
        index - Index of array element
        Returns:
        True if array has an element at the provided index, False otherwise.
        Throws:
        MBFormatException
      • isString

        public boolean isString​(JSONObject json,
                                String name)
                         throws MBFormatException
        True if json has a string value for the provided name, False otherwise.
        Parameters:
        json - JSON object
        name - Name used to look up a value
        Returns:
        True if json has a string value for the provided name, False otherwise.
        Throws:
        MBFormatException
      • isString

        public boolean isString​(JSONArray json,
                                int index)
                         throws MBFormatException
        True if array has a string element at the provided index, False otherwise.
        Parameters:
        json - JSON array
        index - Index of array element
        Returns:
        True if array has a string element at the provided index, False otherwise.
        Throws:
        MBFormatException
      • isNumeric

        public boolean isNumeric​(JSONObject json,
                                 String name)
                          throws MBFormatException
        True if json has a numeric value for the provided name, False otherwise.
        Parameters:
        json - JSON object
        name - Name used to look up a value
        Returns:
        True if json has a numeric value for the provided name, False otherwise.
        Throws:
        MBFormatException
      • isNumeric

        public boolean isNumeric​(JSONArray json,
                                 int index)
                          throws MBFormatException
        True if array has a numeric element at the provided index, False otherwise.
        Parameters:
        json - JSON array
        index - Index of array element
        Returns:
        True if array has a numeric element at the provided index, False otherwise.
        Throws:
        MBFormatException
      • isBoolean

        public boolean isBoolean​(JSONObject json,
                                 String name)
                          throws MBFormatException
        True if json has a boolean value for the provided name, False otherwise.
        Parameters:
        json - JSON object
        name - Name used to look up a value
        Returns:
        True if json has a boolean value for the provided name, False otherwise.
        Throws:
        MBFormatException
      • isBoolean

        public boolean isBoolean​(JSONArray json,
                                 int index)
                          throws MBFormatException
        True if array has a boolean element at the provided index, False otherwise.
        Parameters:
        json - JSON array
        index - Index of array element
        Returns:
        True if array has a boolean element at the provided index, False otherwise.
        Throws:
        MBFormatException
      • isArray

        public boolean isArray​(JSONObject json,
                               String name)
                        throws MBFormatException
        True if json has an array value for the provided name, False otherwise.
        Parameters:
        json - JSON object
        name - Name used to look up a value
        Returns:
        True if json has an array value for the provided name, False otherwise.
        Throws:
        MBFormatException
      • isArray

        public boolean isArray​(JSONArray json,
                               int index)
                        throws MBFormatException
        True if array has an array element at the provided index, False otherwise.
        Parameters:
        json - JSON array
        index - Index of array element
        Returns:
        True if array has an array element at the provided index, False otherwise.
        Throws:
        MBFormatException
      • isObject

        public boolean isObject​(JSONObject json,
                                String name)
                         throws MBFormatException
        True if json has an object value for the provided name, False otherwise.
        Parameters:
        json - JSON object
        name - Name used to look up a value
        Returns:
        True if json has an object value for the provided name, False otherwise.
        Throws:
        MBFormatException
      • isObject

        public boolean isObject​(JSONArray json,
                                int index)
                         throws MBFormatException
        True if array has an object element at the provided index, False otherwise.
        Parameters:
        json - JSON array
        index - Index of array element
        Returns:
        True if array has an object element at the provided index, False otherwise.
        Throws:
        MBFormatException