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>>
Internal class used to manage handler registration. Instances of this class
are thread-safe.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addToFileExtension
(String fileExt, T handler) Add the handler to the internal file extension map.private void
addToFileExtensions
(List<String> fileExts, T handler) Add the handler to the internal file extension map under each file extension.private void
addToFormat
(String fmtName, T handler) Add the handler to the internal format name map.getByFileExtension
(String fileExt) Get the first handler registered for the given file extension or null if not found.Get the first handler registered for the given format, or null if not found.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.Get all registered handlers.private static String
normalizeString
(String str) Normalize the given string for use as a registry identifier.void
register
(GeometryFormat fmt, T handler) Register a handler for the givenformat
.private static <V> void
removeValue
(Map<String, V> map, V value) Remove all keys that map tovalue
.requireHandlerByFormatOrFileName
(GeometryFormat fmt, 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.Unregister the current handler for the given format and return it.
-
Field Details
-
handlers
List of registered handlers. -
handlersByFormatName
Handlers keyed by lower-case format name. -
handlersByFileExtension
Handlers keyed by lower-case file extension.
-
-
Constructor Details
-
HandlerRegistry
private HandlerRegistry()
-
-
Method Details
-
register
Register a handler for the givenformat
.- Parameters:
fmt
- format for the handlerhandler
- handler to register- Throws:
NullPointerException
- if either argument is null
-
unregister
Unregister the given handler.- Parameters:
handler
- handler to unregister
-
unregisterFormat
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
Get all registered handlers.- Returns:
- list of all registered handlers
-
getByFormat
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
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
Get the handler for the given format or file extension, throwing an exception if one cannot be found. Iffmt
is not null, it is used to directly look up the handler and thefileName
argument is ignored. Otherwise, the file extension is extracted fromfileName
and used to look up the handler.- Parameters:
fmt
- format to look up; if present,fileName
is ignoredfileName
- file name to use for the look up iffmt
is null- Returns:
- the handler matching the arguments
- Throws:
IllegalArgumentException
- if a handler cannot be found
-
addToFormat
Add the handler to the internal format name map.- Parameters:
fmtName
- format namehandler
- handler to add- Throws:
NullPointerException
- iffmtName
is null
-
addToFileExtensions
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
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
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
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
Normalize the given string for use as a registry identifier.- Parameters:
str
- string to normalize- Returns:
- normalized string
-