public interface Attributes
A collection of string attributes.
By default, this interface provides a default implementation for all methods that perform writes to the collection. The default
implementation will always throw a UnsupportedOperationException
, which means the collection is read-only by default.
If an implementation needs to also support writes it must override and implement all these default methods.
Modifier and Type | Interface and Description |
---|---|
static interface |
Attributes.Entry
The entry collection for a mapping.
|
static interface |
Attributes.SetEntry
The entry collection for a mapping whose values are a distinct set.
|
Modifier and Type | Field and Description |
---|---|
static Attributes |
EMPTY
Empty, read-only attribute collection.
|
Modifier and Type | Method and Description |
---|---|
default void |
add(String key,
int idx,
String value)
Add a mapping for the given key at the given position.
|
default boolean |
addAll(Map<String,? extends Collection<String>> map)
Add all the values from the given map to this attributes collection.
|
default boolean |
addAll(String key,
Collection<String> values)
Add all the values from the given collection to the value collection for the given key.
|
default void |
addFirst(String key,
String value)
Add a value before the first mapping for the given key.
|
default void |
addLast(String key,
String value)
Add a value after the last mapping for the given key.
|
default Attributes |
asReadOnly()
Returns a read-only instance of this instance.
|
default void |
clear()
Clear this collection, resetting its size to zero.
|
default boolean |
containsKey(String key)
Determine if the given key has values in this collection.
|
default boolean |
containsValue(String key,
String value)
Determine if the given key has a mapping for the given value in this collection.
|
default List<String> |
copyAndRemove(String key)
Remove all values for the given key from this collection, copying the values into a list which is returned.
|
default List<String> |
copyAndReplace(String key,
Collection<String> values)
Replace the mapping for the given key with the values copied from the given collection.
|
Collection<Attributes.Entry> |
entries()
Get the entry collection.
|
Attributes.Entry |
get(String key)
Get the collection of values for the given key.
|
String |
get(String key,
int idx)
Get the mapping for the given key at the given position.
|
default String |
getFirst(String key)
Get the first value mapped to the given key.
|
default String |
getLast(String key)
Get the last value mapped to the given key.
|
default int |
indexOf(String key,
String value)
Get the index of the first occurrence of the given value at the given key, if any.
|
default boolean |
isEmpty()
Determine if this collection is empty.
|
default Set<String> |
keySet()
Get a set comprised of all the keys in this collection.
|
default int |
lastIndexOf(String key,
String value)
Get the index of the last occurrence of the given value at the given key, if any.
|
default boolean |
remove(String key)
Remove all values for the given key from this collection.
|
default String |
remove(String key,
int idx)
Remove and return the mapping for the given key at the given position.
|
default boolean |
remove(String key,
int idx,
String value)
Remove the mapping for the given key at the given position if it matches the given existing value.
|
default boolean |
removeAll(String key,
String value)
Remove the all occurrences of the given value under the given key, if any.
|
default String |
removeFirst(String key)
Remove the first value mapped to the given key.
|
default boolean |
removeFirst(String key,
String value)
Remove the first occurrence of the given value under the given key, if any.
|
default String |
removeLast(String key)
Remove the last value mapped to the given key.
|
default boolean |
removeLast(String key,
String value)
Remove the last occurrence of the given value under the given key, if any.
|
default void |
removeRange(String key,
int from,
int to)
Remove all the values for the given key between the
from index (inclusive) and the to index
(exclusive). |
default String |
set(String key,
int idx,
String value)
Modify the mapping for the given key at the given position.
|
default boolean |
set(String key,
int idx,
String expect,
String update)
Conditionally set a specific value of a given key to a new value, if the existing value matches the
expect
parameter. |
int |
size()
Get the number of keys in this attribute collection.
|
int |
size(String key)
Get the number of values mapped to the given key.
|
default Collection<String> |
values()
Get all the values of all the keys in this collection.
|
static final Attributes EMPTY
Collection<Attributes.Entry> entries()
int size(String key)
key
- the keyAttributes.Entry get(String key)
Attributes.SetEntry
if the values
are distinct (for example, a role or group set).key
- the attribute nameString get(String key, int idx)
key
- the keyidx
- the indexIndexOutOfBoundsException
- if idx
is less than 0 or greater than or equal to size(key)
int size()
default boolean remove(String key)
key
- the keytrue
if the key was found, false
otherwiseUnsupportedOperationException
- if this method is not implemented and the operation is not supporteddefault void add(String key, int idx, String value)
key
- the keyidx
- the indexvalue
- the mapping valueIndexOutOfBoundsException
- if idx
is less than 0 or greater than or equal to size(key)
UnsupportedOperationException
- if this method is not implemented and the operation is not supporteddefault String set(String key, int idx, String value)
key
- the keyidx
- the indexvalue
- the mapping valueIndexOutOfBoundsException
- if idx
is less than 0 or greater than or equal to size(key)
UnsupportedOperationException
- if this method is not implemented and the operation is not supporteddefault String remove(String key, int idx)
key
- the keyidx
- the indexIndexOutOfBoundsException
- if idx
is less than 0 or greater than or equal to size(key)
UnsupportedOperationException
- if this method is not implemented and the operation is not supporteddefault void clear()
UnsupportedOperationException
- if this method is not implemented and the operation is not supporteddefault List<String> copyAndRemove(String key)
key
- the keynull
)default Collection<String> values()
null
)default Set<String> keySet()
null
)default boolean set(String key, int idx, String expect, String update)
expect
parameter.key
- the keyidx
- the indexexpect
- the expected valueupdate
- the value to settrue
if the actual value matched the expected value and was updated, false
otherwiseIndexOutOfBoundsException
- if idx
is less than 0 or greater than or equal to size(key)
default int indexOf(String key, String value)
key
- the keyvalue
- the valuedefault int lastIndexOf(String key, String value)
key
- the keyvalue
- the valuedefault void removeRange(String key, int from, int to)
from
index (inclusive) and the to
index
(exclusive).key
- the keyfrom
- the start index (inclusive)to
- the end index (exclusive)IndexOutOfBoundsException
- if idx
is less than 0 or greater than or equal to size(key)
default String getFirst(String key)
key
- the keyIndexOutOfBoundsException
- if there are no values for the given keydefault String getLast(String key)
key
- the keyIndexOutOfBoundsException
- if there are no values for the given keydefault void addFirst(String key, String value)
key
- the keyvalue
- the valuedefault void addLast(String key, String value)
key
- the keyvalue
- the valuedefault String removeFirst(String key)
key
- the keyIndexOutOfBoundsException
- if there are no values for the given keydefault String removeLast(String key)
key
- the keyIndexOutOfBoundsException
- if there are no values for the given keydefault boolean remove(String key, int idx, String value)
key
- the keyidx
- the indexvalue
- the expected previous mapping valuetrue
if the value matched and was removed, false
otherwiseIndexOutOfBoundsException
- if idx
is less than 0 or greater than or equal to size(key)
default boolean removeFirst(String key, String value)
key
- the keyvalue
- the value to removetrue
if the value was found and removed, false
otherwisedefault boolean removeLast(String key, String value)
key
- the keyvalue
- the value to removetrue
if the value was found and removed, false
otherwisedefault boolean removeAll(String key, String value)
key
- the keyvalue
- the value to removetrue
if the value was found and removed, false
otherwisedefault boolean addAll(Map<String,? extends Collection<String>> map)
map
- the map to copy fromtrue
if elements were added, false
otherwisedefault boolean addAll(String key, Collection<String> values)
key
- the keyvalues
- the values to addtrue
if elements were added, false
otherwisedefault boolean containsKey(String key)
key
- the keytrue
if the key has values, false
otherwisedefault boolean containsValue(String key, String value)
key
- the keyvalue
- the valuetrue
if the key has a mapping to the given value, false
otherwisedefault List<String> copyAndReplace(String key, Collection<String> values)
key
- the keyvalues
- the new valuesdefault boolean isEmpty()
true
if the collection is empty, false
otherwisedefault Attributes asReadOnly()
Copyright © 2020 JBoss by Red Hat. All rights reserved.