Class BoundaryIOManager.HandlerRegistry<T>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<T> handlers
      List of registered handlers.
      private java.util.Map<java.lang.String,​T> handlersByFileExtension
      Handlers keyed by lower-case file extension.
      private java.util.Map<java.lang.String,​T> handlersByFormatName
      Handlers keyed by lower-case format name.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private HandlerRegistry()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void addToFileExtension​(java.lang.String fileExt, T handler)
      Add the handler to the internal file extension map.
      private void addToFileExtensions​(java.util.List<java.lang.String> fileExts, T handler)
      Add the handler to the internal file extension map under each file extension.
      private void addToFormat​(java.lang.String fmtName, T handler)
      Add the handler to the internal format name map.
      T getByFileExtension​(java.lang.String fileExt)
      Get the first handler registered for the given file extension or null if not found.
      T getByFormat​(GeometryFormat fmt)
      Get the first handler registered for the given format, or null if not found.
      private static <V> V getByNormalizedKey​(java.util.Map<java.lang.String,​V> map, java.lang.String key)
      Normalize the given key and return its associated value in the map, or null if not found.
      java.util.List<T> getHandlers()
      Get all registered handlers.
      private static java.lang.String normalizeString​(java.lang.String str)
      Normalize the given string for use as a registry identifier.
      void register​(GeometryFormat fmt, T handler)
      Register a handler for the given format.
      private static <V> void removeValue​(java.util.Map<java.lang.String,​V> map, V value)
      Remove all keys that map to value.
      T requireHandlerByFormatOrFileName​(GeometryFormat fmt, java.lang.String fileName)
      Get the handler for the given format or file extension, throwing an exception if one cannot be found.
      void unregister​(T handler)
      Unregister the given handler.
      T unregisterFormat​(GeometryFormat fmt)
      Unregister the current handler for the given format and return it.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • handlers

        private final java.util.List<T> handlers
        List of registered handlers.
      • handlersByFormatName

        private final java.util.Map<java.lang.String,​T> handlersByFormatName
        Handlers keyed by lower-case format name.
      • handlersByFileExtension

        private final java.util.Map<java.lang.String,​T> handlersByFileExtension
        Handlers keyed by lower-case file extension.
    • Constructor Detail

      • HandlerRegistry

        private HandlerRegistry()
    • Method Detail

      • register

        public void register​(GeometryFormat fmt,
                             T handler)
        Register a handler for the given format.
        Parameters:
        fmt - format for the handler
        handler - handler to register
        Throws:
        java.lang.NullPointerException - if either argument is null
      • unregister

        public void unregister​(T handler)
        Unregister the given handler.
        Parameters:
        handler - handler to unregister
      • unregisterFormat

        public T unregisterFormat​(GeometryFormat fmt)
        Unregister the current handler for the given format and return it. Null is returned if no handler was registered.
        Parameters:
        fmt - format to unregister
        Returns:
        handler instance previously registered for the format or null if not found
      • getHandlers

        public java.util.List<T> getHandlers()
        Get all registered handlers.
        Returns:
        list of all registered handlers
      • getByFormat

        public T getByFormat​(GeometryFormat fmt)
        Get the first handler registered for the given format, or null if not found.
        Parameters:
        fmt - format to obtain a handler for
        Returns:
        first handler registered for the format
      • getByFileExtension

        public T getByFileExtension​(java.lang.String fileExt)
        Get the first handler registered for the given file extension or null if not found.
        Parameters:
        fileExt - file extension
        Returns:
        first handler registered for the given file extension or null if not found
      • requireHandlerByFormatOrFileName

        public T requireHandlerByFormatOrFileName​(GeometryFormat fmt,
                                                  java.lang.String fileName)
        Get the handler for the given format or file extension, throwing an exception if one cannot be found. If fmt is not null, it is used to directly look up the handler and the fileName argument is ignored. Otherwise, the file extension is extracted from fileName and used to look up the handler.
        Parameters:
        fmt - format to look up; if present, fileName is ignored
        fileName - file name to use for the look up if fmt is null
        Returns:
        the handler matching the arguments
        Throws:
        java.lang.IllegalArgumentException - if a handler cannot be found
      • addToFormat

        private void addToFormat​(java.lang.String fmtName,
                                 T handler)
        Add the handler to the internal format name map.
        Parameters:
        fmtName - format name
        handler - handler to add
        Throws:
        java.lang.NullPointerException - if fmtName is null
      • addToFileExtensions

        private void addToFileExtensions​(java.util.List<java.lang.String> fileExts,
                                         T handler)
        Add the handler to the internal file extension map under each file extension.
        Parameters:
        fileExts - file extensions to map to the handler
        handler - handler to add to the file extension map
      • addToFileExtension

        private void addToFileExtension​(java.lang.String fileExt,
                                        T handler)
        Add the handler to the internal file extension map.
        Parameters:
        fileExt - file extension to map to the handler
        handler - handler to add to the file extension map
      • getByNormalizedKey

        private static <V> V getByNormalizedKey​(java.util.Map<java.lang.String,​V> map,
                                                java.lang.String key)
        Normalize the given key and return its associated value in the map, or null if not found.
        Type Parameters:
        V - Value type
        Parameters:
        map - map to search
        key - unnormalized map key
        Returns:
        the value associated with the key after normalization, or null if not found
      • removeValue

        private static <V> void removeValue​(java.util.Map<java.lang.String,​V> map,
                                            V value)
        Remove all keys that map to value.
        Type Parameters:
        V - Value type
        Parameters:
        map - map to remove keys from
        value - value to remove from all entries in the map
      • normalizeString

        private static java.lang.String normalizeString​(java.lang.String str)
        Normalize the given string for use as a registry identifier.
        Parameters:
        str - string to normalize
        Returns:
        normalized string