Package org.wildfly.security.authz
Class MapAttributes
- java.lang.Object
-
- org.wildfly.security.authz.MapAttributes
-
- All Implemented Interfaces:
Attributes
public class MapAttributes extends Object implements Attributes
A map-backed attributes collection.- Author:
- David M. Lloyd
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.wildfly.security.authz.Attributes
Attributes.Entry, Attributes.SetEntry
-
-
Field Summary
-
Fields inherited from interface org.wildfly.security.authz.Attributes
EMPTY
-
-
Constructor Summary
Constructors Constructor Description MapAttributes()
Construct an instance using a hash map for backing store.MapAttributes(Map<String,? extends Collection<String>> original)
Construct a new instance copying mappings from an original map.MapAttributes(Attributes original)
Construct a new instance copying mappings from an original attributes collection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(String key, int idx, String value)
Add a mapping for the given key at the given position.void
addFirst(String key, String value)
Add a value before the first mapping for the given key.void
addLast(String key, String value)
Add a value after the last mapping for the given key.void
clear()
Clear this collection, resetting its size to zero.boolean
containsKey(String key)
Determine if the given key has values in this collection.boolean
containsValue(String key, String value)
Determine if the given key has a mapping for the given value in this collection.List<String>
copyAndRemove(String key)
Remove all values for the given key from this collection, copying the values into a list which is returned.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.String
getFirst(String key)
Get the first value mapped to the given key.String
getLast(String key)
Get the last value mapped to the given key.int
indexOf(String key, String value)
Get the index of the first occurrence of the given value at the given key, if any.boolean
isEmpty()
Determine if this collection is empty.Set<String>
keySet()
Get a set comprised of all the keys in this collection.int
lastIndexOf(String key, String value)
Get the index of the last occurrence of the given value at the given key, if any.boolean
remove(String key)
Remove all values for the given key from this collection.String
remove(String key, int idx)
Remove and return the mapping for the given key at the given position.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.boolean
removeAll(String key, String value)
Remove the all occurrences of the given value under the given key, if any.String
removeFirst(String key)
Remove the first value mapped to the given key.boolean
removeFirst(String key, String value)
Remove the first occurrence of the given value under the given key, if any.String
removeLast(String key)
Remove the last value mapped to the given key.boolean
removeLast(String key, String value)
Remove the last occurrence of the given value under the given key, if any.void
removeRange(String key, int from, int to)
Remove all the values for the given key between thefrom
index (inclusive) and theto
index (exclusive).String
set(String key, int idx, String value)
Modify the mapping for the given key at the given position.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 theexpect
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.Collection<String>
values()
Get all the values of all the keys in this collection.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.wildfly.security.authz.Attributes
addAll, addAll, asReadOnly
-
-
-
-
Constructor Detail
-
MapAttributes
public MapAttributes()
Construct an instance using a hash map for backing store.
-
MapAttributes
public MapAttributes(Map<String,? extends Collection<String>> original)
Construct a new instance copying mappings from an original map.- Parameters:
original
- the original map
-
MapAttributes
public MapAttributes(Attributes original)
Construct a new instance copying mappings from an original attributes collection.- Parameters:
original
- the original collection
-
-
Method Detail
-
keySet
public Set<String> keySet()
Description copied from interface:Attributes
Get a set comprised of all the keys in this collection. The returned set can be used to modify this attributes collection.- Specified by:
keySet
in interfaceAttributes
- Returns:
- the set of all keys (not
null
)
-
values
public Collection<String> values()
Description copied from interface:Attributes
Get all the values of all the keys in this collection. The returned collection can be used to modify this attributes collection.- Specified by:
values
in interfaceAttributes
- Returns:
- the collection of all values (not
null
)
-
entries
public Collection<Attributes.Entry> entries()
Description copied from interface:Attributes
Get the entry collection. Changes to the entry collection will modify this attribute collection, if it is writable. The returned entries will remain up to date with the state of this collection.- Specified by:
entries
in interfaceAttributes
- Returns:
- the entry collection
-
size
public int size(String key)
Description copied from interface:Attributes
Get the number of values mapped to the given key.- Specified by:
size
in interfaceAttributes
- Parameters:
key
- the key- Returns:
- the number of mapped values
-
remove
public boolean remove(String key)
Description copied from interface:Attributes
Remove all values for the given key from this collection.- Specified by:
remove
in interfaceAttributes
- Parameters:
key
- the key- Returns:
true
if the key was found,false
otherwise
-
add
public void add(String key, int idx, String value)
Description copied from interface:Attributes
Add a mapping for the given key at the given position.- Specified by:
add
in interfaceAttributes
- Parameters:
key
- the keyidx
- the indexvalue
- the mapping value
-
get
public String get(String key, int idx)
Description copied from interface:Attributes
Get the mapping for the given key at the given position.- Specified by:
get
in interfaceAttributes
- Parameters:
key
- the keyidx
- the index- Returns:
- the mapping value
-
set
public String set(String key, int idx, String value)
Description copied from interface:Attributes
Modify the mapping for the given key at the given position.- Specified by:
set
in interfaceAttributes
- Parameters:
key
- the keyidx
- the indexvalue
- the mapping value- Returns:
- the previous mapping value
-
remove
public String remove(String key, int idx)
Description copied from interface:Attributes
Remove and return the mapping for the given key at the given position. All later entries for that key are shifted up to fill in the gap left by the removed element.- Specified by:
remove
in interfaceAttributes
- Parameters:
key
- the keyidx
- the index- Returns:
- the previous mapping value
-
copyAndRemove
public List<String> copyAndRemove(String key)
Description copied from interface:Attributes
Remove all values for the given key from this collection, copying the values into a list which is returned.- Specified by:
copyAndRemove
in interfaceAttributes
- Parameters:
key
- the key- Returns:
- the values as a list (not
null
)
-
copyAndReplace
public List<String> copyAndReplace(String key, Collection<String> values)
Description copied from interface:Attributes
Replace the mapping for the given key with the values copied from the given collection.- Specified by:
copyAndReplace
in interfaceAttributes
- Parameters:
key
- the keyvalues
- the new values- Returns:
- a list containing the previously mapped values
-
containsKey
public boolean containsKey(String key)
Description copied from interface:Attributes
Determine if the given key has values in this collection.- Specified by:
containsKey
in interfaceAttributes
- Parameters:
key
- the key- Returns:
true
if the key has values,false
otherwise
-
containsValue
public boolean containsValue(String key, String value)
Description copied from interface:Attributes
Determine if the given key has a mapping for the given value in this collection.- Specified by:
containsValue
in interfaceAttributes
- Parameters:
key
- the keyvalue
- the value- Returns:
true
if the key has a mapping to the given value,false
otherwise
-
removeRange
public void removeRange(String key, int from, int to)
Description copied from interface:Attributes
Remove all the values for the given key between thefrom
index (inclusive) and theto
index (exclusive).- Specified by:
removeRange
in interfaceAttributes
- Parameters:
key
- the keyfrom
- the start index (inclusive)to
- the end index (exclusive)
-
indexOf
public int indexOf(String key, String value)
Description copied from interface:Attributes
Get the index of the first occurrence of the given value at the given key, if any.- Specified by:
indexOf
in interfaceAttributes
- Parameters:
key
- the keyvalue
- the value- Returns:
- the index, or -1 if the value was not found at the given key
-
lastIndexOf
public int lastIndexOf(String key, String value)
Description copied from interface:Attributes
Get the index of the last occurrence of the given value at the given key, if any.- Specified by:
lastIndexOf
in interfaceAttributes
- Parameters:
key
- the keyvalue
- the value- Returns:
- the index, or -1 if the value was not found at the given key
-
set
public boolean set(String key, int idx, String expect, String update)
Description copied from interface:Attributes
Conditionally set a specific value of a given key to a new value, if the existing value matches theexpect
parameter.- Specified by:
set
in interfaceAttributes
- Parameters:
key
- the keyidx
- the indexexpect
- the expected valueupdate
- the value to set- Returns:
true
if the actual value matched the expected value and was updated,false
otherwise
-
getFirst
public String getFirst(String key)
Description copied from interface:Attributes
Get the first value mapped to the given key.- Specified by:
getFirst
in interfaceAttributes
- Parameters:
key
- the key- Returns:
- the value
-
getLast
public String getLast(String key)
Description copied from interface:Attributes
Get the last value mapped to the given key.- Specified by:
getLast
in interfaceAttributes
- Parameters:
key
- the key- Returns:
- the value
-
addFirst
public void addFirst(String key, String value)
Description copied from interface:Attributes
Add a value before the first mapping for the given key.- Specified by:
addFirst
in interfaceAttributes
- Parameters:
key
- the keyvalue
- the value
-
addLast
public void addLast(String key, String value)
Description copied from interface:Attributes
Add a value after the last mapping for the given key.- Specified by:
addLast
in interfaceAttributes
- Parameters:
key
- the keyvalue
- the value
-
removeFirst
public boolean removeFirst(String key, String value)
Description copied from interface:Attributes
Remove the first occurrence of the given value under the given key, if any.- Specified by:
removeFirst
in interfaceAttributes
- Parameters:
key
- the keyvalue
- the value to remove- Returns:
true
if the value was found and removed,false
otherwise
-
removeLast
public boolean removeLast(String key, String value)
Description copied from interface:Attributes
Remove the last occurrence of the given value under the given key, if any.- Specified by:
removeLast
in interfaceAttributes
- Parameters:
key
- the keyvalue
- the value to remove- Returns:
true
if the value was found and removed,false
otherwise
-
removeFirst
public String removeFirst(String key)
Description copied from interface:Attributes
Remove the first value mapped to the given key.- Specified by:
removeFirst
in interfaceAttributes
- Parameters:
key
- the key- Returns:
- the value
-
removeLast
public String removeLast(String key)
Description copied from interface:Attributes
Remove the last value mapped to the given key.- Specified by:
removeLast
in interfaceAttributes
- Parameters:
key
- the key- Returns:
- the value
-
remove
public boolean remove(String key, int idx, String value)
Description copied from interface:Attributes
Remove the mapping for the given key at the given position if it matches the given existing value. All later entries for that key are shifted up to fill in the gap left by the removed element.- Specified by:
remove
in interfaceAttributes
- Parameters:
key
- the keyidx
- the indexvalue
- the expected previous mapping value- Returns:
true
if the value matched and was removed,false
otherwise
-
removeAll
public boolean removeAll(String key, String value)
Description copied from interface:Attributes
Remove the all occurrences of the given value under the given key, if any.- Specified by:
removeAll
in interfaceAttributes
- Parameters:
key
- the keyvalue
- the value to remove- Returns:
true
if the value was found and removed,false
otherwise
-
get
public Attributes.Entry get(String key)
Description copied from interface:Attributes
Get the collection of values for the given key. The result may implementAttributes.SetEntry
if the values are distinct (for example, a role or group set).- Specified by:
get
in interfaceAttributes
- Parameters:
key
- the attribute name- Returns:
- the (possibly empty) attribute value collection
-
size
public int size()
Description copied from interface:Attributes
Get the number of keys in this attribute collection.- Specified by:
size
in interfaceAttributes
- Returns:
- the number of keys
-
isEmpty
public boolean isEmpty()
Description copied from interface:Attributes
Determine if this collection is empty.- Specified by:
isEmpty
in interfaceAttributes
- Returns:
true
if the collection is empty,false
otherwise
-
clear
public void clear()
Description copied from interface:Attributes
Clear this collection, resetting its size to zero.- Specified by:
clear
in interfaceAttributes
-
-