Package java.util.jar

Class Attributes

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

public class Attributes
extends Object
implements Cloneable, Map<Object,​Object>
The Attributes class is used to store values for manifest entries. Attribute keys are generally instances of Attributes.Name. Values associated with attribute keys are of type String.
  • Nested Class Summary

    Nested Classes
    Modifier and Type Class Description
    static class  Attributes.Name
    The name part of the name/value pairs constituting an attribute as defined by the specification of the JAR manifest.

    Nested classes/interfaces inherited from interface java.util.Map

    Map.Entry<K,​V>
  • Field Summary

    Fields
    Modifier and Type Field Description
    protected Map<Object,​Object> map
    The Attributes as name/value pairs.
  • Constructor Summary

    Constructors
    Constructor Description
    Attributes()
    Constructs an Attributes instance.
    Attributes​(int size)
    Constructs an Attributes instance with initial capacity of size size.
    Attributes​(Attributes attrib)
    Constructs an Attributes instance obtaining keys and values from the parameter attrib.
  • Method Summary

    Modifier and Type Method Description
    void clear()
    Removes all key/value pairs from this Attributes.
    Object clone()
    Creates and returns a copy of this Object.
    boolean containsKey​(Object key)
    Determines whether this Attributes contains the specified key.
    boolean containsValue​(Object value)
    Determines whether this Attributes contains the specified value.
    Set<Map.Entry<Object,​Object>> entrySet()
    Returns a set containing map entries for each of the key/value pair contained in this Attributes.
    boolean equals​(Object obj)
    Determines if this Attributes and the parameter Attributes are equal.
    Object get​(Object key)
    Returns the value associated with the parameter key.
    String getValue​(String name)
    Returns the string associated with the parameter name.
    String getValue​(Attributes.Name name)
    Returns the value associated with the parameter Attributes.Name key.
    int hashCode()
    Returns the hash code of this Attributes.
    boolean isEmpty()
    Determines whether this Attributes contains any keys.
    Set<Object> keySet()
    Returns a Set containing all the keys found in this Attributes.
    Object put​(Object key, Object value)
    Stores key/value pairs in this Attributes.
    void putAll​(Map<?,​?> attrib)
    Stores all the key/value pairs in the argument in this Attributes.
    String putValue​(String name, String value)
    Stores the value value associated with the key name in this Attributes.
    Object remove​(Object key)
    Deletes the key/value pair with key key from this Attributes.
    int size()
    Returns the number of key/value pairs associated with this Attributes.
    Collection<Object> values()
    Returns a collection of all the values present in this Attributes.

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • map

      protected Map<Object,​Object> map
      The Attributes as name/value pairs. Maps the attribute names (as Attributes.Name) of a JAR file manifest to arbitrary values. The attribute names thus are obtained from the Manifest for convenience.
  • Constructor Details

    • Attributes

      public Attributes()
      Constructs an Attributes instance.
    • Attributes

      public Attributes​(Attributes attrib)
      Constructs an Attributes instance obtaining keys and values from the parameter attrib.
      Parameters:
      attrib - The attributes to obtain entries from.
    • Attributes

      public Attributes​(int size)
      Constructs an Attributes instance with initial capacity of size size.
      Parameters:
      size - Initial size of this Attributes instance.
  • Method Details

    • clear

      public void clear()
      Removes all key/value pairs from this Attributes.
      Specified by:
      clear in interface Map<Object,​Object>
      See Also:
      Map.isEmpty(), Map.size()
    • containsKey

      public boolean containsKey​(Object key)
      Determines whether this Attributes contains the specified key.
      Specified by:
      containsKey in interface Map<Object,​Object>
      Parameters:
      key - The key to search for.
      Returns:
      true if the key is found, false otherwise.
    • containsValue

      public boolean containsValue​(Object value)
      Determines whether this Attributes contains the specified value.
      Specified by:
      containsValue in interface Map<Object,​Object>
      Parameters:
      value - the value to search for.
      Returns:
      true if the value is found, false otherwise.
    • entrySet

      public Set<Map.Entry<Object,​Object>> entrySet()
      Returns a set containing map entries for each of the key/value pair contained in this Attributes.
      Specified by:
      entrySet in interface Map<Object,​Object>
      Returns:
      a set of Map.Entry's
    • get

      public Object get​(Object key)
      Returns the value associated with the parameter key.
      Specified by:
      get in interface Map<Object,​Object>
      Parameters:
      key - the key to search for.
      Returns:
      Object associated with key, or null if key does not exist.
    • isEmpty

      public boolean isEmpty()
      Determines whether this Attributes contains any keys.
      Specified by:
      isEmpty in interface Map<Object,​Object>
      Returns:
      true if one or more keys exist, false otherwise.
      See Also:
      Map.size()
    • keySet

      public Set<Object> keySet()
      Returns a Set containing all the keys found in this Attributes.
      Specified by:
      keySet in interface Map<Object,​Object>
      Returns:
      a Set of all keys.
    • put

      public Object put​(Object key, Object value)
      Stores key/value pairs in this Attributes.
      Specified by:
      put in interface Map<Object,​Object>
      Parameters:
      key - the key to associate with value.
      value - the value to store in this Attributes.
      Returns:
      the value being stored.
      Throws:
      ClassCastException - when key is not an Attributes.Name or value is not a String.
    • putAll

      public void putAll​(Map<?,​?> attrib)
      Stores all the key/value pairs in the argument in this Attributes.
      Specified by:
      putAll in interface Map<Object,​Object>
      Parameters:
      attrib - the associations to store (must be of type Attributes).
    • remove

      public Object remove​(Object key)
      Deletes the key/value pair with key key from this Attributes.
      Specified by:
      remove in interface Map<Object,​Object>
      Parameters:
      key - the key to remove.
      Returns:
      the values associated with the removed key, null if not present.
    • size

      public int size()
      Returns the number of key/value pairs associated with this Attributes.
      Specified by:
      size in interface Map<Object,​Object>
      Returns:
      the size of this Attributes.
    • values

      public Collection<Object> values()
      Returns a collection of all the values present in this Attributes.
      Specified by:
      values in interface Map<Object,​Object>
      Returns:
      a collection of all values present.
    • clone

      public Object clone()
      Description copied from class: Object
      Creates and returns a copy of this Object. The default implementation returns a so-called "shallow" copy: It creates a new instance of the same class and then copies the field values (including object references) from this instance to the new instance. A "deep" copy, in contrast, would also recursively clone nested objects. A subclass that needs to implement this kind of cloning should call super.clone() to create the new instance and then create deep copies of the nested, mutable objects.
      Overrides:
      clone in class Object
      Returns:
      a copy of this object.
    • hashCode

      public int hashCode()
      Returns the hash code of this Attributes.
      Specified by:
      hashCode in interface Map<Object,​Object>
      Overrides:
      hashCode in class Object
      Returns:
      the hash code of this object.
      See Also:
      Object.equals(java.lang.Object)
    • equals

      public boolean equals​(Object obj)
      Determines if this Attributes and the parameter Attributes are equal. Two Attributes instances are equal if they contain the same keys and values.
      Specified by:
      equals in interface Map<Object,​Object>
      Overrides:
      equals in class Object
      Parameters:
      obj - the object with which this Attributes is compared.
      Returns:
      true if the Attributes are equal, false otherwise.
      See Also:
      Object.hashCode()
    • getValue

      public String getValue​(Attributes.Name name)
      Returns the value associated with the parameter Attributes.Name key.
      Parameters:
      name - the key to obtain the value for.
      Returns:
      the String associated with name, or null if name is not a valid key.
    • getValue

      public String getValue​(String name)
      Returns the string associated with the parameter name.
      Parameters:
      name - the key to obtain the value for.
      Returns:
      the string associated with name, or null if name is not a valid key.
    • putValue

      public String putValue​(String name, String value)
      Stores the value value associated with the key name in this Attributes.
      Returns:
      the value being stored.