Package jnr.constants

Class ConstantSet

  • All Implemented Interfaces:
    java.lang.Iterable<Constant>, java.util.Collection<Constant>, java.util.Set<Constant>

    public class ConstantSet
    extends java.util.AbstractSet<Constant>
    Provides forward and reverse lookup for platform constants
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ConstantSet​(java.lang.Class<java.lang.Enum> enumClass)
      Creates a new instance of ConstantSet
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean contains​(java.lang.Object o)  
      Constant getConstant​(long value)
      Gets the constant for a value.
      Constant getConstant​(java.lang.String name)
      Gets the constant for a name.
      static ConstantSet getConstantSet​(java.lang.String name)
      Gets a ConstantSet
      private static java.lang.Class<java.lang.Enum> getEnumClass​(java.lang.String name)
      Gets the Enum class for the constant name space.
      private java.lang.Long getLongField​(java.lang.String name, long defaultValue)  
      java.lang.String getName​(int value)
      Gets the name of a platform constant value.
      long getValue​(java.lang.String name)
      Gets the integer value of a platform constant.
      java.util.Iterator<Constant> iterator()  
      private static ConstantSet loadConstantSet​(java.lang.String name)  
      static void main​(java.lang.String[] args)  
      long maxValue()
      Returns the maximum value in this ConstantSet
      long minValue()
      Returns the minimum value in this ConstantSet
      int size()  
      • Methods inherited from class java.util.AbstractSet

        equals, hashCode, removeAll
      • Methods inherited from class java.util.AbstractCollection

        add, addAll, clear, containsAll, isEmpty, remove, retainAll, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Set

        add, addAll, clear, containsAll, isEmpty, remove, retainAll, spliterator, toArray, toArray
    • Field Detail

      • nameToConstant

        private final java.util.Map<java.lang.String,​Constant> nameToConstant
      • valueToConstant

        private final java.util.Map<java.lang.Long,​Constant> valueToConstant
      • constants

        private final java.util.Set<java.lang.Enum> constants
      • enumClass

        private final java.lang.Class<java.lang.Enum> enumClass
      • minValue

        private volatile java.lang.Long minValue
      • maxValue

        private volatile java.lang.Long maxValue
      • constantSets

        private static final java.util.concurrent.ConcurrentMap<java.lang.String,​ConstantSet> constantSets
      • lock

        private static final java.lang.Object lock
      • LOADER

        private static final java.lang.ClassLoader LOADER
      • CAN_LOAD_RESOURCES

        private static final boolean CAN_LOAD_RESOURCES
      • RESOURCE_READ_ERROR

        private static volatile java.lang.Throwable RESOURCE_READ_ERROR
    • Constructor Detail

      • ConstantSet

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

      • getConstantSet

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

        private static ConstantSet loadConstantSet​(java.lang.String name)
      • getEnumClass

        private static final java.lang.Class<java.lang.Enum> getEnumClass​(java.lang.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​(java.lang.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​(java.lang.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 java.lang.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 java.lang.Long getLongField​(java.lang.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 java.util.Iterator<Constant> iterator()
        Specified by:
        iterator in interface java.util.Collection<Constant>
        Specified by:
        iterator in interface java.lang.Iterable<Constant>
        Specified by:
        iterator in interface java.util.Set<Constant>
        Specified by:
        iterator in class java.util.AbstractCollection<Constant>
      • size

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

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

        public static void main​(java.lang.String[] args)