- java.lang.Object
-
- java.util.jar.Attributes
-
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. 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.- Since:
- 1.2
- See Also:
Manifest
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static class
Attributes.Name
The Attributes.Name class represents an attribute name stored in this Map.
-
Field Summary
Fields Modifier and Type Field and Description protected Map<Object,Object>
map
The attribute name-value mappings.
-
Constructor Summary
Constructors Constructor and Description Attributes()
Constructs a new, empty Attributes object with default size.Attributes(Attributes attr)
Constructs a new Attributes object with the same attribute name-value mappings as in the specified Attributes.Attributes(int size)
Constructs a new, empty Attributes object with the specified initial size.
-
Method Summary
Methods Modifier and Type Method and Description void
clear()
Removes all attributes from this Map.Object
clone()
Returns a copy of the Attributes, implemented as follows: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<Map.Entry<Object,Object>>
entrySet()
Returns a Collection view of the attribute name-value mappings contained in this Map.boolean
equals(Object o)
Compares the specified Attributes object with this 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(Attributes.Name name)
Returns the value of the specified Attributes.Name, or null if the attribute 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.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.
-
-
-
Constructor Detail
-
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 Detail
-
get
public Object get(Object name)
Returns the value of the specified attribute name, or null if the attribute name was not found.
-
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:
put
in interfaceMap<Object,Object>
- Parameters:
name
- the attribute namevalue
- 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 stringvalue
- 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:
containsValue
in 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:
containsKey
in 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:
putAll
in interfaceMap<Object,Object>
- Parameters:
attr
- the Attributes to be stored in this map- Throws:
ClassCastException
- if attr is not an Attributes
-
clear
public void clear()
Removes all attributes from this Map.
-
size
public int size()
Returns the number of attributes in this Map.
-
isEmpty
public boolean isEmpty()
Returns true if this Map contains no attributes.
-
keySet
public Set<Object> keySet()
Returns a Set view of the attribute names (keys) contained in this Map.
-
values
public Collection<Object> values()
Returns a Collection view of the attribute values contained in this Map.
-
entrySet
public Set<Map.Entry<Object,Object>> entrySet()
Returns a Collection view of the attribute name-value mappings contained in this Map.
-
equals
public boolean equals(Object o)
Compares the specified Attributes object with this Map for equality. Returns true if the given object is also an instance of Attributes and the two Attributes objects represent the same mappings.
-
hashCode
public int hashCode()
Returns the hash code value for this Map.- Specified by:
hashCode
in interfaceMap<Object,Object>
- Overrides:
hashCode
in classObject
- Returns:
- a hash code value for this object.
- See Also:
Object.equals(java.lang.Object)
,System.identityHashCode(java.lang.Object)
-
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.
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
21/11/2024 21:44:39 Cette version de la page est en cache (à la date du 21/11/2024 21:44:39) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 29/08/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-java/util/jar/attributes.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.