Package io.netty.util
Class ConstantPool<T extends Constant<T>>
java.lang.Object
io.netty.util.ConstantPool<T>
- Type Parameters:
T
- the type of the constant
A pool of
Constant
s.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConcurrentMap
<String, T> private final AtomicInteger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate T
createOrThrow
(String name) Creates constant by name or throws exception.boolean
private T
getOrCreate
(String name) Get existing constant by name or creates new one if not exists.protected abstract T
newConstant
(int id, String name) newInstance
(String name) Creates a newConstant
for the givenname
or fail with anIllegalArgumentException
if aConstant
for the givenname
exists.final int
nextId()
Deprecated.Returns theConstant
which is assigned to the specifiedname
.
-
Field Details
-
constants
-
nextId
-
-
Constructor Details
-
ConstantPool
public ConstantPool()
-
-
Method Details
-
valueOf
-
valueOf
Returns theConstant
which is assigned to the specifiedname
. If there's no suchConstant
, a new one will be created and returned. Once created, the subsequent calls with the samename
will always return the previously created one (i.e. singleton.)- Parameters:
name
- the name of theConstant
-
getOrCreate
Get existing constant by name or creates new one if not exists. Threadsafe- Parameters:
name
- the name of theConstant
-
exists
-
newInstance
Creates a newConstant
for the givenname
or fail with anIllegalArgumentException
if aConstant
for the givenname
exists. -
createOrThrow
Creates constant by name or throws exception. Threadsafe- Parameters:
name
- the name of theConstant
-
newConstant
-
nextId
Deprecated.
-