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 java.lang.ObjectInternal class used to manage handler registration. Instances of this class are thread-safe.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<T>handlersList of registered handlers.private java.util.Map<java.lang.String,T>handlersByFileExtensionHandlers keyed by lower-case file extension.private java.util.Map<java.lang.String,T>handlersByFormatNameHandlers keyed by lower-case format name.
-
Constructor Summary
Constructors Modifier Constructor Description privateHandlerRegistry()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddToFileExtension(java.lang.String fileExt, T handler)Add the handler to the internal file extension map.private voidaddToFileExtensions(java.util.List<java.lang.String> fileExts, T handler)Add the handler to the internal file extension map under each file extension.private voidaddToFormat(java.lang.String fmtName, T handler)Add the handler to the internal format name map.TgetByFileExtension(java.lang.String fileExt)Get the first handler registered for the given file extension or null if not found.TgetByFormat(GeometryFormat fmt)Get the first handler registered for the given format, or null if not found.private static <V> VgetByNormalizedKey(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.StringnormalizeString(java.lang.String str)Normalize the given string for use as a registry identifier.voidregister(GeometryFormat fmt, T handler)Register a handler for the givenformat.private static <V> voidremoveValue(java.util.Map<java.lang.String,V> map, V value)Remove all keys that map tovalue.TrequireHandlerByFormatOrFileName(GeometryFormat fmt, java.lang.String fileName)Get the handler for the given format or file extension, throwing an exception if one cannot be found.voidunregister(T handler)Unregister the given handler.TunregisterFormat(GeometryFormat fmt)Unregister the current handler for the given format and return it.
-
-
-
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.
-
-
Method Detail
-
register
public void register(GeometryFormat fmt, T handler)
Register a handler for the givenformat.- Parameters:
fmt- format for the handlerhandler- 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. Iffmtis not null, it is used to directly look up the handler and thefileNameargument is ignored. Otherwise, the file extension is extracted fromfileNameand used to look up the handler.- Parameters:
fmt- format to look up; if present,fileNameis ignoredfileName- file name to use for the look up iffmtis 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 namehandler- handler to add- Throws:
java.lang.NullPointerException- iffmtNameis 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 handlerhandler- 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 handlerhandler- 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 searchkey- 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 tovalue.- Type Parameters:
V- Value type- Parameters:
map- map to remove keys fromvalue- 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
-
-