Top Description Inners Fields Constructors Methods
jnr.constants

public Class ConstantSet

extends AbstractSet<Constant>
Class Inheritance
Imports
jnr.constants.platform.Errno, java.io.InputStream, java.lang.reflect.Field, java.net.URL, java.security.AccessController, .PrivilegedAction, java.util.*, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap

Provides forward and reverse lookup for platform constants

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private static final boolean
private final Set<Enum<E extends Enum<E>>>
private static final ConcurrentMap<String, ConstantSet>
private final Class<Enum<E extends Enum<E>>>
private static final ClassLoader
private static final Object
private volatile Long
private volatile Long
private final Map<String, Constant>
private static volatile Throwable
private final Map<Long, Constant>

Constructor Summary

AccessConstructor and Description
private
ConstantSet(Class<Enum<E extends Enum<E>>>
The Enum subclass to load constants from.
enumClass
)

Creates a new instance of ConstantSet

Method Summary

Modifier and TypeMethod and Description
public boolean
contains(Object
element whose presence in this set is to be tested
o
)

Overrides java.util.AbstractCollection.contains.

Implements java.util.Set.contains, java.util.Collection.contains.

Returns true if this set contains the specified element.
public final Constant

Returns:

A Constant instance.
getConstant
(String
The name of the system constant (e.g. "EINVAL").
name
)

Gets the constant for a name.

public Constant

Returns:

A Constant instance.
getConstant
(long
A system constant value.
value
)

Gets the constant for a value.

public static ConstantSet

Returns:

A ConstantSet.
getConstantSet
(String
The name of the constant set to get.
name
)

Gets a ConstantSet

private static final Class<Enum<E extends Enum<E>>>

Returns:

A Class.
getEnumClass
(String
The name of the constants to locate.
name
)

Gets the Enum class for the constant name space.

private Long
getLongField(String name, long defaultValue)

public String

Returns:

The name of the constant.
getName
(int
The integer value to look up.
value
)

Gets the name of a platform constant value.

public long

Returns:

The integer value of the constant.
getValue
(String
The name of the platform constant to look up (e.g. "EINVAL").
name
)

Gets the integer value of a platform constant.

public Iterator<Constant>
iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Set.iterator, java.util.Collection.iterator.

Returns an iterator over the elements in this set.
private static ConstantSet
public static void
main(String[] args)

public long

Returns:

a long value
maxValue
()

Returns the maximum value in this ConstantSet

public long

Returns:

a long value
minValue
()

Returns the minimum value in this ConstantSet

public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Set.size, java.util.Collection.size.

Returns the number of elements in this set (its cardinality).
Inherited from java.util.AbstractSet:
equalshashCoderemoveAll

Field Detail

CAN_LOAD_RESOURCESback to summary
private static final boolean CAN_LOAD_RESOURCES
constantsback to summary
private final Set<Enum<E extends Enum<E>>> constants
constantSetsback to summary
private static final ConcurrentMap<String, ConstantSet> constantSets
enumClassback to summary
private final Class<Enum<E extends Enum<E>>> enumClass
LOADERback to summary
private static final ClassLoader LOADER
lockback to summary
private static final Object lock
maxValueback to summary
private volatile Long maxValue
minValueback to summary
private volatile Long minValue
nameToConstantback to summary
private final Map<String, Constant> nameToConstant
RESOURCE_READ_ERRORback to summary
private static volatile Throwable RESOURCE_READ_ERROR
valueToConstantback to summary
private final Map<Long, Constant> valueToConstant

Constructor Detail

ConstantSetback to summary
private ConstantSet(Class<Enum<E extends Enum<E>>> enumClass)

Creates a new instance of ConstantSet

Parameters
enumClass:Class<Enum<E extends Enum<E>>>

The Enum subclass to load constants from.

Annotations
@SuppressWarnings:unchecked

Method Detail

containsback to summary
public boolean contains(Object o)

Overrides java.util.AbstractCollection.contains.

Implements java.util.Set.contains, java.util.Collection.contains.

Doc from java.util.Set.contains.

Returns true if this set contains the specified element. More formally, returns true if and only if this set contains an element e such that Objects.equals(o, e).

Parameters
o:Object

element whose presence in this set is to be tested

Returns:boolean

true if this set contains the specified element

Annotations
@Override
getConstantback to summary
public final Constant getConstant(String name)

Gets the constant for a name.

Parameters
name:String

The name of the system constant (e.g. "EINVAL").

Returns:Constant

A Constant instance.

getConstantback to summary
public Constant getConstant(long value)

Gets the constant for a value.

Parameters
value:long

A system constant value.

Returns:Constant

A Constant instance.

getConstantSetback to summary
public static ConstantSet getConstantSet(String name)

Gets a ConstantSet

Parameters
name:String

The name of the constant set to get.

Returns:ConstantSet

A ConstantSet.

getEnumClassback to summary
private static final Class<Enum<E extends Enum<E>>> getEnumClass(String name)

Gets the Enum class for the constant name space.

Parameters
name:String

The name of the constants to locate.

Returns:Class<Enum<E extends Enum<E>>>

A Class.

Annotations
@SuppressWarnings:unchecked
getLongFieldback to summary
private Long getLongField(String name, long defaultValue)
getNameback to summary
public String getName(int value)

Gets the name of a platform constant value.

Parameters
value:int

The integer value to look up.

Returns:String

The name of the constant.

getValueback to summary
public long getValue(String name)

Gets the integer value of a platform constant.

Parameters
name:String

The name of the platform constant to look up (e.g. "EINVAL").

Returns:long

The integer value of the constant.

iteratorback to summary
public Iterator<Constant> iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Set.iterator, java.util.Collection.iterator.

Doc from java.util.Set.iterator.

Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee).

Returns:Iterator<Constant>

an iterator over the elements in this set

Annotations
@Override
loadConstantSetback to summary
private static ConstantSet loadConstantSet(String name)
mainback to summary
public static void main(String[] args)
maxValueback to summary
public long maxValue()

Returns the maximum value in this ConstantSet

Returns:long

a long value

minValueback to summary
public long minValue()

Returns the minimum value in this ConstantSet

Returns:long

a long value

sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Set.size, java.util.Collection.size.

Doc from java.util.Set.size.

Returns the number of elements in this set (its cardinality). If this set contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this set (its cardinality)

Annotations
@Override
jnr.constants back to summary

private final Class ConstantSet.ConstantIterator

extends Object
implements Iterator<Constant>
Class Inheritance
All Implemented Interfaces
java.util.Iterator

Field Summary

Modifier and TypeField and Description
private final Iterator<Enum<E extends Enum<E>>>
private Constant

Constructor Summary

AccessConstructor and Description
pack-priv
ConstantIterator(Collection<Enum<E extends Enum<E>>> constants)

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.
public Constant
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.
public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

itback to summary
private final Iterator<Enum<E extends Enum<E>>> it
nextback to summary
private Constant next

Constructor Detail

ConstantIteratorback to summary
pack-priv ConstantIterator(Collection<Enum<E extends Enum<E>>> constants)

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

nextback to summary
public Constant next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Constant

the next element in the iteration

removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.