Class ConstantPool<T extends Constant<T>>

java.lang.Object
io.netty.util.ConstantPool<T>
Type Parameters:
T - the type of the constant

public abstract class ConstantPool<T extends Constant<T>> extends java.lang.Object
A pool of Constants.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final java.util.concurrent.ConcurrentMap<java.lang.String, T>
     
    private final java.util.concurrent.atomic.AtomicInteger
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private T
    createOrThrow(java.lang.String name)
    Creates constant by name or throws exception.
    boolean
    exists(java.lang.String name)
    Returns true if a AttributeKey exists for the given name.
    private T
    getOrCreate(java.lang.String name)
    Get existing constant by name or creates new one if not exists.
    protected abstract T
    newConstant(int id, java.lang.String name)
     
    newInstance(java.lang.String name)
    Creates a new Constant for the given name or fail with an IllegalArgumentException if a Constant for the given name exists.
    final int
    Deprecated.
    valueOf(java.lang.Class<?> firstNameComponent, java.lang.String secondNameComponent)
    valueOf(java.lang.String name)
    Returns the Constant which is assigned to the specified name.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • constants

      private final java.util.concurrent.ConcurrentMap<java.lang.String, T extends Constant<T>> constants
    • nextId

      private final java.util.concurrent.atomic.AtomicInteger nextId
  • Constructor Details

    • ConstantPool

      public ConstantPool()
  • Method Details

    • valueOf

      public T valueOf(java.lang.Class<?> firstNameComponent, java.lang.String secondNameComponent)
    • valueOf

      public T valueOf(java.lang.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 - the name of the Constant
    • getOrCreate

      private T getOrCreate(java.lang.String name)
      Get existing constant by name or creates new one if not exists. Threadsafe
      Parameters:
      name - the name of the Constant
    • exists

      public boolean exists(java.lang.String name)
      Returns true if a AttributeKey exists for the given name.
    • newInstance

      public T newInstance(java.lang.String name)
      Creates a new Constant for the given name or fail with an IllegalArgumentException if a Constant for the given name exists.
    • createOrThrow

      private T createOrThrow(java.lang.String name)
      Creates constant by name or throws exception. Threadsafe
      Parameters:
      name - the name of the Constant
    • newConstant

      protected abstract T newConstant(int id, java.lang.String name)
    • nextId

      @Deprecated public final int nextId()
      Deprecated.