io.undertow.util

## Class AbstractAttachable

- java.lang.Object
- - io.undertow.util.AbstractAttachable

All Implemented Interfaces:
  Attachable

Direct Known Subclasses:
  ClientRequest, ClientResponse, Http2ClientExchange, HttpServerExchange, ServerConnection

    public abstract class AbstractAttachable
    extends Object
    implements Attachable

A thing which can have named attachments.

Author:
  David M. Lloyd

### Constructor Summary

Constructors
Constructor and Description
`AbstractAttachable()`

### Method Summary

All Methods Instance Methods Concrete Methods
`<T> void` `addToAttachmentList(AttachmentKey<AttachmentList<T>> key, T value)` Add a value to a list-typed attachment key.
`protected Map<AttachmentKey<?>,Object>` `createAttachmentMap()`
`<T> T` `getAttachment(AttachmentKey<T> key)` Get an attachment value.
`<T> List<T>` `getAttachmentList(AttachmentKey<? extends List<T>> key)` Gets a list attachment value.
`<T> T` `putAttachment(AttachmentKey<T> key, T value)` Set an attachment value.
`<T> T` `removeAttachment(AttachmentKey<T> key)` Remove an attachment, returning its previous value.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### AbstractAttachable

    public AbstractAttachable()

### Method Detail

#### getAttachment

    public <T> T getAttachment(AttachmentKey<T> key)

Get an attachment value. If no attachment exists for this key, `null` is returned.

Specified by:
  `getAttachment` in interface `Attachable`
Type Parameters:
  `T` - the value type
Parameters:
  `key` - the attachment key
Returns:
  the value, or `null` if there is none

#### getAttachmentList

    public <T> List<T> getAttachmentList(AttachmentKey<? extends List<T>> key)

Gets a list attachment value. If not attachment exists for this key an empty list is returned

Specified by:
  `getAttachmentList` in interface `Attachable`
Type Parameters:
  `T` - the value type
Parameters:
  `key` - the attachment key
Returns:
  the value, or an empty list if there is none

#### putAttachment

    public <T> T putAttachment(AttachmentKey<T> key,
                               T value)

Set an attachment value. If an attachment for this key was already set, return the original value. If the value being set is `null`, the attachment key is removed.

Specified by:
  `putAttachment` in interface `Attachable`
Type Parameters:
  `T` - the value type
Parameters:
  `key` - the attachment key
  `value` - the new value
Returns:
  the old value, or `null` if there was none

#### createAttachmentMap

    protected Map<AttachmentKey<?>,Object> createAttachmentMap()

#### removeAttachment

    public <T> T removeAttachment(AttachmentKey<T> key)

Remove an attachment, returning its previous value.

Specified by:
  `removeAttachment` in interface `Attachable`
Type Parameters:
  `T` - the value type
Parameters:
  `key` - the attachment key
Returns:
  the old value, or `null` if there was none

#### addToAttachmentList

    public <T> void addToAttachmentList(AttachmentKey<AttachmentList<T>> key,
                                        T value)

Add a value to a list-typed attachment key. If the key is not mapped, add such a mapping.

Specified by:
  `addToAttachmentList` in interface `Attachable`
Type Parameters:
  `T` - the list value type
Parameters:
  `key` - the attachment key
  `value` - the value to add