Package com.atlassian.adf.util
Class ParserSupport
- java.lang.Object
-
- com.atlassian.adf.util.ParserSupport
-
@Internal @ReturnValuesAreNonnullByDefault public abstract class ParserSupport extends Object
Utility/support methods common to parsing nodes or marks.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intasInt(Number value, String attrKey)Parses the given value as an integer, tolerating lossless conversions from other number formats when possible.static voidcheckType(Map<String,?> map, String expectedType)Verify that thetypevalue of the given map is correct.static StringcleanUri(String uri, String attrKey)static StringcleanUri(URI uri, String attrKey)static StringcleanUri(URL url, String attrKey)static <T> Tget(Map<String,?> map, String key)Extract a value from the given map, assuming that it will be of the expected type (ornull.static <T> Optional<T>getAttr(Map<String,?> map, String attr)static <T> Optional<T>getAttr(Map<String,?> map, String attr, Class<T> requiredClass)static Optional<Double>getAttrDouble(Map<String,?> map, String attr)static Optional<Integer>getAttrInt(Map<String,?> map, String attr)static intgetAttrIntOrThrow(Map<String,?> map, String attr)static StringgetAttrNonEmpty(Map<String,?> map, String attr)static Optional<Number>getAttrNumber(Map<String,?> map, String attr)static NumbergetAttrNumberOrThrow(Map<String,?> map, String attr)static <T> TgetAttrOrThrow(Map<String,?> map, String attr)static <T> TgetAttrOrThrow(Map<String,?> map, String attr, Class<T> requiredClass)static <T> TgetOrThrow(Map<String,?> map, String key)Extract a value from the given map, requiring that it be of the given type (ornull.static StringgetTypeOrThrow(Map<String,?> map)Extract thetypevalue from the given map.
-
-
-
Method Detail
-
get
@Nullable public static <T> T get(Map<String,?> map, String key)
Extract a value from the given map, assuming that it will be of the expected type (ornull.
-
getOrThrow
public static <T> T getOrThrow(Map<String,?> map, String key)
Extract a value from the given map, requiring that it be of the given type (ornull.
-
checkType
public static void checkType(Map<String,?> map, String expectedType)
Verify that thetypevalue of the given map is correct.Since most of the parser methods are resolved from a lookup map that keys off of the type in the first place, this would indicate a serious internal error in the parser code, which is why it is not handled as an
AdfException.- Throws:
IllegalArgumentException- if thetypevalue is not theexpectedType
-
getTypeOrThrow
public static String getTypeOrThrow(Map<String,?> map)
Extract thetypevalue from the given map.- Throws:
AdfException.MissingType- if the map does not have atypefield, it isn't a string, or it is empty.
-
getAttr
public static <T> Optional<T> getAttr(Map<String,?> map, String attr, Class<T> requiredClass)
-
asInt
public static int asInt(Number value, String attrKey)
Parses the given value as an integer, tolerating lossless conversions from other number formats when possible.- Parameters:
value- the numeric value to be mapped to anintif possibleattrKey- the attribute key from which the value was read- Returns:
- the resulting
intvalue - Throws:
AdfException.ValueTypeMismatch- if the original value cannot be represented as anint, such as aLongthat is>= Integer.MAX_VALUE.
-
getAttrOrThrow
public static <T> T getAttrOrThrow(Map<String,?> map, String attr, Class<T> requiredClass)
-
-