java.util.jar
Class Attributes

java.lang.Object
  extended by java.util.jar.Attributes
All Implemented Interfaces:
Cloneable, Map<Object,Object>

public class Attributes
extends Object
implements Cloneable, Map<Object,Object>

Represents attribute name/value pairs from a Manifest as a Map. The names of an attribute are represented by the Attributes.Name class and should confirm to the restrictions described in that class. Note that the Map interface that Attributes implements allows you to put names and values into the attribute that don't follow these restriction (and are not really Atrribute.Names, but if you do that it might cause undefined behaviour later).

If you use the constants defined in the inner class Name then you can be sure that you always access the right attribute names. This makes manipulating the Attributes more or less type safe.

Most of the methods are wrappers to implement the Map interface. The really useful and often used methods are getValue(Name) and getValue(String). If you actually want to set attributes you may want to use the putValue(String, String) method (sorry there is no public type safe putValue(Name, String) method).

See Also:
Attributes.Name

Nested Class Summary
static class Attributes.Name
          Represents a name of a Manifest Attribute.
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
protected  Map<Object,Object> map
          The map that holds all the attribute name/value pairs.
 
Constructor Summary
Attributes()
          Creates an empty Attributes map.
Attributes(Attributes attr)
          Creates an Attributes map with the initial values taken from another Attributes map.
Attributes(int size)
          Creates an empty Attributes map with the given initial size.
 
Method Summary
 void clear()
          Removes all attributes.
 Object clone()
          Return a clone of this attribute map.
 boolean containsKey(Object attrName)
          Checks to see if there is an attribute with the specified name.
 boolean containsValue(Object attrValue)
          Checks to see if there is an attribute name with the specified value.
 Set<Map.Entry<Object,Object>> entrySet()
          Gives a Set of attribute name and values pairs as MapEntries.
 boolean equals(Object o)
          Checks to see if two Attributes are equal.
 Object get(Object attrName)
          Gets the value of a specified attribute name.
 String getValue(Attributes.Name name)
          Gets the value of the given attribute name.
 String getValue(String name)
          Gets the value of an attribute name given as a String.
 int hashCode()
          Returns the hashcode of the attribute name/value map.
 boolean isEmpty()
          Returns true if there are no attributes set, false otherwise.
 Set<Object> keySet()
          Gives a Set of all the values of defined attribute names.
 Object put(Object name, Object value)
          Adds or replaces a attribute name/value pair.
 void putAll(Map<?,?> attr)
          Adds or replaces all attribute name/value pairs from another Attributes object to this one.
 String putValue(String name, String value)
          Stores an attribute name (represented by a String) and value in this Attributes map.
 Object remove(Object name)
          Remove a attribute name/value pair.
 int size()
          Returns the number of defined attribute name/value pairs.
 Collection<Object> values()
          Returns all the values of the defined attribute name/value pairs as a Collection.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

map

protected Map<Object,Object> map
The map that holds all the attribute name/value pairs. In this implementation it is actually a Hashtable, but that can be different in other implementations.

Constructor Detail

Attributes

public Attributes()
Creates an empty Attributes map.


Attributes

public Attributes(int size)
Creates an empty Attributes map with the given initial size.

Parameters:
size - the initial size of the underlying map

Attributes

public Attributes(Attributes attr)
Creates an Attributes map with the initial values taken from another Attributes map.

Parameters:
attr - Attributes map to take the initial values from
Method Detail

getValue

public String getValue(String name)
Gets the value of an attribute name given as a String.

Parameters:
name - a String describing the Name to look for
Returns:
the value gotten from the map of null when not found

getValue

public String getValue(Attributes.Name name)
Gets the value of the given attribute name.

Parameters:
name - the Name to look for
Returns:
the value gotten from the map of null when not found

putValue

public String putValue(String name,
                       String value)
Stores an attribute name (represented by a String) and value in this Attributes map. When the (case insensitive string) name already exists the value is replaced and the old value is returned.

