org.apache.hadoop.hbase.regionserver
Class LruHashMap.Entry<K extends HeapSize,V extends HeapSize>

java.lang.Object
  extended by org.apache.hadoop.hbase.regionserver.LruHashMap.Entry<K,V>
All Implemented Interfaces:
Map.Entry<K,V>, HeapSize
Enclosing class:
LruHashMap<K extends HeapSize,V extends HeapSize>

protected static class LruHashMap.Entry<K extends HeapSize,V extends HeapSize>
extends Object
implements Map.Entry<K,V>, HeapSize

Entry to store key/value mappings.

Contains previous and next pointers for the doubly linked-list which is used for LRU eviction.

Instantiations of this class are memory aware. Both the key and value classes used must also implement HeapSize.


Field Summary
protected  int hash
          The hash value for this entries key
protected  long heapSize
          The precomputed heap size of this entry
protected  K key
          The key
protected  LruHashMap.Entry<K,V> next
          The next entry in the hash chain (for collisions)
protected  LruHashMap.Entry<K,V> nextPtr
          The next entry in the LRU list (towards MRU)
protected  LruHashMap.Entry<K,V> prevPtr
          The previous entry in the LRU list (towards LRU)
protected  V value
          The value
 
Method Summary
 boolean equals(Object o)
          Returns true is the specified entry has the same key and the same value as this entry.
 K getKey()
          Get the key of this entry.
protected  LruHashMap.Entry<K,V> getNextPtr()
          Returns the next pointer for the entry in teh LRU.
protected  LruHashMap.Entry<K,V> getPrevPtr()
          Returns the previous pointer for the entry in the LRU.
 V getValue()
          Get the value of this entry.
 int hashCode()
          Returns the hash code of the entry by xor'ing the hash values of the key and value of this entry.
 long heapSize()
          Returns the pre-computed and "deep" size of the Entry
protected  long replaceValue(V newValue)
          Replace the value of this entry.
protected  void setNextPtr(LruHashMap.Entry<K,V> nextPtr)
          Sets the next pointer for the entry in the LRU.
protected  void setPrevPtr(LruHashMap.Entry<K,V> prevPtr)
          Sets the previous pointer for the entry in the LRU.
 V setValue(V newValue)
          Set the value of this entry.
 String toString()
          Returns String representation of the entry in form "key=value"
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

key

protected final K extends HeapSize key
The key


value

protected V extends HeapSize value
The value


hash

protected final int hash
The hash value for this entries key


next

protected LruHashMap.Entry<K extends HeapSize,V extends HeapSize> next
The next entry in the hash chain (for collisions)


prevPtr

protected LruHashMap.Entry<K extends HeapSize,V extends HeapSize> prevPtr
The previous entry in the LRU list (towards LRU)


nextPtr

protected LruHashMap.Entry<K extends HeapSize,V extends HeapSize> nextPtr
The next entry in the LRU list (towards MRU)


heapSize

protected long heapSize
The precomputed heap size of this entry

Method Detail

getKey

public K getKey()
Get the key of this entry.

Specified by:
getKey in interface Map.Entry<K extends HeapSize,V extends HeapSize>
Returns:
the key associated with this entry

getValue

public V getValue()
Get the value of this entry.

Specified by:
getValue in interface Map.Entry<K extends HeapSize,V extends HeapSize>
Returns:
the value currently associated with this entry

setValue

public V setValue(V newValue)
Set the value of this entry. It is not recommended to use this method when changing the value. Rather, using replaceValue will return the difference in heap usage between the previous and current values.

Specified by:
setValue in interface Map.Entry<K extends HeapSize,V extends HeapSize>
Parameters:
newValue - the new value to associate with this entry
Returns:
the value previously associated with this entry

replaceValue

protected long replaceValue(V newValue)
Replace the value of this entry. Computes and returns the difference in heap size when changing the value associated with this entry.

Parameters:
newValue - the new value to associate with this entry
Returns:
the change in heap usage of this entry in bytes

equals

public boolean equals(Object o)
Returns true is the specified entry has the same key and the same value as this entry.

Specified by:
equals in interface Map.Entry<K extends HeapSize,V extends HeapSize>
Overrides:
equals in class Object
Parameters:
o - entry to test against current
Returns:
true is entries have equal key and value, false if no

hashCode

public int hashCode()
Returns the hash code of the entry by xor'ing the hash values of the key and value of this entry.

Specified by:
hashCode in interface Map.Entry<K extends HeapSize,V extends HeapSize>
Overrides:
hashCode in class Object
Returns:
hash value of this entry

toString

public String toString()
Returns String representation of the entry in form "key=value"

Overrides:
toString in class Object
Returns:
string value of entry

setPrevPtr

protected void setPrevPtr(LruHashMap.Entry<K,V> prevPtr)
Sets the previous pointer for the entry in the LRU.

Parameters:
prevPtr - previous entry

getPrevPtr

protected LruHashMap.Entry<K,V> getPrevPtr()
Returns the previous pointer for the entry in the LRU.

Returns:
previous entry

setNextPtr

protected void setNextPtr(LruHashMap.Entry<K,V> nextPtr)
Sets the next pointer for the entry in the LRU.

Parameters:
nextPtr - next entry

getNextPtr

protected LruHashMap.Entry<K,V> getNextPtr()
Returns the next pointer for the entry in teh LRU.

Returns:
next entry

heapSize

public long heapSize()
Returns the pre-computed and "deep" size of the Entry

Specified by:
heapSize in interface HeapSize
Returns:
size of the entry in bytes


Copyright © 2007-2016 The Apache Software Foundation. All Rights Reserved.