Package com.oorian

Class AttributeMap

java.lang.Object
com.oorian.AttributeMap
All Implemented Interfaces:
Map<String,String>

public class AttributeMap extends Object implements Map<String,String>
A thread-safe map implementation for storing HTML element attributes.

This class provides a synchronized wrapper around a LinkedHashMap to store HTML element attributes as key-value pairs. It maintains insertion order and ensures thread-safe access to attribute data. All methods are synchronized to prevent concurrent modification issues when attributes are accessed from multiple threads.

Features:

  • Thread-safe access to all map operations
  • Maintains insertion order of attributes
  • Implements standard Map interface
  • Supports copying via copy constructor
  • Used for HTML element attribute management in the Oorian framework

Thread Safety: All map operations are synchronized, making this class safe for concurrent access from multiple threads. However, iteration over the map's views (keySet, values, entrySet) should still be externally synchronized if the map is modified during iteration.

Usage:


 // Create an attribute map
 AttributeMap attributes = new AttributeMap();

 // Add attributes
 attributes.put("class", "btn btn-primary");
 attributes.put("id", "submitButton");
 attributes.put("data-action", "submit");

 // Access attributes
 String cssClass = attributes.get("class");

 // Copy attributes
 AttributeMap copy = new AttributeMap(attributes);

 // Iterate (synchronize externally for safety during modification)
 synchronized(attributes) {
     for (Map.Entry<String, String> entry : attributes.entrySet()) {
         String name = entry.getKey();
         String value = entry.getValue();
         // Process attribute
     }
 }
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • AttributeMap

      public AttributeMap()
      Constructs an empty AttributeMap.

      Creates a new map with no attributes. Attributes can be added using put(String, String) or putAll(Map).

    • AttributeMap

      public AttributeMap(AttributeMap copy)
      Constructs a new AttributeMap as a copy of an existing one.

      Creates a deep copy of the attribute map, copying all key-value pairs from the source map. Changes to the copy will not affect the original, and vice versa.

      Parameters:
      copy - the AttributeMap to copy (must not be null)
  • Method Details

    • size

      public int size()
      Returns the number of attributes in this map.
      Specified by:
      size in interface Map<String,String>
      Returns:
      the number of key-value mappings in this map
    • isEmpty

      public boolean isEmpty()
      Returns true if this map contains no attributes.
      Specified by:
      isEmpty in interface Map<String,String>
      Returns:
      true if this map contains no key-value mappings
    • containsKey

      public boolean containsKey(Object key)
      Returns true if this map contains an attribute with the specified name.
      Specified by:
      containsKey in interface Map<String,String>
      Parameters:
      key - the attribute name to check for
      Returns:
      true if this map contains a mapping for the specified key
    • containsValue

      public boolean containsValue(Object value)
      Returns true if this map contains one or more attributes with the specified value.
      Specified by:
      containsValue in interface Map<String,String>
      Parameters:
      value - the attribute value to check for
      Returns:
      true if this map maps one or more keys to the specified value
    • get

      public String get(Object key)
      Returns the value of the attribute with the specified name.
      Specified by:
      get in interface Map<String,String>
      Parameters:
      key - the attribute name whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped, or null if this map contains no mapping for the key
    • put

      public String put(String key, String value)
      Associates the specified value with the specified attribute name in this map.

      If the map previously contained a mapping for the attribute, the old value is replaced.

      Specified by:
      put in interface Map<String,String>
      Parameters:
      key - the attribute name with which the specified value is to be associated
      value - the attribute value to be associated with the specified key
      Returns:
      the previous value associated with the key, or null if there was no mapping
    • remove

      public String remove(Object key)
      Removes the attribute with the specified name from this map if present.
      Specified by:
      remove in interface Map<String,String>
      Parameters:
      key - the attribute name whose mapping is to be removed from the map
      Returns:
      the previous value associated with the key, or null if there was no mapping
    • putAll

      public void putAll(Map<? extends String,? extends String> m)
      Copies all of the mappings from the specified map to this attribute map.

      These mappings will replace any attributes that this map had for any of the keys currently in the specified map.

      Specified by:
      putAll in interface Map<String,String>
      Parameters:
      m - mappings to be stored in this map
    • clear

      public void clear()
      Removes all attributes from this map.

      The map will be empty after this call returns.

      Specified by:
      clear in interface Map<String,String>
    • keySet

      public Set<String> keySet()
      Returns a Set view of the attribute names contained in this map.

      The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined.

      Specified by:
      keySet in interface Map<String,String>
      Returns:
      a set view of the keys (attribute names) contained in this map
    • values

      public Collection<String> values()
      Returns a Collection view of the attribute values contained in this map.

      The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress, the results of the iteration are undefined.

      Specified by:
      values in interface Map<String,String>
      Returns:
      a collection view of the values (attribute values) contained in this map
    • entrySet

      public Set<Map.Entry<String,String>> entrySet()
      Returns a Set view of the attribute mappings contained in this map.

      The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined.

      Specified by:
      entrySet in interface Map<String,String>
      Returns:
      a set view of the mappings (attribute name-value pairs) contained in this map