Qwylt

java.lang.module
Class AttributeSource

java.lang.Object
  extended by java.lang.module.AttributeSource
Direct Known Subclasses:
AttributeMatcher, ModuleArchive, ScopedName

public abstract class AttributeSource
extends java.lang.Object

A named container for immutable attributes.

Since:
Dec 13, 2008
Author:
Bryan Atsatt

Field Summary
static java.util.Map<java.lang.String,java.lang.String> NO_ATTRIBUTES
           
static java.lang.String SERVICE_IMPLEMENTATION_KEY
          The attribute key specifying a service implementation class.
 
Constructor Summary
AttributeSource()
           
 
Method Summary
protected  void appendAttributes(java.lang.StringBuilder builder)
           
static java.util.List<java.lang.String> asList(java.lang.String value)
          Converts the value to a list.
abstract  boolean containsAttribute(java.lang.String key)
          Returns true if the specified attribute is present in this instance.
 boolean containsAttributes(java.util.Map<java.lang.String,java.lang.String> attributes)
          Returns true if all of the specified attributes are present in this instance and have values that are equal.
abstract  java.lang.String getAttribute(java.lang.String key)
          Returns the attribute value.
 java.util.List<java.lang.String> getAttributeAsList(java.lang.String key)
          Returns the attribute value as a list.
abstract  java.util.Set<java.lang.String> getAttributeKeys()
          Returns an unmodifiable set of the attribute keys.
abstract  java.util.Map<java.lang.String,java.lang.String> getAttributes()
          Returns an unmodifiable map of the attributes.
abstract  java.lang.String getName()
          Returns the name of this instance.
static
<T> java.util.List<T>
modifiableList(T value)
          Returns a new modifiable but non-growable singleton list.
static
<K,V> java.util.Map<K,V>
unmodifiableMap(java.util.Map<? extends K,? extends V> map)
          Ensure that the specified map is unmodifiable, wrapping it if required.
static java.util.Map<java.lang.String,java.lang.String> unmodifiableMap(java.lang.String... attributePairs)
          Returns a new unmodifiable map from the specified attribute pairs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_ATTRIBUTES

public static final java.util.Map<java.lang.String,java.lang.String> NO_ATTRIBUTES

SERVICE_IMPLEMENTATION_KEY

public static final java.lang.String SERVICE_IMPLEMENTATION_KEY
The attribute key specifying a service implementation class.

See Also:
Constant Field Values
Constructor Detail

AttributeSource

public AttributeSource()
Method Detail

asList

public static java.util.List<java.lang.String> asList(java.lang.String value)
Converts the value to a list. If the value does not begin with '{' and end with '}' it is returned as a singleton list; otherwise it is assumed to be a comma separated list of values. List values may be surrounded by quotes (e.g. to embed a comma) and will be removed in the result. For example:
     List list = asList("{a, 'b,c', \"d, e\"}");
     assert(list.get(0).equals("a"));
     assert(list.get(1).equals("b,c"));
     assert(list.get(2).equals("d, e"));
 

Parameters:
value - The value.
Returns:
The list.

unmodifiableMap

public static <K,V> java.util.Map<K,V> unmodifiableMap(java.util.Map<? extends K,? extends V> map)
Ensure that the specified map is unmodifiable, wrapping it if required.

Type Parameters:
K - The key type.
V - The value type.
Parameters:
map - The map.
Returns:
The unmodifiable map.

unmodifiableMap

public static java.util.Map<java.lang.String,java.lang.String> unmodifiableMap(java.lang.String... attributePairs)
Returns a new unmodifiable map from the specified attribute pairs.

Parameters:
attributePairs - The key/value pairs, must be an even length.
Returns:
The unmodifiable map.
Throws:
java.lang.IllegalArgumentException - If attributePairs.length is not even.

modifiableList

public static <T> java.util.List<T> modifiableList(T value)
Returns a new modifiable but non-growable singleton list.

Parameters:
value - The list value.
Returns:
The list.

getName

public abstract java.lang.String getName()
Returns the name of this instance.

Returns:
the name of this instance.

containsAttribute

public abstract boolean containsAttribute(java.lang.String key)
Returns true if the specified attribute is present in this instance.

Parameters:
key - The attribute key.
Returns:
true if the attribute is present.

getAttribute

public abstract java.lang.String getAttribute(java.lang.String key)
Returns the attribute value.

Parameters:
key - The attribute key.
Returns:
The attribute value or null if the key is unknown or if the attribute value is null.

getAttributeAsList

public java.util.List<java.lang.String> getAttributeAsList(java.lang.String key)
Returns the attribute value as a list. Same as calling asList(getAttribute(key)); however, subclasses may override and change the list format.

Parameters:
key - The attribute key.
Returns:
The attribute values. Will be empty if none.

getAttributeKeys

public abstract java.util.Set<java.lang.String> getAttributeKeys()
Returns an unmodifiable set of the attribute keys.

Returns:
an unmodifiable set of attribute keys.

getAttributes

public abstract java.util.Map<java.lang.String,java.lang.String> getAttributes()
Returns an unmodifiable map of the attributes.

Returns:
an unmodifiable map of attributes.

containsAttributes

public boolean containsAttributes(java.util.Map<java.lang.String,java.lang.String> attributes)
Returns true if all of the specified attributes are present in this instance and have values that are equal.

Parameters:
attributes - The attributes to check against this instance.
Returns:
true if all attributes are contained.

appendAttributes

protected void appendAttributes(java.lang.StringBuilder builder)

Qwylt

Send comments or questions to Bryan Atsatt