Class ParserSupport


  • @Internal
    @ReturnValuesAreNonnullByDefault
    public abstract class ParserSupport
    extends Object
    Utility/support methods common to parsing nodes or marks.
    • 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 (or null.
      • 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 (or null.
      • checkType

        public static void checkType​(Map<String,​?> map,
                                     String expectedType)
        Verify that the type value 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 the type value is not the expectedType
      • getTypeOrThrow

        public static String getTypeOrThrow​(Map<String,​?> map)
        Extract the type value from the given map.
        Throws:
        AdfException.MissingType - if the map does not have a type field, it isn't a string, or it is empty.
      • 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 an int if possible
        attrKey - the attribute key from which the value was read
        Returns:
        the resulting int value
        Throws:
        AdfException.ValueTypeMismatch - if the original value cannot be represented as an int, such as a Long that is >= Integer.MAX_VALUE.
      • getAttrIntOrThrow

        public static int getAttrIntOrThrow​(Map<String,​?> map,
                                            String attr)
      • getAttrNumberOrThrow

        public static Number getAttrNumberOrThrow​(Map<String,​?> map,
                                                  String attr)
      • getAttrOrThrow

        public static <T> T getAttrOrThrow​(Map<String,​?> map,
                                           String attr)
      • getAttrOrThrow

        public static <T> T getAttrOrThrow​(Map<String,​?> map,
                                           String attr,
                                           Class<T> requiredClass)