Top Description Fields Constructors Methods
io.netty5.util

public abstract Class ConstantPool<T extends Constant<T>>

extends Object
Class Inheritance
Type Parameters
<T>
the type of the constant
Imports
java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, java.util.concurrent.atomic.AtomicInteger

A pool of Constants.

Field Summary

Modifier and TypeField and Description
private final ConcurrentMap<String, T>
private final AtomicInteger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private T
createOrThrow(String
the name of the Constant
name
)

Creates constant by name or throws exception.

public boolean
exists(String name)

Returns true if a AttributeKey exists for the given name.

private T
getOrCreate(String
the name of the Constant
name
)

Get existing constant by name or creates new one if not exists.

protected abstract T
newConstant(int id, String name)

public T
newInstance(String name)

Creates a new Constant for the given name or fail with an IllegalArgumentException if a Constant for the given name exists.

public final int
nextId()

Deprecated
public T
valueOf(Class<?> firstNameComponent, String secondNameComponent)

Shortcut of valueOf(firstNameComponent.getName() + "#" + secondNameComponent).

public T
valueOf(String
the name of the Constant
name
)

Returns the Constant which is assigned to the specified name.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

constantsback to summary
private final ConcurrentMap<String, T> constants
nextIdback to summary
private final AtomicInteger nextId

Constructor Detail

ConstantPoolback to summary
public ConstantPool()

Method Detail

createOrThrowback to summary
private T createOrThrow(String name)

Creates constant by name or throws exception. Threadsafe

Parameters
name:String

the name of the Constant

existsback to summary
public boolean exists(String name)

Returns true if a AttributeKey exists for the given name.

getOrCreateback to summary
private T getOrCreate(String name)

Get existing constant by name or creates new one if not exists. Threadsafe

Parameters
name:String

the name of the Constant

newConstantback to summary
protected abstract T newConstant(int id, String name)
newInstanceback to summary
public T newInstance(String name)

Creates a new Constant for the given name or fail with an IllegalArgumentException if a Constant for the given name exists.

nextIdback to summary
public final int nextId()

Deprecated

Annotations
@Deprecated
valueOfback to summary
public T valueOf(Class<?> firstNameComponent, String secondNameComponent)

Shortcut of valueOf(firstNameComponent.getName() + "#" + secondNameComponent).

valueOfback to summary
public T valueOf(String name)

Returns the Constant which is assigned to the specified name. If there's no such Constant, a new one will be created and returned. Once created, the subsequent calls with the same name will always return the previously created one (i.e. singleton.)

Parameters
name:String

the name of the Constant