Class TransitFactory


  • public class TransitFactory
    extends Object
    Main entry point for using transit-java library. Provides methods to construct readers and writers, as well as helpers to make various other values.
    • Constructor Detail

      • TransitFactory

        public TransitFactory()
    • Method Detail

      • writer

        public static <T> Writer<T> writer​(TransitFactory.Format type,
                                           OutputStream out)
        Creates a writer instance.
        Parameters:
        type - format to write in
        out - output stream to write to
        Returns:
        a Writer
      • writer

        public static <T> Writer<T> writer​(TransitFactory.Format type,
                                           OutputStream out,
                                           Map<Class,​WriteHandler<?,​?>> customHandlers)
        Creates a writer instance.
        Parameters:
        type - format to write in
        out - output stream to write to
        customHandlers - additional WriteHandlers to use in addition to or in place of the default WriteHandlers
        Returns:
        a writer
      • writer

        public static <T> Writer<T> writer​(TransitFactory.Format type,
                                           OutputStream out,
                                           WriteHandler<?,​?> defaultWriteHandler)
        Creates a writer instance.
        Parameters:
        type - format to write in
        out - output stream to write to
        defaultWriteHandler - WriteHandler to use by default
        Returns:
        a writer
      • writer

        public static <T> Writer<T> writer​(TransitFactory.Format type,
                                           OutputStream out,
                                           Map<Class,​WriteHandler<?,​?>> customHandlers,
                                           WriteHandler<?,​?> defaultWriteHandler)
        Creates a writer instance.
        Parameters:
        type - format to write in
        out - output stream to write to
        customHandlers - additional WriteHandlers to use in addition to or in place of the default WriteHandlers
        defaultWriteHandler - WriteHandler to use by default
        Returns:
        a writer
      • writer

        public static <T> Writer<T> writer​(TransitFactory.Format type,
                                           OutputStream out,
                                           Map<Class,​WriteHandler<?,​?>> customHandlers,
                                           WriteHandler<?,​?> defaultWriteHandler,
                                           Function<Object,​Object> transform)
        Creates a writer instance.
        Parameters:
        type - format to write in
        out - output stream to write to
        customHandlers - additional WriteHandlers to use in addition to or in place of the default WriteHandlers
        defaultWriteHandler - WriteHandler to use by default
        transform - a transform function to apply to values before writing
        Returns:
        a writer
      • reader

        public static Reader reader​(TransitFactory.Format type,
                                    InputStream in)
        Creates a reader instance.
        Parameters:
        type - the format to read in
        in - the input stream to read from
        Returns:
        a reader
      • reader

        public static Reader reader​(TransitFactory.Format type,
                                    InputStream in,
                                    Map<String,​ReadHandler<?,​?>> customHandlers)
        Creates a reader instance.
        Parameters:
        type - the format to read in
        in - the input stream to read from
        customHandlers - a map of custom ReadHandlers to use in addition or in place of the default ReadHandlers
        Returns:
        a reader
      • reader

        public static Reader reader​(TransitFactory.Format type,
                                    InputStream in,
                                    DefaultReadHandler<?> customDefaultHandler)
        Creates a reader instance.
        Parameters:
        type - the format to read in
        in - the input stream to read from
        customDefaultHandler - a DefaultReadHandler to use for processing encoded values for which there is no read handler
        Returns:
        a reader
      • reader

        public static Reader reader​(TransitFactory.Format type,
                                    InputStream in,
                                    Map<String,​ReadHandler<?,​?>> customHandlers,
                                    DefaultReadHandler<?> customDefaultHandler)
        Creates a reader instance.
        Parameters:
        type - the format to read in
        in - the input stream to read from
        customHandlers - a map of custom ReadHandlers to use in addition or in place of the default ReadHandlers
        customDefaultHandler - a DefaultReadHandler to use for processing encoded values for which there is no read handler
        Returns:
        a reader
      • keyword

        public static Keyword keyword​(Object o)
        Converts a string or keyword to a keyword
        Parameters:
        o - A string or a keyword
        Returns:
        a keyword
      • symbol

        public static Symbol symbol​(Object o)
        Converts a string or a symbol to a symbol
        Parameters:
        o - a string or a symbol
        Returns:
        a symbol
      • taggedValue

        public static <T> TaggedValue<T> taggedValue​(String tag,
                                                     T rep)
        Creates a TaggedValue
        Parameters:
        tag - tag string
        rep - value representation
        Returns:
        a tagged value
      • link

        public static Link link​(String href,
                                String rel)
        Creates a Link
        Parameters:
        href - an href value
        rel - a rel value
        Returns:
        a link instance
      • link

        public static Link link​(URI href,
                                String rel)
        Creates a Link
        Parameters:
        href - an href value
        rel - a rel value
        Returns:
        a link instance
      • link

        public static Link link​(String href,
                                String rel,
                                String name,
                                String prompt,
                                String render)
        Creates a Link
        Parameters:
        href - an href value
        rel - a rel value
        name - an optional name value
        prompt - an optional prompt value
        render - an optional render value
        Returns:
        a link instance
      • link

        public static Link link​(URI href,
                                String rel,
                                String name,
                                String prompt,
                                String render)
        Creates a Link
        Parameters:
        href - an href value
        rel - a rel value
        name - an optional name value
        prompt - an optional prompt value
        render - an optional render value
        Returns:
        a link instance
      • uri

        public static URI uri​(String uri)
        Creates a URI
        Parameters:
        uri - a uri string
        Returns:
        the URI
      • defaultDefaultReadHandler

        public static DefaultReadHandler<TaggedValue<Object>> defaultDefaultReadHandler()
        Returns the DefaultReadHandler that is used by default
        Returns:
        DefaultReadHandler instance
      • defaultDefaultWriteHandler

        public static WriteHandler<?,​?> defaultDefaultWriteHandler()
      • defaultReadHandlers

        public static Map<String,​ReadHandler<?,​?>> defaultReadHandlers()
        Returns a map of tags to ReadHandlers that is used by default
        Returns:
        tag to ReadHandler map
      • readHandlerMap

        public static Map<String,​ReadHandler<?,​?>> readHandlerMap​(Map<String,​ReadHandler<?,​?>> customHandlers)
        Creates a read-only Map of String to ReadHandler containing default ReadHandlers with customHandlers merged in. Use this to build the collection of read handlers once, and pass it to repeated calls to TransitFactory.reader. This can be more efficient than repeatedly passing a map of custom handlers to TransitFactory.reader, which then merges them with the default handlers and/or looks them up in a cache each invocation.
        Parameters:
        customHandlers - a map of custom ReadHandlers to use in addition or in place of the default ReadHandlers
        Returns:
        a ReadHandlerMap
      • defaultWriteHandlers

        public static Map<Class,​WriteHandler<?,​?>> defaultWriteHandlers()
        Returns a map of classes to Handlers that is used by default
        Returns:
        class to Handler map
      • writeHandlerMap

        public static Map<Class,​WriteHandler<?,​?>> writeHandlerMap​(Map<Class,​WriteHandler<?,​?>> customHandlers)
        Creates a read-only Map of Class to WriteHandler containing default WriteHandlers with customHandlers merged in. Use this to build the collection of write handlers once, and pass it to repeated calls to TransitFactory.reader. This can be more efficient than repeatedly passing a map of custom handlers to TransitFactory.writer, which then merges them with the default handlers and/or looks them up in a cache each invocation.
        Parameters:
        customHandlers - a map of custom WriteHandler to use in addition or in place of the default WriteHandler
        Returns:
        a WriteHandlerMap