Interface AttachmentContainer

All Known Implementing Classes:
SimpleAttachmentContainer

public interface AttachmentContainer
Represents an object that can hold attachments (any Objects), each identified by a unique name string.
Since:
2.9
See Also:
  • Method Details

    • getAttachment

      Object getAttachment(String key)
      Retrieves an attachment identified by the given key previously set by setAttachment(String, Object). If no attribute was set with the given key, null is returned.
      Parameters:
      key - The name of the attachment
      Returns:
      The value of the attachment, or null if no attachment with the given key exists
    • setAttachment

      void setAttachment(String key, Object value)
      Stores an object identified by the given key.

      Values stored here likely have no meaning in the used application and are purely intended to store metadata used by the application.

      Parameters:
      key - The name string identifying the given value in this AttributeContainer
      value - The value to be stored, or null to delete an existing attachment
    • requireAttachment

      default Object requireAttachment(String key)
      Retrieves an attachment identified by the given key previously set by setAttachment(String, Object). If no attribute was set with the given key, a NoSuchElementException is thrown.
      Parameters:
      key - The name of the attachment
      Returns:
      The value of the attachment
      Throws:
      NoSuchElementException - If no attachment with the given key exists
      See Also:
      Implementation Note:
      The default implementation of this method (added in 2.11.0) checks getAttachment(key) != null
    • hasAttachment

      default boolean hasAttachment(String key)
      Determines whether an attachment identified by the given key exists.
      Parameters:
      key - The name of the attachment
      Returns:
      true if an attachment with the given key exists
      See Also:
      Implementation Note:
      The default implementation of this method (added in 2.11.0) checks getAttachment(key) != null
    • removeAttachment

      default Object removeAttachment(String key)
      Removes an attachment identified by the given key and returns it.
      Parameters:
      key - The name of the attachment
      Returns:
      The value of the attachment, or null if no attachment with the given key existed
      Implementation Note:
      The default implementation of this method (added in 2.11.0) calls getAttachment(key) to get the previous value and then setAttachment(key, null)