public final class MutableContextSet extends Object implements ContextSet
ContextSet.| Constructor and Description |
|---|
MutableContextSet() |
| Modifier and Type | Method and Description |
|---|---|
void |
add(Map.Entry<String,String> entry)
Adds a context to this set.
|
void |
add(@NonNull String key,
@NonNull String value)
Adds a context to this set.
|
void |
addAll(@NonNull ContextSet contextSet)
Adds of of the contexts in another
ContextSet to this set. |
void |
addAll(@NonNull Iterable<? extends Map.Entry<String,String>> iterable)
Adds the contexts contained in the given
Iterable to this set. |
void |
addAll(@NonNull Map<String,String> map)
Adds the contexts contained in the given
Map to this set. |
void |
addAll(@NonNull Multimap<String,String> multimap)
Adds the contexts contained in the given
Multimap to this set. |
protected SetMultimap<String,String> |
backing() |
void |
clear()
Removes all contexts from the set.
|
boolean |
containsKey(@NonNull String key)
Returns if the
ContextSet contains at least one value for the
given key. |
protected void |
copyTo(SetMultimap<String,String> other) |
static @NonNull MutableContextSet |
create()
Creates a new empty MutableContextSet.
|
boolean |
equals(Object o) |
static @NonNull MutableContextSet |
fromEntries(@NonNull Iterable<? extends Map.Entry<String,String>> iterable)
|
static @NonNull MutableContextSet |
fromMap(@NonNull Map<String,String> map)
Creates a
MutableContextSet from an existing Map. |
static @NonNull MutableContextSet |
fromMultimap(@NonNull Multimap<String,String> multimap)
Creates a
MutableContextSet from an existing Multimap. |
static @NonNull MutableContextSet |
fromSet(@NonNull ContextSet contextSet)
Creates a new
MutableContextSet from an existing Set. |
@NonNull Set<String> |
getValues(@NonNull String key)
Returns a
Set of the values mapped to the given key. |
boolean |
has(@NonNull String key,
@NonNull String value)
Returns if the
ContextSet contains a given context pairing. |
int |
hashCode() |
boolean |
isEmpty()
Returns if the
ContextSet is empty. |
boolean |
isImmutable()
Gets if this
ContextSet is immutable. |
@NonNull Iterator<Map.Entry<String,String>> |
iterator()
Returns an
Iterator over each of the context pairs in this set. |
@NonNull ImmutableContextSet |
makeImmutable()
Returns an immutable representation of this
ContextSet. |
@NonNull MutableContextSet |
mutableCopy()
Creates a mutable copy of this
ContextSet. |
static @NonNull MutableContextSet |
of(@NonNull String key1,
@NonNull String value1,
@NonNull String key2,
@NonNull String value2)
Creates a
MutableContextSet from two context pairs. |
void |
remove(@NonNull String key,
@NonNull String value)
Removes a context from this set.
|
void |
removeAll(@NonNull String key)
Removes all contexts from this set with the given key.
|
static @NonNull MutableContextSet |
singleton(@NonNull String key,
@NonNull String value)
Creates a
MutableContextSet from a context pair. |
int |
size()
Gets the number of context pairs in the
ContextSet. |
Spliterator<Map.Entry<String,String>> |
spliterator() |
@NonNull Map<String,String> |
toMap()
Deprecated.
|
@NonNull Multimap<String,String> |
toMultimap()
Returns a
Multimap representing the current state of this
ContextSet. |
@NonNull Set<Map.Entry<String,String>> |
toSet()
|
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitcontainsKey, empty, getAnyValue, getValues, has, has, isEmpty, isSatisfiedBy, sizepublic static @NonNull MutableContextSet singleton(@NonNull String key, @NonNull String value)
MutableContextSet from a context pair.singleton in interface ContextSetkey - the keyvalue - the valueNullPointerException - if key or value is nullpublic static @NonNull MutableContextSet of(@NonNull String key1, @NonNull String value1, @NonNull String key2, @NonNull String value2)
MutableContextSet from two context pairs.of in interface ContextSetkey1 - the first keyvalue1 - the first valuekey2 - the second keyvalue2 - the second valueNullPointerException - if any of the keys or values are nullpublic static @NonNull MutableContextSet fromEntries(@NonNull Iterable<? extends Map.Entry<String,String>> iterable)
fromEntries in interface ContextSetiterable - the iterable to copy fromNullPointerException - if the iterable is nullpublic static @NonNull MutableContextSet fromMap(@NonNull Map<String,String> map)
MutableContextSet from an existing Map.fromMap in interface ContextSetmap - the map to copy fromNullPointerException - if the map is nullpublic static @NonNull MutableContextSet fromMultimap(@NonNull Multimap<String,String> multimap)
MutableContextSet from an existing Multimap.fromMultimap in interface ContextSetmultimap - the multimap to copy fromNullPointerException - if the multimap is nullpublic static @NonNull MutableContextSet fromSet(@NonNull ContextSet contextSet)
MutableContextSet from an existing Set.
Only really useful for converting between mutable and immutable types.
fromSet in interface ContextSetcontextSet - the context set to copy fromNullPointerException - if contextSet is nullpublic static @NonNull MutableContextSet create()
protected SetMultimap<String,String> backing()
protected void copyTo(SetMultimap<String,String> other)
public boolean isImmutable()
ContextSetContextSet is immutable.
The state of immutable instances will never change.
isImmutable in interface ContextSetpublic @NonNull ImmutableContextSet makeImmutable()
ContextSetContextSet.
If the set is already immutable, the same object will be returned. If the set is mutable, an immutable copy will be made.
makeImmutable in interface ContextSetpublic @NonNull MutableContextSet mutableCopy()
ContextSetContextSet.
A new copy is returned regardless of the
mutability of this set.
mutableCopy in interface ContextSetpublic @NonNull Set<Map.Entry<String,String>> toSet()
ContextSetSet of Map.Entrys representing the current
state of this ContextSet.
The returned set is immutable, and is a copy of the current set. (will not update live)
toSet in interface ContextSet@Deprecated public @NonNull Map<String,String> toMap()
ContextSetMap loosely representing the current state of
this ContextSet.
The returned map is immutable, and is a copy of the current set. (will not update live)
As a single context key can be mapped to multiple values, this method may not be a true representation of the set.
If you need a representation of the set in a Java collection instance,
use ContextSet.toSet() or ContextSet.toMultimap() followed by
Multimap.asMap().
toMap in interface ContextSetpublic @NonNull Multimap<String,String> toMultimap()
ContextSetMultimap representing the current state of this
ContextSet.
The returned multimap is immutable, and is a copy of the current set. (will not update live)
toMultimap in interface ContextSetpublic @NonNull Iterator<Map.Entry<String,String>> iterator()
ContextSetIterator over each of the context pairs in this set.
The returned iterator represents the state of the set at the time of creation. It is not updated as the set changes.
The iterator does not support Iterator.remove() calls.
public Spliterator<Map.Entry<String,String>> spliterator()
spliterator in interface Iterable<Map.Entry<String,String>>public void add(@NonNull String key, @NonNull String value)
key - the key to addvalue - the value to addNullPointerException - if the key or value is nullpublic void add(Map.Entry<String,String> entry)
entry - the entry to addNullPointerException - if the entry is nullpublic void addAll(@NonNull Iterable<? extends Map.Entry<String,String>> iterable)
Iterable to this set.iterable - an iterable of key value context pairsNullPointerException - if iterable is nullpublic void addAll(@NonNull Map<String,String> map)
Map to this set.map - the map to add fromNullPointerException - if the map is nullpublic void addAll(@NonNull Multimap<String,String> multimap)
Multimap to this set.multimap - the multimap to add fromNullPointerException - if the map is nullpublic void addAll(@NonNull ContextSet contextSet)
ContextSet to this set.contextSet - the set to add fromNullPointerException - if the contextSet is nullpublic void remove(@NonNull String key, @NonNull String value)
key - the key to removevalue - the value to removeNullPointerException - if the key or value is nullpublic void removeAll(@NonNull String key)
key - the key to removeNullPointerException - if the key is nullpublic void clear()
public boolean containsKey(@NonNull String key)
ContextSetContextSet contains at least one value for the
given key.containsKey in interface ContextSetkey - the key to check forpublic @NonNull Set<String> getValues(@NonNull String key)
ContextSetSet of the values mapped to the given key.
The returned set is immutable, and only represents the current state
of the ContextSet. (will not update live)
getValues in interface ContextSetkey - the key to get values forpublic boolean has(@NonNull String key, @NonNull String value)
ContextSetContextSet contains a given context pairing.has in interface ContextSetkey - the key to look forvalue - the value to look forpublic boolean isEmpty()
ContextSetContextSet is empty.isEmpty in interface ContextSetpublic int size()
ContextSetContextSet.size in interface ContextSet