Class BoundaryIOManager.HandlerRegistry<T>

java.lang.Object
org.apache.commons.geometry.io.core.BoundaryIOManager.HandlerRegistry<T>
Type Parameters:
T - Handler type
Enclosing class:
BoundaryIOManager<H extends HyperplaneConvexSubset<?>,B extends BoundarySource<H>,R extends BoundaryReadHandler<H,B>,W extends BoundaryWriteHandler<H,B>>

private static final class BoundaryIOManager.HandlerRegistry<T> extends Object
Internal class used to manage handler registration. Instances of this class are thread-safe.
  • Field Details

    • handlers

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

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

      private final Map<String,T> handlersByFileExtension
      Handlers keyed by lower-case file extension.
  • Constructor Details

    • HandlerRegistry

      private HandlerRegistry()
  • Method Details

    • 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:
      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 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(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, 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:
      IllegalArgumentException - if a handler cannot be found
    • addToFormat

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

      private void addToFileExtensions(List<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(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(Map<String,V> map, 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(Map<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 String normalizeString(String str)
      Normalize the given string for use as a registry identifier.
      Parameters:
      str - string to normalize
      Returns:
      normalized string