Package org.wildfly.security.util
Class StringMapping<T>
- java.lang.Object
-
- org.wildfly.security.util.StringMapping<T>
-
public final class StringMapping<T> extends Object
An efficient mapping of enumerated strings to some other object.- Author:
- David M. Lloyd
-
-
Field Summary
Fields Modifier and Type Field Description private T[]
items
private StringEnumeration
stringEnumeration
-
Constructor Summary
Constructors Constructor Description StringMapping(StringEnumeration stringEnumeration, Function<String,T> mapping)
Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
getItemById(int index)
Get an item from this mapping by ID.T
getItemByString(String str)
Get an item from this mapping by the corresponding string name.StringEnumeration
getStringEnumeration()
Get the string enumeration for this mapping.
-
-
-
Field Detail
-
stringEnumeration
private final StringEnumeration stringEnumeration
-
items
private final T[] items
-
-
Constructor Detail
-
StringMapping
public StringMapping(StringEnumeration stringEnumeration, Function<String,T> mapping)
Construct a new instance.- Parameters:
stringEnumeration
- the string enumeration (must not benull
)mapping
- the mapping function (must not benull
)
-
-
Method Detail
-
getItemById
public T getItemById(int index) throws IllegalArgumentException
Get an item from this mapping by ID.- Parameters:
index
- the index to look up- Returns:
- the mapped item for the given ID
- Throws:
IllegalArgumentException
- if the given index is out of range
-
getItemByString
public T getItemByString(String str) throws IllegalArgumentException
Get an item from this mapping by the corresponding string name.- Parameters:
str
- the string name- Returns:
- the item
- Throws:
IllegalArgumentException
- if the string name is unknown
-
getStringEnumeration
public StringEnumeration getStringEnumeration()
Get the string enumeration for this mapping.- Returns:
- the string enumeration for this mapping (not
null
)
-
-