Package com.tangosol.util
Class SimpleMapEntry<K,V>
java.lang.Object
com.tangosol.util.Base
com.tangosol.util.SimpleMapEntry<K,V>
- All Implemented Interfaces:
InvocableMap.Entry<K,
,V> MapTrigger.Entry<K,
,V> QueryMap.Entry<K,
,V> Serializable
,Cloneable
,Map.Entry<K,
V>
- Direct Known Subclasses:
AbstractKeyBasedMap.EntrySet.Entry
,BinaryMap.Entry
,InvocableMapHelper.SimpleEntry
,SimpleElement.AttributeMap.Entry
public class SimpleMapEntry<K,V>
extends Base
implements MapTrigger.Entry<K,V>, Cloneable, Serializable
A map entry (key-value pair). The Map.entrySet method returns
a collection-view of the map, whose elements are of this class. The
only way to obtain a reference to a map entry is from the
iterator of this collection-view. These Map.Entry objects are
valid only for the duration of the iteration; more formally,
the behavior of a map entry is undefined if the backing map has been
modified after the entry was returned by the iterator, except through
the iterator's own remove operation, or through the
setValue operation on a map entry returned by the iterator.
- Author:
- cp 2002.02.07
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
Default constructor.SimpleMapEntry
(Map.Entry<K, V> entry) Copy constructor.protected
SimpleMapEntry
(K key) Construct a SimpleMapEntry with just a key.SimpleMapEntry
(K key, V value) Construct a SimpleMapEntry with a key and a value.SimpleMapEntry
(K key, V value, V origValue) Construct a SimpleMapEntry with a key, value and original value. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Clone the Entry.boolean
Compares the specified object with this entry for equality.<T,
E> E extract
(ValueExtractor<T, E> extractor) Extract a value out of the Entry's key or value.getKey()
Return the key corresponding to this entry.Determine the value that existed before the start of the mutating operation that is being evaluated by the trigger.getValue()
Returns the value corresponding to this entry.int
hashCode()
Returns the hash code value for this map entry.boolean
Determine whether or not the Entry existed before the start of the mutating operation that is being evaluated by the trigger.boolean
Determine if this Entry exists in the Map.boolean
Determine if this Entry has been synthetically mutated.void
remove
(boolean fSynthetic) Remove this Entry from the Map if it is present in the Map.Replaces the value corresponding to this entry with the specified value (optional operation).void
Store the value corresponding to this entry.toString()
Render the map entry as a String.<U> void
update
(ValueUpdater<V, U> updater, U value) Update the Entry's value.Methods inherited from class com.tangosol.util.Base
azzert, azzert, azzert, azzertFailed, breakLines, breakLines, capitalize, checkNotEmpty, checkNotNull, checkRange, computeSafeWaitTime, decimalValue, dup, dup, ensureBigDecimal, ensureClassLoader, ensureRuntimeException, ensureRuntimeException, equals, equalsDeep, err, err, err, err, err, escape, formatDateTime, getCallerStackFrame, getCommonMonitor, getCommonMonitor, getCommonMonitor, getContextClassLoader, getContextClassLoader, getDeepMessage, getErr, getLastSafeTimeMillis, getLog, getMaxDecDigits, getMaxHexDigits, getOriginalException, getOut, getProcessRandom, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mergeArray, mergeBooleanArray, mergeByteArray, mergeCharArray, mergeDoubleArray, mergeFloatArray, mergeIntArray, mergeLongArray, mod, mod, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, randomize, randomize, randomize, randomize, read, read, read, read, read, read, read, replace, setErr, setLog, setLogEcho, setOut, sleep, toBandwidthString, toBandwidthString, toCharEscape, toCrc, toCrc, toCrc, toCrc, toCrc, toDecString, toDelimitedString, toDelimitedString, toDelimitedString, toDelimitedString, toHex, toHex, toHexDump, toHexEscape, toHexEscape, toHexEscape, toHexEscape, toHexString, toMemorySizeString, toMemorySizeString, toQuotedCharEscape, toQuotedStringEscape, toSqlString, toString, toString, toStringEscape, toUnicodeEscape, trace, trace, trace, trace, trace, trace, trace, trace, trace, truncateString, truncateString, wait
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.tangosol.util.InvocableMap.Entry
asBinaryEntry, getValue, getValue
Methods inherited from interface com.tangosol.util.QueryMap.Entry
extractFromKey, extractFromValue
-
Field Details
-
NO_VALUE
Constant used to indicate that the original value does not exist. -
m_oKey
The key. This object reference will not change for the life of the Entry. -
m_oValue
The value. This object reference can change within the life of the Entry. -
m_oOrigValue
The original value. This object reference will not change within the life of the Entry.
-
-
Constructor Details
-
SimpleMapEntry
protected SimpleMapEntry()Default constructor. -
SimpleMapEntry
Construct a SimpleMapEntry with just a key.- Parameters:
key
- an object for the key
-
SimpleMapEntry
Copy constructor.- Parameters:
entry
- an entry to copy from
-
SimpleMapEntry
Construct a SimpleMapEntry with a key and a value.- Parameters:
key
- an object for the keyvalue
- an object for the value
-
SimpleMapEntry
Construct a SimpleMapEntry with a key, value and original value.- Parameters:
key
- an object for the keyvalue
- an object for the valueorigValue
- an object for the original value- Since:
- Coherence 3.6
-
-
Method Details
-
getKey
Return the key corresponding to this entry. The resultant key does not necessarily exist within the containing Map, which is to say that InvocableMap.this.containsKey(getKey()) could return false. To test for the presence of this key within the Map, useInvocableMap.Entry.isPresent()
, and to create the entry for the key, useInvocableMap.Entry.setValue(V)
. -
getValue
Returns the value corresponding to this entry. If the mapping has been removed from the backing map (by the iterator's remove operation), the results of this call are undefined. -
setValue
Replaces the value corresponding to this entry with the specified value (optional operation). (Writes through to the map.) The behavior of this call is undefined if the mapping has already been removed from the map (by the iterator's remove operation). -
getOriginalValue
Determine the value that existed before the start of the mutating operation that is being evaluated by the trigger.- Specified by:
getOriginalValue
in interfaceMapTrigger.Entry<K,
V> - Returns:
- the original value corresponding to this Entry; may be null if the value is null or if the Entry did not exist in the Map
-
isOriginalPresent
public boolean isOriginalPresent()Determine whether or not the Entry existed before the start of the mutating operation that is being evaluated by the trigger.- Specified by:
isOriginalPresent
in interfaceMapTrigger.Entry<K,
V> - Returns:
- true iff this Entry was existent in the containing Map
-
setValue
Store the value corresponding to this entry. If the entry does not exist, then the entry will be created by invoking this method, even with a null value (assuming the Map supports null values).Unlike the other form of
setValue
, this form does not return the previous value, and as a result may be significantly less expensive (in terms of cost of execution) for certain Map implementations.- Specified by:
setValue
in interfaceInvocableMap.Entry<K,
V> - Parameters:
oValue
- the new value for this EntryfSynthetic
- pass true only if the insertion into or modification of the Map should be treated as a synthetic event
-
update
Update the Entry's value. Calling this method is semantically equivalent to:V target = entry.getValue(); updater.update(target, value); entry.setValue(target, false);
The benefit of using this method is that it may allow the Entry implementation to significantly optimize the operation, such as for purposes of delta updates and backup maintenance.- Specified by:
update
in interfaceInvocableMap.Entry<K,
V> - Type Parameters:
U
- the class of the value- Parameters:
updater
- a ValueUpdater used to modify the Entry's valuevalue
- the new value for this Entry
-
isPresent
public boolean isPresent()Determine if this Entry exists in the Map. If the Entry is not present, it can be created by callingInvocableMap.Entry.setValue(Object)
orInvocableMap.Entry.setValue(Object, boolean)
. If the Entry is present, it can be destroyed by callingInvocableMap.Entry.remove(boolean)
.- Specified by:
isPresent
in interfaceInvocableMap.Entry<K,
V> - Returns:
- true iff this Entry is existent in the containing Map
-
isSynthetic
public boolean isSynthetic()Determine if this Entry has been synthetically mutated. This method returnsfalse
if either a non-synthetic update was made or the entry has not been modified.- Specified by:
isSynthetic
in interfaceInvocableMap.Entry<K,
V> - Returns:
- true if the Entry has been synthetically mutated
-
remove
public void remove(boolean fSynthetic) Description copied from interface:InvocableMap.Entry
Remove this Entry from the Map if it is present in the Map.This method supports both the operation corresponding to
Map.remove(java.lang.Object)
as well as synthetic operations such as eviction. If the containing Map does not differentiate between the two, then this method will always be identical to InvocableMap.this.remove(getKey()).- Specified by:
remove
in interfaceInvocableMap.Entry<K,
V> - Parameters:
fSynthetic
- pass true only if the removal from the Map should be treated as a synthetic event- Throws:
UnsupportedOperationException
- by default
-
extract
Extract a value out of the Entry's key or value. Calling this method is semantically equivalent to extractor.extract(entry.getValue()), but this method may be significantly less expensive. For example, the resultant value may be obtained from a forward index, avoiding a potential object de-serialization.- Specified by:
extract
in interfaceQueryMap.Entry<K,
V> - Type Parameters:
T
- the type of the value to extract fromE
- the type of value that will be extracted- Parameters:
extractor
- a ValueExtractor to apply to the Entry's key or value- Returns:
- the extracted value
-
equals
Compares the specified object with this entry for equality. Returns true if the given object is also a map entry and the two entries represent the same mapping. More formally, two entries e1 and e2 represent the same mapping if(e1.getKey()==null ? e2.getKey()==null : e1.getKey().equals(e2.getKey())) && (e1.getValue()==null ? e2.getValue()==null : e1.getValue().equals(e2.getValue()))
This ensures that the equals method works properly across different implementations of the Map.Entry interface. -
hashCode
public int hashCode()Returns the hash code value for this map entry. The hash code of a map entry e is defined to be:(e.getKey()==null ? 0 : e.getKey().hashCode()) ^ (e.getValue()==null ? 0 : e.getValue().hashCode())
This ensures that e1.equals(e2) implies that e1.hashCode()==e2.hashCode() for any two Entries e1 and e2, as required by the general contract of Object.hashCode. -
toString
Render the map entry as a String. -
clone
Clone the Entry.
-