Package jnr.constants

Class ConstantSet

All Implemented Interfaces:
Iterable<Constant>, Collection<Constant>, Set<Constant>

public class ConstantSet extends AbstractSet<Constant>
Provides forward and reverse lookup for platform constants
  • Field Details

    • nameToConstant

      private final Map<String,Constant> nameToConstant
    • valueToConstant

      private final Map<Long,Constant> valueToConstant
    • constants

      private final Set<Enum> constants
    • enumClass

      private final Class<Enum> enumClass
    • minValue

      private volatile Long minValue
    • maxValue

      private volatile Long maxValue
    • constantSets

      private static final ConcurrentMap<String,ConstantSet> constantSets
    • lock

      private static final Object lock
    • LOADER

      private static final ClassLoader LOADER
    • CAN_LOAD_RESOURCES

      private static final boolean CAN_LOAD_RESOURCES
    • RESOURCE_READ_ERROR

      private static volatile Throwable RESOURCE_READ_ERROR
  • Constructor Details

    • ConstantSet

      private ConstantSet(Class<Enum> enumClass)
      Creates a new instance of ConstantSet
      Parameters:
      enumClass - The Enum subclass to load constants from.
  • Method Details

    • getConstantSet

      public static ConstantSet getConstantSet(String name)
      Gets a ConstantSet
      Parameters:
      name - The name of the constant set to get.
      Returns:
      A ConstantSet.
    • loadConstantSet

      private static ConstantSet loadConstantSet(String name)
    • getEnumClass

      private static final Class<Enum> getEnumClass(String name)
      Gets the Enum class for the constant name space.
      Parameters:
      name - The name of the constants to locate.
      Returns:
      A Class.
    • getConstant

      public final Constant getConstant(String name)
      Gets the constant for a name.
      Parameters:
      name - The name of the system constant (e.g. "EINVAL").
      Returns:
      A Constant instance.
    • getConstant

      public Constant getConstant(long value)
      Gets the constant for a value.
      Parameters:
      value - A system constant value.
      Returns:
      A Constant instance.
    • getValue

      public long getValue(String name)
      Gets the integer value of a platform constant.
      Parameters:
      name - The name of the platform constant to look up (e.g. "EINVAL").
      Returns:
      The integer value of the constant.
    • getName

      public String getName(int value)
      Gets the name of a platform constant value.
      Parameters:
      value - The integer value to look up.
      Returns:
      The name of the constant.
    • getLongField

      private Long getLongField(String name, long defaultValue)
    • minValue

      public long minValue()
      Returns the minimum value in this ConstantSet
      Returns:
      a long value
    • maxValue

      public long maxValue()
      Returns the maximum value in this ConstantSet
      Returns:
      a long value
    • iterator

      public Iterator<Constant> iterator()
      Specified by:
      iterator in interface Collection<Constant>
      Specified by:
      iterator in interface Iterable<Constant>
      Specified by:
      iterator in interface Set<Constant>
      Specified by:
      iterator in class AbstractCollection<Constant>
    • size

      public int size()
      Specified by:
      size in interface Collection<Constant>
      Specified by:
      size in interface Set<Constant>
      Specified by:
      size in class AbstractCollection<Constant>
    • contains

      public boolean contains(Object o)
      Specified by:
      contains in interface Collection<Constant>
      Specified by:
      contains in interface Set<Constant>
      Overrides:
      contains in class AbstractCollection<Constant>
    • main

      public static void main(String[] args)