Attributes

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

java.lang.Object
   ↳ java.util.jar.Attributes


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.

See also:

Summary

Nested classes

class Attributes.Name

The Attributes.Name class represents an attribute name stored in this Map. 

Fields

protected Map<ObjectObject> map

The attribute name-value mappings.

Public constructors

Attributes()

Constructs a new, empty Attributes object with default size.

Attributes(int size)

Constructs a new, empty Attributes object with the specified initial size.

Attributes(Attributes attr)

Constructs a new Attributes object with the same attribute name-value mappings as in the specified Attributes.

Public methods

void clear()

Removes all attributes from this Map.

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.

boolean containsKey(Object name)

Returns true if this Map contains the specified attribute name (key).

boolean containsValue(Object value)

Returns true if this Map maps one or more attribute names (keys) to the specified value.

Set<Entry<ObjectObject>> entrySet()

Returns a Collection view of the attribute name-value mappings contained in this Map.

boolean equals(Object o)

Compares the specified object to the underlying map for equality.

Object get(Object name)

Returns the value of the specified attribute name, or null if the attribute name was not found.

String getValue(String name)

Returns the value of the specified attribute name, specified as a string, or null if the attribute was not found.

String getValue(Attributes.Name name)

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<Object> keySet()

Returns a Set view of the attribute names (keys) contained in this Map.

Object put(Object name, Object value)

Associates the specified value with the specified attribute name (key) in this Map.

void putAll(Map<?, ?> attr)

Copies all of the attribute name-value mappings from the specified Attributes to this Map.

String putValue(String name, String value)

Associates the specified value with the specified attribute name, specified as a String.

Object remove(Object name)

Removes the attribute with the specified name (key) from this Map.

int size()

Returns the number of attributes in this Map.

Collection<Object> values()

Returns a Collection view of the attribute values contained in this Map.

Inherited methods

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the 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(long timeoutMillis, int nanos)

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(long timeoutMillis)

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.

abstract void clear()

Removes all of the mappings from this map (optional operation).

default Object compute(Object key, BiFunction<? super K, ? super V, ? extends V> remappingFunction)

Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping).

default Object computeIfAbsent(Object key, Function<? super K, ? extends V> mappingFunction)

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.

default Object computeIfPresent(Object key, BiFunction<? super K, ? super V, ? extends V> remappingFunction)

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.

abstract boolean containsKey(Object key)

Returns true if this map contains a mapping for the specified key.

abstract boolean containsValue(Object value)

Returns true if this map maps one or more keys to the specified value.

static <K, V> Map<ObjectObject> copyOf(Map<? extends K, ? extends V> map)

Returns an unmodifiable Map containing the entries of the given Map.

static <K, V> Entry<ObjectObject> entry(Object k, Object v)

Returns an unmodifiable Entry containing the given key and value.

abstract Set<Entry<ObjectObject>> entrySet()

Returns a Set view of the mappings contained in this map.

abstract boolean equals(Object o)

Compares the specified object with this map for equality.

default void forEach(BiConsumer<? super K, ? super V> action)

Performs the given action for each entry in this map until all entries have been processed or the action throws an exception.

abstract Object get(Object key)

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

default Object getOrDefault(Object key, Object defaultValue)

Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.

abstract int hashCode()

Returns the hash code value for this map.

abstract boolean isEmpty()

Returns true if this map contains no key-value mappings.

abstract Set<Object> keySet()

Returns a Set view of the keys contained in this map.

default Object merge(Object key, Object value, BiFunction<? super V, ? super V, ? extends V> remappingFunction)

If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value.

static <K, V> Map<ObjectObject> of(Object k1, Object v1, Object k2, Object v2, Object k3, Object v3, Object k4, Object v4, Object k5, Object v5)

Returns an unmodifiable map containing five mappings.

static <K, V> Map<ObjectObject> of(Object k1, Object v1, Object k2, Object v2, Object k3, Object v3, Object k4, Object v4)

Returns an unmodifiable map containing four mappings.

static <K, V> Map<ObjectObject> of(Object k1, Object v1)

Returns an unmodifiable map containing a single mapping.

static <K, V> Map<ObjectObject> of(Object k1, Object v1, Object k2, Object v2, Object k3, Object v3, Object k4, Object v4, Object k5, Object v5, Object k6, Object v6, Object k7, Object v7, Object k8, Object v8)

Returns an unmodifiable map containing eight mappings.

static <K, V> Map<ObjectObject> of(Object k1, Object v1, Object k2, Object v2)

Returns an unmodifiable map containing two mappings.

static <K, V> Map<ObjectObject> of(Object k1, Object v1, Object k2, Object v2, Object k3, Object v3)

Returns an unmodifiable map containing three mappings.

static <K, V> Map<ObjectObject> of()

Returns an unmodifiable map containing zero mappings.

static <K, V> Map<ObjectObject> of(Object k1, Object v1, Object k2, Object v2, Object k3, Object v3, Object k4, Object v4, Object k5, Object v5, Object k6, Object v6, Object k7, Object v7, Object k8, Object v8, Object k9, Object v9)

Returns an unmodifiable map containing nine mappings.

static <K, V> Map<ObjectObject> of(Object k1, Object v1, Object k2, Object v2, Object k3, Object v3, Object k4, Object v4, Object k5, Object v5, Object k6, Object v6)

