Class Attributes
java.lang.Object
java.util.jar.Attributes
- All Implemented Interfaces:
Cloneable, Map<Object,Object>
public class Attributes extends Object implements Map<Object,Object>, Cloneable
The Attributes class maps Manifest attribute names to associated string values. Valid attribute names are case-insensitive, are restricted to the ASCII characters in the set [0-9a-zA-Z_-], and cannot exceed 70 characters in length. There must be a colon and a SPACE after the name; the combined length will not exceed 72 characters. Attribute values can contain any characters and will be UTF8-encoded when written to the output stream. See the JAR File Specification for more information about valid attribute names and values.
This map and its views have a predictable iteration order, namely the order that keys were inserted into the map, as with LinkedHashMap.
- Since:
- 1.2
- External Specifications
- See Also:
Nested Class Summary
| Modifier and Type | Class | Description |
|---|---|---|
static class |
Attributes.Name |
The Attributes.Name class represents an attribute name stored in this Map. |
Field Summary
| Modifier and Type | Field | Description |
|---|---|---|
protected Map |
map |
The attribute name-value mappings. |
Constructor Summary
| Constructor | Description |
|---|---|
Attributes() |
Constructs a new, empty Attributes object with default size. |
Attributes |
Constructs a new, empty Attributes object with the specified initial size. |
Attributes |
Constructs a new Attributes object with the same attribute name-value mappings as in the specified Attributes. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
void |
clear() |
Removes all attributes from this Map. |
Object |
clone() |
Returns a copy of the Attributes, implemented as follows: |
boolean |
containsKey |
Returns true if this Map contains the specified attribute name (key). |
boolean |
containsValue |
Returns true if this Map maps one or more attribute names (keys) to the specified value. |
Set |
entrySet() |
Returns a Collection view of the attribute name-value mappings contained in this Map. |
boolean |
equals |
Compares the specified object to the underlying map for equality. |
Object |
get |
Returns the value of the specified attribute name, or null if the attribute name was not found. |
String |
getValue |
Returns the value of the specified attribute name, specified as a string, or null if the attribute was not found. |
String |
getValue |
Returns the value of the specified Attributes.Name, or null if the attribute was not found. |
int |
hashCode() |
Returns the hash code value for this Map. |
boolean |
isEmpty() |
Returns true if this Map contains no attributes. |
Set |
keySet() |
Returns a Set view of the attribute names (keys) contained in this Map. |
Object |
put |
Associates the specified value with the specified attribute name (key) in this Map. |
void |
putAll |
Copies all of the attribute name-value mappings from the specified Attributes to this Map. |
String |
putValue |
Associates the specified value with the specified attribute name, specified as a String. |
Object |
remove |
Removes the attribute with the specified name (key) from this Map. |
int |
size() |
Returns the number of attributes in this Map. |
Collection |
values() |
Returns a Collection view of the attribute values contained in this Map. |
Methods declared in class Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait | Modifier and Type | Method | Description |
|---|---|---|
protected void |
finalize() |
Deprecated, for removal: This API element is subject to removal in a future version. Finalization is deprecated and subject to removal in a future release. |
final Class |
getClass() |
Returns the runtime class of this Object. |
final void |
notify() |
Wakes up a single thread that is waiting on this object's monitor. |
final void |
notifyAll() |
Wakes up all threads that are waiting on this object's monitor. |
String |
toString() |
Returns a string representation of the object. |
final void |
wait() |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
Methods declared in interface Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll | Modifier and Type | Method | Description |
|---|---|---|
default Object |
compute |
Attempts to compute a mapping for the specified key and its current mapped value, or null if there is no current mapping (optional operation). |
default Object |
computeIfAbsent |
If the specified key is not already associated with a value (or is mapped to null), attempts to compute its value using the given mapping function and enters it into this map unless null (optional operation). |
default Object |
computeIfPresent |
If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value (optional operation). |
default void |
forEach |
Performs the given action for each entry in this map until all entries have been processed or the action throws an exception. |
default Object |
getOrDefault |
Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key. |
default Object |
merge |
If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value (optional operation). |
default Object |
putIfAbsent |
If the specified key is not already associated with a value (or is mapped to null) associates it with the given value and returns null, else returns the current value (optional operation). |
default boolean |
remove |
Removes the entry for the specified key only if it is currently mapped to the specified value (optional operation). |
default Object |
replace |
Replaces the entry for the specified key only if it is currently mapped to some value (optional operation). |
default boolean |
replace |
Replaces the entry for the specified key only if currently mapped to the specified value (optional operation). |
default void |
replaceAll |
Replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception (optional operation). |
Field Details
map
protected Map<Object,Object> map
The attribute name-value mappings.
Constructor Details
Attributes
public Attributes()
Constructs a new, empty Attributes object with default size.
Attributes
public Attributes(int size)
Constructs a new, empty Attributes object with the specified initial size.
- Parameters:
-
size- the initial number of attributes
Attributes
public Attributes(Attributes attr)
Constructs a new Attributes object with the same attribute name-value mappings as in the specified Attributes.
- Parameters:
-
attr- the specified Attributes
Method Details
get
getValue
public String getValue(String name)
Returns the value of the specified attribute name, specified as a string, or null if the attribute was not found. The attribute name is case-insensitive.
This method is defined as:
return (String)get(new Attributes.Name((String)name));
- Parameters:
-
name- the attribute name as a string - Returns:
- the String value of the specified attribute name, or null if not found.
- Throws:
-
IllegalArgumentException- if the attribute name is invalid
getValue
public String getValue(Attributes.Name name)
Returns the value of the specified Attributes.Name, or null if the attribute was not found.
This method is defined as:
return (String)get(name);
- Parameters:
-
name- the Attributes.Name object - Returns:
- the String value of the specified Attribute.Name, or null if not found.
put
public Object put(Object name, Object value)
Associates the specified value with the specified attribute name (key) in this Map. If the Map previously contained a mapping for the attribute name, the old value is replaced.
- Specified by:
-
putin interfaceMap<Object,Object> - Parameters:
-
name- the attribute name -
value- the attribute value - Returns:
- the previous value of the attribute, or null if none
- Throws:
-
ClassCastException- if the name is not a Attributes.Name or the value is not a String
putValue
public String putValue(String name, String value)
Associates the specified value with the specified attribute name, specified as a String. The attributes name is case-insensitive. If the Map previously contained a mapping for the attribute name, the old value is replaced.
This method is defined as:
return (String)put(new Attributes.Name(name), value);
- Parameters:
-
name- the attribute name as a string -
value- the attribute value - Returns:
- the previous value of the attribute, or null if none
- Throws:
-
IllegalArgumentException- if the attribute name is invalid
remove
public Object remove(Object name)
Removes the attribute with the specified name (key) from this Map. Returns the previous attribute value, or null if none.
containsValue
public boolean containsValue(Object value)
Returns true if this Map maps one or more attribute names (keys) to the specified value.
- Specified by:
-
containsValuein interfaceMap<Object,Object> - Parameters:
-
value- the attribute value - Returns:
- true if this Map maps one or more attribute names to the specified value
containsKey
public boolean containsKey(Object name)
Returns true if this Map contains the specified attribute name (key).
- Specified by:
-
containsKeyin interfaceMap<Object,Object> - Parameters:
-
name- the attribute name - Returns:
- true if this Map contains the specified attribute name
putAll
public void putAll(Map<?,?> attr)
Copies all of the attribute name-value mappings from the specified Attributes to this Map. Duplicate mappings will be replaced.
- Specified by:
-
putAllin interfaceMap<Object,Object> - Parameters:
-
attr- the Attributes to be stored in this map - Throws:
-
ClassCastException- if attr is not an Attributes
clear
size
isEmpty
keySet
values
entrySet
equals
public boolean equals(Object o)
Compares the specified object to the underlying map for equality. Returns true if the given object is also a Map and the two maps represent the same mappings.
hashCode
clone
public Object clone()
Returns a copy of the Attributes, implemented as follows:
public Object clone() { return new Attributes(this); }
Since the attribute names and values are themselves immutable, the Attributes returned can be safely modified without affecting the original.
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.