java.util.jar
Class Attributes
java.lang.Object
|
+--java.util.jar.Attributes
All Implemented Interfaces:
Cloneable, Map
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).
Author:- Mark Wielaard (mark@klomp.org)
See Also:
map
protected Map 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.
Attributes
public Attributes()
Creates an empty Attributes map.
Attributes
public Attributes(int size)
Creates an empty Attributes map with the given initial size.
Parameters:
Attributes
public Attributes(java.util.jar.Attributes attr)
Creates an Attributes map with the initial values taken from another
Attributes map.
Parameters:
clear
public void clear()
Removes all attributes.
clone
public Object clone()
Return a clone of this attribute map.
containsKey
public boolean containsKey(java.lang.Object attrName)
Checks to see if there is an attribute with the specified name.
XXX - what if the object is a String?
Parameters:
Returns:
- true if there is an attribute with the specified name, false
otherwise
containsValue
public boolean containsValue(java.lang.Object attrValue)
Checks to see if there is an attribute name with the specified value.
Parameters:
Returns:
- true if there is an attribute name with the specified value,
false otherwise
entrySet
public Set entrySet()
Gives a Set of attribute name and values pairs as MapEntries.
Returns:
- a set of attribute name value pairs
See Also:
equals
public boolean equals(java.lang.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.
Parameters:
Returns:
- true if the object is an instance of Attributes and contains the
same name/value pairs, false otherwise
get
public Object get(java.lang.Object attrName)
Gets the value of a specified attribute name.
XXX - what if the object is a String?
Parameters:
Returns:
- the value of the specified attribute name or null when there is
no such attribute name
getValue
public String getValue(java.lang.String name)
Gets the value of an attribute name given as a String.
Parameters:
Returns:
- the value gotten from the map of null when not found
getValue
public String getValue(java.util.jar.Attributes.Name name)
Gets the value of the given attribute name.
Parameters:
Returns:
- the value gotten from the map of null when not found
hashCode
public int hashCode()
Returns the hashcode of the attribute name/value map.
isEmpty
public boolean isEmpty()
Returns true if there are no attributes set, false otherwise.
keySet
public Set keySet()
Gives a Set of all the values of defined attribute names.
put
public Object put(java.lang.Object name, java.lang.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?
Parameters:
Returns:
- the old value of the attribute or null when there was no old
attribute with this name
putAll
public void putAll(java.util.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.
Parameters:
Throws:
putValue
public String putValue(java.lang.String name, java.lang.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:
remove
public Object remove(java.lang.Object name)
Remove a attribute name/value pair.
XXX - What if the name is a String?
Parameters:
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.
values
public Collection values()
Returns all the values of the defined attribute name/value pairs as a
Collection.
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)
andgetValue(String)
. If you actually want to set attributes you may want to use theputValue(String, String)
method (sorry there is no public type safeputValue(Name, String)
method).