Package io.netty.util

Class ConstantPool<T extends Constant<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 java.util.concurrent.ConcurrentMap<java.lang.String,​T> constants  
      private java.util.concurrent.atomic.AtomicInteger nextId  
    • Constructor Summary

      Constructors 
      Constructor Description
      ConstantPool()  
    • Field Detail

      • 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 Detail

      • ConstantPool

        public ConstantPool()
    • Method Detail

      • 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.