Class Factory<T extends Element>

  • Type Parameters:
    T - the type of element returned by this factory (either a node or a mark)

    @Internal
    @ReturnValuesAreNonnullByDefault
    public class Factory<T extends Element>
    extends Object
    Supporting class for the parser that resolves the type of an element to its corresponding node or mark class as well as a sub-parser that can reconstruct the element from its map value.
    • Method Detail

      • type

        public String type()
        Returns:
        the value used to identify elements of this type, or an empty string if this factory creates opaque representations for an unsupported element type
      • typeClass

        public Class<T> typeClass()
        Returns:
        the class of elements that this factory returns
      • parse

        public T parse​(Map<String,​?> map)
        Parses the given value map, assuming that it is a well-formed representation of an element of the type that this factory can produce.
        Parameters:
        map - the value map to be parsed
        Returns:
        the reconstructed element
      • extractLookupMap

        @SafeVarargs
        public static <K,​T extends ElementMap<K,​Factory<? extends T>> extractLookupMap​(Function<Factory<? extends T>,​K> keyExtractor,
                                                                                                     Factory<? extends T>... factories)
        Given a group of factories, builds a lookup map that can resolve each factory's typeClass() to the corresponding factory.
        Type Parameters:
        K - the inferred key type for the resulting lookup map
        T - the inferred element type returned by this factory
        Parameters:
        keyExtractor - the function for extracting the lookup key for the factory lookup map
        factories - all factories to include in the lookup map
        Returns:
        the (immutable) lookup map