Interface AttributeAware

All Known Subinterfaces:
HttpRequest, WebsocketConnection
All Known Implementing Classes:
WebsocketClient

public interface AttributeAware
Interface that is implemented by any bean that has attributes. An attribute is simply a key-value pair. Therefore, this interface contains methods that set, get, and remove attributes.

Example

The following shows a typical implementation.
 
  public class MyClass implements AttributeAware {

      private final Map<Object, Object> attrMap = new HashMap<>();

      @Override
      public void setAttribute(Object key, Object value) {
          if (value == null) {
              attrMap.remove(key);
          } else {
              attrMap.put(key, value);
          }
      }

      @Override
      public Object getAttribute(Object key) {
          return attrMap.get(key);
      }

      @Override
      public Object removeAttribute(Object key) {
          return attrMap.remove(key);
      }
  }
 
 
Since:
1.0
Version:
2022-08-30
  • Method Details

    • setAttribute

      void setAttribute(Object key, Object value)
      Sets the attribute for the given key.
      Parameters:
      key - the attribute key
      value - the attribute value
    • getAttribute

      Object getAttribute(Object key)
      Given a key, returns its attribute.
      Parameters:
      key - the attribute key
      Returns:
      the value of the attribute, or null if it doesn't exist
    • removeAttribute

      Object removeAttribute(Object key)
      Given a key, removes the attribute.
      Parameters:
      key - the attribute key
      Returns:
      the value of the attribute being removed, or null if it didn't exist