Package org.omegazero.common.util
Interface AttachmentContainer
- All Known Implementing Classes:
SimpleAttachmentContainer
public interface AttachmentContainer
Represents an object that can hold attachments (any
Object
s), each identified by a unique name string.- Since:
- 2.9
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiongetAttachment
(String key) Retrieves an attachment identified by the given key previously set bysetAttachment(String, Object)
.default boolean
hasAttachment
(String key) Determines whether an attachment identified by the given key exists.default Object
removeAttachment
(String key) Removes an attachment identified by the given key and returns it.default Object
requireAttachment
(String key) Retrieves an attachment identified by the given key previously set bysetAttachment(String, Object)
.void
setAttachment
(String key, Object value) Stores an object identified by the given key.
-
Method Details
-
getAttachment
Retrieves an attachment identified by the given key previously set bysetAttachment(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
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 thisAttributeContainer
value
- The value to be stored, ornull
to delete an existing attachment
-
requireAttachment
Retrieves an attachment identified by the given key previously set bysetAttachment(String, Object)
. If no attribute was set with the given key, aNoSuchElementException
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
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
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 thensetAttachment(key, null)
-