Package org.geotools.mbstyle.parse
Class MBObjectParser
- Object
-
- MBObjectParser
-
public class MBObjectParser extends Object
Helper class used to perform JSON traversal ofJSONObject
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.
Non generic "get" methods, likeString id = parse.get("id"); String visibility = parse.getBoolean("visibility"); String source = parse.get("source");
paint(JSONObject)
, are in position to provide an appropriate default value.JSONObject paint = parse.paint( layer );
- Author:
- Torben Barsballe (Boundless)
-
-
Constructor Summary
Constructors Constructor Description MBObjectParser(Class<?> context)
Parser used to in the provided context.MBObjectParser(Class<MBFilter> context, MBObjectParser parse)
Copy constructor allowing reuse of factories, while returning correctcontext
.
-
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 aLiteral
.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 aDisplacement
.<T extends Enum<?>>
ExpressionenumToExpression(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 providedJSONArray
at the provided index, or throw anMBFormatException
.Boolean
getBoolean(JSONObject json, String name)
Look up a Boolean in the providedJSONObject
at the provided 'tag', or thrown anMBFormatException
.Boolean
getBoolean(JSONObject json, String name, Boolean fallback)
Look up a Boolean in the providedJSONObject
at the provided 'tag', or thrown anMBFormatException
, with a fallback if the json is null or contains no such 'tag'.<T extends Enum<?>>
TgetEnum(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 FilterFactoryJSONArray
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 providedJSONArray
at the provided index, or throw anMBFormatException
.Double
getNumeric(JSONObject json, String name)
Look up a Double in the providedJSONObject
at the provided 'tag', or thrown anMBFormatException
.StyleFactory
getStyleFactory()
Shared StyleFactoryboolean
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 anMBFormatException
).JSONArray
jsonArray(Object obj, String message)
Casts the provided obj to a JSONArray (otherwise throws anMBFormatException
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 exceptionJSONObject
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 anMBFormatException
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 anMBFormatException
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 correctcontext
.- 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 JSONObjectname
- 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 JSONObjectname
- The tag to look up in the provided JSONObjectfallback
- 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 JSONArrayname
- The tag to look up in the provided JSONObjectfallback
- 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 Stringname
- 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 Stringname
- Tag to lookupfallback
- default string- Returns:
- required string, or fallback if unavailable
-
getNumeric
public double getNumeric(JSONArray json, int index)
Look up a double in the providedJSONArray
at the provided index, or throw anMBFormatException
.- Parameters:
json
- The array in which to look up the doubleindex
- 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 providedJSONObject
at the provided 'tag', or thrown anMBFormatException
.- Parameters:
json
- The object in which to look up the Doublename
- 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 providedJSONArray
at the provided index, or throw anMBFormatException
.- Parameters:
json
- The array in which to look up the Booleanindex
- 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 providedJSONObject
at the provided 'tag', or thrown anMBFormatException
.- Parameters:
json
- The object in which to look up the Booleanname
- 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 providedJSONObject
at the provided 'tag', or thrown anMBFormatException
, with a fallback if the json is null or contains no such 'tag'.- Parameters:
json
- The object in which to look up the Booleanname
- The tag at which to look up the Booleanfallback
- 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 anMBFormatException
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 anMBFormatException
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 lookupjson
- The JSONObject in which to lookup the valuename
- The tag at which to lookupthe value in the JSONObjectfallback
- 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 fromname
- 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", orLineMBLayer.LineJoin.MITER
to an expression that evaluates to "mitre".- Parameters:
json
- The json object containing the propertyname
- The json key corresponding to the propertyenumeration
- The Mapbox enumeration that the value should be an instance offallback
- 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 literalenumeration
- 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 castmessage
- 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) throws MBFormatException
Casts the provided obj to a JSONArray (otherwise throws anMBFormatException
).- Parameters:
obj
- The object to cast- Returns:
- The object, cast to JSONArray
- Throws:
MBFormatException
-
jsonArray
public JSONArray jsonArray(Object obj, String message) throws MBFormatException
Casts the provided obj to a JSONArray (otherwise throws anMBFormatException
with the provided message).- Parameters:
obj
- The object to castmessage
- 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 arrayjson
- The JSONObject in which to look up the arrayname
- The tag at which to look up the arrayfallback
- 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 representationname
- The tag at which to look up the percentagefallback
- 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 valueindex
- 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 valueindex
- The index in the JSONArray at which to look up the valuefallback
- 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 valuename
- 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 valuename
- The tag in the JSONObject at which to look up the valuefallback
- 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 valueindex
- 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 representationfallback
- 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 representationfallback
- 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 aLiteral
.-
{"line-color": "yellow"
named: a few have been put in pass test cases, prnding: plan to useHints.COLOR_DEFINITION
to allow for web colors. -
{"line-color": "#ffff00"}
hex: hex color conversion are supplied byColorConverterFactory
-
{"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
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 useHints.COLOR_DEFINITION
to allow for web colors. -
{"line-color": "#ffff00"}
hex: hex color conversion are supplied byColorConverterFactory
-
{"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
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 representationfallback
- 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 aDisplacement
.- Parameters:
json
- The JSONObject in which to look up a displacement valuename
- The tag in the JSONObjectfallback
- The fallback displacement, if no value is found at that tag.- Returns:
- A displacement from the json
-
isPropertyDefined
@Deprecated public boolean isPropertyDefined(JSONObject json, String propertyName) throws MBFormatException
Deprecated.- Returns:
- True if json has a value for the property, False otherwise.
- Throws:
MBFormatException
-
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 objectname
- 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 arrayindex
- 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 objectname
- 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 arrayindex
- 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 objectname
- 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 arrayindex
- 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 objectname
- 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 arrayindex
- 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 objectname
- 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 arrayindex
- 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 objectname
- 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 arrayindex
- Index of array element- Returns:
- True if array has an object element at the provided index, False otherwise.
- Throws:
MBFormatException
-
-