- java.lang.Object
-
- javafx.beans.binding.MapExpression<K,V>
-
- Type Parameters:
K- the type of the key elementsV- the type of the value elements
- All Implemented Interfaces:
Map<K,V>,Observable,ObservableMapValue<K,V>,ObservableObjectValue<K>,ObservableValue<K>,ObservableMap<K,V>
- Direct Known Subclasses:
MapBinding,ReadOnlyMapProperty
public abstract class MapExpression<K,V> extends Object implements ObservableMapValue<K,V>
MapExpressionis anObservableMapValueplus additional convenience methods to generate bindings in a fluent style.A concrete sub-class of
MapExpressionhas to implement the methodObservableObjectValue.get(), which provides the actual value of this expression.If the wrapped list of a
MapExpressionisnull, all methods implementing theMapinterface will behave as if they were applied to an immutable empty list.- Since:
- JavaFX 2.1
-
-
Property Summary
Properties Type Property Description abstract ReadOnlyBooleanPropertyemptyA boolean property that istrue, if the map is empty.abstract ReadOnlyIntegerPropertysizeAn integer property that represents the size of the map.
-
Constructor Summary
Constructors Constructor Description MapExpression()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description StringBindingasString()voidclear()Removes all of the mappings from this map (optional operation).booleancontainsKey(Object obj)Returnstrueif this map contains a mapping for the specified key.booleancontainsValue(Object obj)Returnstrueif this map maps one or more keys to the specified value.abstract ReadOnlyBooleanPropertyemptyProperty()A boolean property that istrue, if the map is empty.Set<Map.Entry<K,V>>entrySet()Returns aSetview of the mappings contained in this map.Vget(Object key)Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.intgetSize()The size of the mapObservableMap<K,V>getValue()Returns the current value of thisObservableValuebooleanisEmpty()Gets the value of the property empty.BooleanBindingisEqualTo(ObservableMap<?,?> other)BooleanBindingisNotEqualTo(ObservableMap<?,?> other)BooleanBindingisNotNull()BooleanBindingisNull()Set<K>keySet()Returns aSetview of the keys contained in this map.static <K,V> MapExpression<K,V>mapExpression(ObservableMapValue<K,V> value)Returns aMapExpressionthat wraps aObservableMapValue.Vput(K key, V value)Associates the specified value with the specified key in this map (optional operation).voidputAll(Map<? extends K,? extends V> elements)Copies all of the mappings from the specified map to this map (optional operation).Vremove(Object obj)Removes the mapping for a key from this map if it is present (optional operation).intsize()Returns the number of key-value mappings in this map.abstract ReadOnlyIntegerPropertysizeProperty()An integer property that represents the size of the map.ObjectBinding<V>valueAt(ObservableValue<K> key)Creates a newObjectBindingthat contains the mapping of the specified key.ObjectBinding<V>valueAt(K key)Creates a newObjectBindingthat contains the mapping of the specified key.Collection<V>values()Returns aCollectionview of the values contained in this map.-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, entry, equals, forEach, getOrDefault, hashCode, merge, of, of, of, of, of, of, of, of, of, of, of, ofEntries, putIfAbsent, remove, replace, replace, replaceAll
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javafx.beans.Observable
addListener, removeListener
-
Methods inherited from interface javafx.collections.ObservableMap
addListener, removeListener
-
Methods inherited from interface javafx.beans.value.ObservableObjectValue
get
-
Methods inherited from interface javafx.beans.value.ObservableValue
addListener, removeListener
-
-
-
-
Property Detail
-
size
public abstract ReadOnlyIntegerProperty sizeProperty
An integer property that represents the size of the map.- See Also:
getSize()
-
empty
public abstract ReadOnlyBooleanProperty emptyProperty
A boolean property that istrue, if the map is empty.- See Also:
isEmpty()
-
-
Method Detail
-
getValue
public ObservableMap<K,V> getValue()
Description copied from interface:ObservableValueReturns the current value of thisObservableValue- Specified by:
getValuein interfaceObservableValue<K>- Returns:
- The current value
-
mapExpression
public static <K,V> MapExpression<K,V> mapExpression(ObservableMapValue<K,V> value)
Returns aMapExpressionthat wraps aObservableMapValue. If theObservableMapValueis already aMapExpression, it will be returned. Otherwise a newMapBindingis created that is bound to theObservableMapValue.- Type Parameters:
K- the type of the key elementsV- the type of the value elements- Parameters:
value- The sourceObservableMapValue- Returns:
- A
MapExpressionthat wraps theObservableMapValueif necessary - Throws:
NullPointerException- ifvalueisnull
-
getSize
public int getSize()
The size of the map- Returns:
- the size
-
sizeProperty
public abstract ReadOnlyIntegerProperty sizeProperty()
An integer property that represents the size of the map.- See Also:
getSize()
-
emptyProperty
public abstract ReadOnlyBooleanProperty emptyProperty()
A boolean property that istrue, if the map is empty.- See Also:
isEmpty()
-
valueAt
public ObjectBinding<V> valueAt(K key)
Creates a newObjectBindingthat contains the mapping of the specified key.- Parameters:
key- the key of the mapping- Returns:
- the
ObjectBinding
-
valueAt
public ObjectBinding<V> valueAt(ObservableValue<K> key)
Creates a newObjectBindingthat contains the mapping of the specified key.- Parameters:
key- the key of the mapping- Returns:
- the
ObjectBinding - Throws:
NullPointerException- ifkeyisnull
-
isEqualTo
public BooleanBinding isEqualTo(ObservableMap<?,?> other)
- Parameters:
other- the otherObservableMap- Returns:
- the new
BooleanBinding - Throws:
NullPointerException- ifotherisnull
-
isNotEqualTo
public BooleanBinding isNotEqualTo(ObservableMap<?,?> other)
- Parameters:
other- the otherObservableMap- Returns:
- the new
BooleanBinding - Throws:
NullPointerException- ifotherisnull
-
isNull
public BooleanBinding isNull()
- Returns:
- the new
BooleanBinding
-
isNotNull
public BooleanBinding isNotNull()
- Returns:
- the new
BooleanBinding
-
asString
public StringBinding asString()
Creates aStringBindingthat holds the value of theMapExpressionturned into aString. If the value of thisMapExpressionchanges, the value of theStringBindingwill be updated automatically.- Returns:
- the new
StringBinding
-
size
public int size()
Description copied from interface:MapReturns the number of key-value mappings in this map. If the map contains more thanInteger.MAX_VALUEelements, returnsInteger.MAX_VALUE.
-
isEmpty
public boolean isEmpty()
Gets the value of the property empty.
-
containsKey
public boolean containsKey(Object obj)
Description copied from interface:MapReturnstrueif this map contains a mapping for the specified key. More formally, returnstrueif and only if this map contains a mapping for a keyksuch thatObjects.equals(key, k). (There can be at most one such mapping.)- Specified by:
containsKeyin interfaceMap<K,V>- Parameters:
obj- key whose presence in this map is to be tested- Returns:
trueif this map contains a mapping for the specified key
-
containsValue
public boolean containsValue(Object obj)
Description copied from interface:MapReturnstrueif this map maps one or more keys to the specified value. More formally, returnstrueif and only if this map contains at least one mapping to a valuevsuch thatObjects.equals(value, v). This operation will probably require time linear in the map size for most implementations of theMapinterface.- Specified by:
containsValuein interfaceMap<K,V>- Parameters:
obj- value whose presence in this map is to be tested- Returns:
trueif this map maps one or more keys to the specified value
-
put
public V put(K key, V value)
Description copied from interface:MapAssociates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A mapmis said to contain a mapping for a keykif and only ifm.containsKey(k)would returntrue.)- Specified by:
putin interfaceMap<K,V>- Parameters:
key- key with which the specified value is to be associatedvalue- value to be associated with the specified key- Returns:
- the previous value associated with
key, ornullif there was no mapping forkey. (Anullreturn can also indicate that the map previously associatednullwithkey, if the implementation supportsnullvalues.)
-
remove
public V remove(Object obj)
Description copied from interface:MapRemoves the mapping for a key from this map if it is present (optional operation). More formally, if this map contains a mapping from keykto valuevsuch thatObjects.equals(key, k), that mapping is removed. (The map can contain at most one such mapping.)Returns the value to which this map previously associated the key, or
nullif the map contained no mapping for the key.If this map permits null values, then a return value of
nulldoes not necessarily indicate that the map contained no mapping for the key; it's also possible that the map explicitly mapped the key tonull.The map will not contain a mapping for the specified key once the call returns.
-
putAll
public void putAll(Map<? extends K,? extends V> elements)
Description copied from interface:MapCopies all of the mappings from the specified map to this map (optional operation). The effect of this call is equivalent to that of callingput(k, v)on this map once for each mapping from keykto valuevin the specified map. The behavior of this operation is undefined if the specified map is modified while the operation is in progress.
-
clear
public void clear()
Description copied from interface:MapRemoves all of the mappings from this map (optional operation). The map will be empty after this call returns.
-
keySet
public Set<K> keySet()
Description copied from interface:MapReturns aSetview of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's ownremoveoperation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Set.remove,removeAll,retainAll, andclearoperations. It does not support theaddoraddAlloperations.
-
values
public Collection<V> values()
Description copied from interface:MapReturns aCollectionview of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress (except through the iterator's ownremoveoperation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Collection.remove,removeAll,retainAllandclearoperations. It does not support theaddoraddAlloperations.
-
entrySet
public Set<Map.Entry<K,V>> entrySet()
Description copied from interface:MapReturns aSetview of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's ownremoveoperation, or through thesetValueoperation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Set.remove,removeAll,retainAllandclearoperations. It does not support theaddoraddAlloperations.
-
get
public V get(Object key)
Description copied from interface:MapReturns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.More formally, if this map contains a mapping from a key
kto a valuevsuch thatObjects.equals(key, k), then this method returnsv; otherwise it returnsnull. (There can be at most one such mapping.)If this map permits null values, then a return value of
nulldoes not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key tonull. ThecontainsKeyoperation may be used to distinguish these two cases.
-
-