Returns an unmodifiable map containing six mappings.

static <K, V> Map<ObjectObject> of(Object k1, Object v1, Object k2, Object v2, Object k3, Object v3, Object k4, Object v4, Object k5, Object v5, Object k6, Object v6, Object k7, Object v7)

Returns an unmodifiable map containing seven mappings.

static <K, V> Map<ObjectObject> of(Object k1, Object v1, Object k2, Object v2, Object k3, Object v3, Object k4, Object v4, Object k5, Object v5, Object k6, Object v6, Object k7, Object v7, Object k8, Object v8, Object k9, Object v9, Object k10, Object v10)

Returns an unmodifiable map containing ten mappings.

static <K, V> Map<ObjectObject> ofEntries(Entry...<? extends K, ? extends V> entries)

Returns an unmodifiable map containing keys and values extracted from the given entries.

abstract Object put(Object key, Object value)

Associates the specified value with the specified key in this map (optional operation).

abstract void putAll(Map<? extends K, ? extends V> m)

Copies all of the mappings from the specified map to this map (optional operation).

default Object putIfAbsent(Object key, Object value)

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.

default boolean remove(Object key, Object value)

Removes the entry for the specified key only if it is currently mapped to the specified value.

abstract Object remove(Object key)

Removes the mapping for a key from this map if it is present (optional operation).

default boolean replace(Object key, Object oldValue, Object newValue)

Replaces the entry for the specified key only if currently mapped to the specified value.

default Object replace(Object key, Object value)

Replaces the entry for the specified key only if it is currently mapped to some value.

default void replaceAll(BiFunction<? super K, ? super V, ? extends V> function)

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.

abstract int size()

Returns the number of key-value mappings in this map.

abstract Collection<Object> values()

Returns a Collection view of the values contained in this map.

Fields

map

Added in API level 1
protected Map<ObjectObject> map

The attribute name-value mappings.

Public constructors

Attributes

Added in API level 1
public Attributes ()

Constructs a new, empty Attributes object with default size.

Attributes

Added in API level 1
public Attributes (int size)

Constructs a new, empty Attributes object with the specified initial size.

Parameters
size int: the initial number of attributes

Attributes

Added in API level 1
public Attributes (Attributes attr)

Constructs a new Attributes object with the same attribute name-value mappings as in the specified Attributes.

Parameters
attr Attributes: the specified Attributes

Public methods

clear

Added in API level 1
public void clear ()

Removes all attributes from this Map.

clone

Added in API level 1
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.

Returns
Object a clone of this instance.

containsKey

Added in API level 1
public boolean containsKey (Object name)

Returns true if this Map contains the specified attribute name (key).

Parameters
name Object: the attribute name

Returns
boolean true if this Map contains the specified attribute name

containsValue

Added in API level 1
public boolean containsValue (Object value)

Returns true if this Map maps one or more attribute names (keys) to the specified value.

Parameters
value Object: the attribute value

Returns
boolean true if this Map maps one or more attribute names to the specified value

entrySet

Added in API level 1
public Set<Entry<ObjectObject>> entrySet ()

Returns a Collection view of the attribute name-value mappings contained in this Map.

Returns
Set<Entry<ObjectObject>> a set view of the mappings contained in this map

equals

Added in API level 1
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.

Parameters
o Object: the Object to be compared

Returns
boolean true if the specified Object is equal to this Map

get

Added in API level 1
public Object get (Object name)

Returns the value of the specified attribute name, or null if the attribute name was not found.

Parameters
name Object: the attribute name

Returns
Object the value of the specified attribute name, or null if not found.

getValue

Added in API level 1
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 String: the attribute name as a string

Returns
String the String value of the specified attribute name, or null if not found.

Throws
IllegalArgumentException if the attribute name is invalid

getValue

Added in API level 1
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 Attributes.Name: the Attributes.Name object

Returns
String the String value of the specified Attribute.Name, or null if not found.

hashCode

Added in API level 1
public int hashCode ()

Returns the hash code value for this Map.

Returns
int a hash code value for this object.

isEmpty

Added in API level 1
public boolean isEmpty ()

Returns true if this Map contains no attributes.

Returns
boolean true if this map contains no key-value mappings

keySet

Added in API level 1
public Set<Object> keySet ()

Returns a Set view of the attribute names (keys) contained in this Map.

Returns
Set<Object> a set view of the keys contained in this map

put

Added in API level 1
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.

Parameters
name Object: the attribute name

value Object: the attribute value

Returns
Object 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

putAll

Added in API level 1
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.

Parameters
attr Map: the Attributes to be stored in this map

Throws
ClassCastException if attr is not an Attributes

putValue

Added in API level 1
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 String: the attribute name as a string

value String: the attribute value

Returns
String the previous value of the attribute, or null if none

Throws
IllegalArgumentException if the attribute name is invalid

remove

Added in API level 1
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.

Parameters
name Object: attribute name

Returns
Object the previous value of the attribute, or null if none

size

Added in API level 1
public int size ()

Returns the number of attributes in this Map.

Returns
int the number of key-value mappings in this map

values

Added in API level 1
public Collection<Object> values ()

Returns a Collection view of the attribute values contained in this Map.

Returns
Collection<Object> a collection view of the values contained in this map