Parameters:
name - a (case insensitive) String representation of the attribite name to add/replace
value - the (new) value of the attribute name

clone

public Object clone()
Return a clone of this attribute map.

Overrides:
clone in class Object
Returns:
a copy of the Object
See Also:
Cloneable

clear

public void clear()
Removes all attributes.

Specified by:
clear in interface Map<Object,Object>

containsKey

public boolean containsKey(Object attrName)
Checks to see if there is an attribute with the specified name. XXX - what if the object is a String?

Specified by:
containsKey in interface Map<Object,Object>
Parameters:
attrName - the name of the attribute to check
Returns:
true if there is an attribute with the specified name, false otherwise

containsValue

public boolean containsValue(Object attrValue)
Checks to see if there is an attribute name with the specified value.

Specified by:
containsValue in interface Map<Object,Object>
Parameters:
attrValue - the value of a attribute to check
Returns:
true if there is an attribute name with the specified value, false otherwise

entrySet

public Set<Map.Entry<Object,Object>> entrySet()
Gives a Set of attribute name and values pairs as MapEntries.

Specified by:
entrySet in interface Map<Object,Object>
Returns:
a set of attribute name value pairs
See Also:
Map.Entry, Map.entrySet()

equals

public boolean equals(Object o)
Checks to see if two Attributes are equal. The supplied object must be a real instance of Attributes and contain the same attribute name/value pairs.

Specified by:
equals in interface Map<Object,Object>
Overrides:
equals in class Object
Parameters:
o - another Attribute object which should be checked for equality
Returns:
true if the object is an instance of Attributes and contains the same name/value pairs, false otherwise
See Also:
Object.hashCode()

get

public Object get(Object attrName)
Gets the value of a specified attribute name. XXX - what if the object is a String?

Specified by:
get in interface Map<Object,Object>
Parameters:
attrName - the name of the attribute we want the value of
Returns:
the value of the specified attribute name or null when there is no such attribute name
See Also:
Map.containsKey(Object)

hashCode

public int hashCode()
Returns the hashcode of the attribute name/value map.

Specified by:
hashCode in interface Map<Object,Object>
Overrides:
hashCode in class Object
Returns:
the hash code for this Object
See Also:
Object.equals(Object), System.identityHashCode(Object)

isEmpty

public boolean isEmpty()
Returns true if there are no attributes set, false otherwise.

Specified by:
isEmpty in interface Map<Object,Object>
Returns:
true if the map is empty

keySet

public Set<Object> keySet()
Gives a Set of all the values of defined attribute names.

Specified by:
keySet in interface Map<Object,Object>
Returns:
the set view of all keys

put

public Object put(Object name,
                  Object value)
Adds or replaces a attribute name/value pair. XXX - What if the name is a string? What if the name is neither a Name nor a String? What if the value is not a string?

Specified by:
put in interface Map<Object,Object>
Parameters:
name - the name of the attribute
value - the (new) value of the attribute
Returns:
the old value of the attribute or null when there was no old attribute with this name
See Also:
Map.containsKey(Object)

putAll

public void putAll(Map<?,?> attr)
Adds or replaces all attribute name/value pairs from another Attributes object to this one. The supplied Map must be an instance of Attributes.

Specified by:
putAll in interface Map<Object,Object>
Parameters:
attr - the Attributes object to merge with this one
Throws:
ClassCastException - if the supplied map is not an instance of Attributes
See Also:
Map.put(Object, Object)

remove

public Object remove(Object name)
Remove a attribute name/value pair. XXX - What if the name is a String?

Specified by:
remove in interface Map<Object,Object>
Parameters:
name - the name of the attribute name/value pair to remove
Returns:
the old value of the attribute or null if the attribute didn't exist

size

public int size()
Returns the number of defined attribute name/value pairs.

Specified by:
size in interface Map<Object,Object>
Returns:
the number of mappings

values

public Collection<Object> values()
Returns all the values of the defined attribute name/value pairs as a Collection.

Specified by:
values in interface Map<Object,Object>
Returns:
the collection view of all values