org.infinispan.tree
Class NodeImpl<K,V>

java.lang.Object
  extended by org.infinispan.batch.AutoBatchSupport
      extended by org.infinispan.tree.TreeStructureSupport
          extended by org.infinispan.tree.NodeImpl<K,V>
All Implemented Interfaces:
Node<K,V>

public class NodeImpl<K,V>
extends TreeStructureSupport
implements Node<K,V>

Implementation backed by an AtomicMap

Since:
4.0
Author:
Manik Surtani (manik AT jboss DOT org)

Field Summary
 
Fields inherited from class org.infinispan.tree.TreeStructureSupport
cache, icc
 
Fields inherited from class org.infinispan.batch.AutoBatchSupport
batchContainer
 
Constructor Summary
NodeImpl(Fqn fqn, Cache<?,?> cache, BatchContainer batchContainer, InvocationContextContainer icc)
           
 
Method Summary
 Node<K,V> addChild(Fqn f)
          Adds a child node with the given Fqn under the current node.
 Node<K,V> addChild(Fqn f, Flag... flags)
           
 void clearData()
          Removes all mappings from the node's data map.
 void clearData(Flag... flags)
           
 int dataSize()
           
 int dataSize(Flag... flags)
           
 boolean equals(Object o)
           
 V get(K key)
          Returns the value to which this node maps the specified key.
 V get(K key, Flag... flags)
           
 Node<K,V> getChild(Fqn f)
          Returns the child node
 Node<K,V> getChild(Fqn f, Flag... flags)
           
 Node<K,V> getChild(Object name)
           
 Node<K,V> getChild(Object name, Flag... flags)
           
 Set<Node<K,V>> getChildren()
          Returns an immutable set of children nodes.
 Set<Node<K,V>> getChildren(Flag... flags)
           
 Set<Object> getChildrenNames()
          Returns an immutable set of children node names.
 Set<Object> getChildrenNames(Flag... flags)
           
 Map<K,V> getData()
          Returns a map containing the data in this Node.
 Map<K,V> getData(Flag... flags)
           
 Fqn getFqn()
          Returns the Fqn which represents the location of this Node in the cache structure.
 Set<K> getKeys()
          Returns a Set containing the data in this Node.
 Set<K> getKeys(Flag... flags)
           
 Node<K,V> getParent()
          Returns the parent node.
 Node<K,V> getParent(Flag... flags)
           
 boolean hasChild(Fqn f)
          Returns true if the child node denoted by the relative Fqn passed in exists.
 boolean hasChild(Fqn f, Flag... flags)
           
 boolean hasChild(Object o)
          Returns true if the child node denoted by the Object name passed in exists.
 boolean hasChild(Object o, Flag... flags)
           
 int hashCode()
           
 boolean isValid()
          Tests if a node reference is still valid.
 V put(K key, V value)
          Associates the specified value with the specified key for this node.
 V put(K key, V value, Flag... flags)
           
 void putAll(Map<? extends K,? extends V> map)
          Copies all of the mappings from the specified map to this node's map.
 void putAll(Map<? extends K,? extends V> map, Flag... flags)
           
 V putIfAbsent(K key, V value)
          If the specified key is not already associated with a value, associate it with the given value, and returns the Object (if any) that occupied the space, or null.
 V putIfAbsent(K key, V value, Flag... flags)
           
 V remove(K key)
          Removes the mapping for this key from this node if it is present.
 V remove(K key, Flag... flags)
           
 boolean removeChild(Fqn f)
          Removes a child node specified by the given relative Fqn.
 boolean removeChild(Fqn f, Flag... flags)
           
 boolean removeChild(Object childName)
          Removes a child node specified by the given name.
 boolean removeChild(Object childName, Flag... flags)
           
 void removeChildren()
           
 void removeChildren(Flag... flags)
           
 V replace(K key, V value)
          Replace entry for key only if currently mapped to some value.
 V replace(K key, V value, Flag... flags)
           
 boolean replace(K key, V oldValue, V newValue)
          Replace entry for key only if currently mapped to given value.
 boolean replace(K key, V oldValue, V value, Flag... flags)
           
 void replaceAll(Map<? extends K,? extends V> map)
          Similar to Node.putAll(java.util.Map) except that it removes any entries that exists in the data map first.
 void replaceAll(Map<? extends K,? extends V> map, Flag... flags)
           
 String toString()
           
 
Methods inherited from class org.infinispan.tree.TreeStructureSupport
exists, getAtomicMap, isLocked, printTree
 
Methods inherited from class org.infinispan.batch.AutoBatchSupport
assertBatchingSupported, endAtomic, startAtomic
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NodeImpl

public NodeImpl(Fqn fqn,
                Cache<?,?> cache,
                BatchContainer batchContainer,
                InvocationContextContainer icc)
Method Detail

getParent

public Node<K,V> getParent()
Description copied from interface: Node
Returns the parent node. If this is the root node, this method returns null.

Specified by:
getParent in interface Node<K,V>
Returns:
the parent node, or null if this is the root node

getParent

public Node<K,V> getParent(Flag... flags)
Specified by:
getParent in interface Node<K,V>

getChildren

public Set<Node<K,V>> getChildren()
Description copied from interface: Node
Returns an immutable set of children nodes.

Specified by:
getChildren in interface Node<K,V>
Returns:
an immutable Set of child nodes. Empty Set if there aren't any children.

getChildren

public Set<Node<K,V>> getChildren(Flag... flags)
Specified by:
getChildren in interface Node<K,V>

getChildrenNames

public Set<Object> getChildrenNames()
Description copied from interface: Node
Returns an immutable set of children node names.

Specified by:
getChildrenNames in interface Node<K,V>
Returns:
an immutable Set of child node names. Empty Set if there aren't any children.

getChildrenNames

public Set<Object> getChildrenNames(Flag... flags)
Specified by:
getChildrenNames in interface Node<K,V>

getData

public Map<K,V> getData()
Description copied from interface: Node
Returns a map containing the data in this Node.

Specified by:
getData in interface Node<K,V>
Returns:
a Map containing the data in this Node. If there is no data, an empty Map is returned. The Map returned is always immutable.

getData

public Map<K,V> getData(Flag... flags)
Specified by:
getData in interface Node<K,V>

getKeys

public Set<K> getKeys()
Description copied from interface: Node
Returns a Set containing the data in this Node.

Specified by:
getKeys in interface Node<K,V>
Returns:
a Set containing the data in this Node. If there is no data, an empty Set is returned. The Set returned is always immutable.

getKeys

public Set<K> getKeys(Flag... flags)
Specified by:
getKeys in interface Node<K,V>

getFqn

public Fqn getFqn()
Description copied from interface: Node
Returns the Fqn which represents the location of this Node in the cache structure. The Fqn returned is absolute.

Specified by:
getFqn in interface Node<K,V>
Returns:
The Fqn which represents the location of this Node in the cache structure. The Fqn returned is absolute.

addChild

public Node<K,V> addChild(Fqn f)
Description copied from interface: Node
Adds a child node with the given Fqn under the current node. Returns the newly created node.

If the child exists returns the child node anyway. Guaranteed to return a non-null node.

The Fqn passed in is relative to the current node. The new child node will have an absolute fqn calculated as follows:

new Fqn(getFqn(), f)
. See Fqn for the operation of this constructor.

Specified by:
addChild in interface Node<K,V>
Parameters:
f - Fqn of the child node, relative to the current node.
Returns:
the newly created node, or the existing node if one already exists.

addChild

public Node<K,V> addChild(Fqn f,
                          Flag... flags)
Specified by:
addChild in interface Node<K,V>

removeChild

public boolean removeChild(Fqn f)
Description copied from interface: Node
Removes a child node specified by the given relative Fqn.

If you wish to remove children based on absolute Fqns, use the TreeCache interface instead.

Specified by:
removeChild in interface Node<K,V>
Parameters:
f - Fqn of the child node, relative to the current node.
Returns:
true if the node was found and removed, false otherwise

removeChild

public boolean removeChild(Fqn f,
                           Flag... flags)
Specified by:
removeChild in interface Node<K,V>

removeChild

public boolean removeChild(Object childName)
Description copied from interface: Node
Removes a child node specified by the given name.

Specified by:
removeChild in interface Node<K,V>
Parameters:
childName - name of the child node, directly under the current node.
Returns:
true if the node was found and removed, false otherwise

removeChild

public boolean removeChild(Object childName,
                           Flag... flags)
Specified by:
removeChild in interface Node<K,V>

getChild

public Node<K,V> getChild(Fqn f)
Description copied from interface: Node
Returns the child node

Specified by:
getChild in interface Node<K,V>
Parameters:
f - Fqn of the child node
Returns:
null if the child does not exist.

getChild

public Node<K,V> getChild(Fqn f,
                          Flag... flags)
Specified by:
getChild in interface Node<K,V>

getChild

public Node<K,V> getChild(Object name)
Specified by:
getChild in interface Node<K,V>
Parameters:
name - name of the child
Returns:
a direct child of the current node.

getChild

public Node<K,V> getChild(Object name,
                          Flag... flags)
Specified by:
getChild in interface Node<K,V>

put

public V put(K key,
             V value)
Description copied from interface: Node
Associates the specified value with the specified key for this node. If this node previously contained a mapping for this key, the old value is replaced by the specified value.

Specified by:
put in interface Node<K,V>
Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
Returns the old value contained under this key. Null if key doesn't exist.

put

public V put(K key,
             V value,
             Flag... flags)
Specified by:
put in interface Node<K,V>

putIfAbsent

public V putIfAbsent(K key,
                     V value)
Description copied from interface: Node
If the specified key is not already associated with a value, associate it with the given value, and returns the Object (if any) that occupied the space, or null.

Equivalent to calling

   if (!node.getKeys().contains(key))
     return node.put(key, value);
   else
     return node.get(key);
 

except that this is atomic.

Specified by:
putIfAbsent in interface Node<K,V>
Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
previous value associated with specified key, or null if there was no mapping for key.

putIfAbsent

public V putIfAbsent(K key,
                     V value,
                     Flag... flags)
Specified by:
putIfAbsent in interface Node<K,V>

replace

public V replace(K key,
                 V value)
Description copied from interface: Node
Replace entry for key only if currently mapped to some value. Acts as
 if ((node.getKeys().contains(key))
 {
     return node.put(key, value);
 }
 else
     return null;
 

except that this is atomic.

Specified by:
replace in interface Node<K,V>
Parameters:
key - key with which the specified value is associated.
value - value to be associated with the specified key.
Returns:
previous value associated with specified key, or null if there was no mapping for key.

replace

public V replace(K key,
                 V value,
                 Flag... flags)
Specified by:
replace in interface Node<K,V>

replace

public boolean replace(K key,
                       V oldValue,
                       V newValue)
Description copied from interface: Node
Replace entry for key only if currently mapped to given value. Acts as
 if (node.get(key).equals(oldValue))
 {
     node.put(key, newValue);
     return true;
 }
 else
     return false;
 

except that this is atomic.

Specified by:
replace in interface Node<K,V>
Parameters:
key - key with which the specified value is associated.
oldValue - value expected to be associated with the specified key.
newValue - value to be associated with the specified key.
Returns:
true if the value was replaced

replace

public boolean replace(K key,
                       V oldValue,
                       V value,
                       Flag... flags)
Specified by:
replace in interface Node<K,V>

putAll

public void putAll(Map<? extends K,? extends V> map)
Description copied from interface: Node
Copies all of the mappings from the specified map to this node's map. If any data exists, existing keys are overwritten with the keys in the new map. The behavior is equivalent to:
 Node node;
 for (Map.Entry me : map.entrySet())
   node.put(me.getKey(), me.getValue());
 

Specified by:
putAll in interface Node<K,V>
Parameters:
map - map to copy from

putAll

public void putAll(Map<? extends K,? extends V> map,
                   Flag... flags)
Specified by:
putAll in interface Node<K,V>

replaceAll

public void replaceAll(Map<? extends K,? extends V> map)
Description copied from interface: Node
Similar to Node.putAll(java.util.Map) except that it removes any entries that exists in the data map first. Note that this happens atomically, under a single lock. This is the analogous to doing a Node.clearData() followed by a Node.putAll(java.util.Map) in the same transaction.

Specified by:
replaceAll in interface Node<K,V>
Parameters:
map - map to copy from

replaceAll

public void replaceAll(Map<? extends K,? extends V> map,
                       Flag... flags)
Specified by:
replaceAll in interface Node<K,V>

get

public V get(K key)
Description copied from interface: Node
Returns the value to which this node maps the specified key. Returns null if the node contains no mapping for this key.

Specified by:
get in interface Node<K,V>
Parameters:
key - key of the data to return
Returns:
the value to which this node maps the specified key, or null if the map contains no mapping for this key

get

public V get(K key,
             Flag... flags)
Specified by:
get in interface Node<K,V>

remove

public V remove(K key)
Description copied from interface: Node
Removes the mapping for this key from this node if it is present. Returns the value to which the node previously associated the key, or null if the node contained no mapping for this key

Specified by:
remove in interface Node<K,V>
Parameters:
key - key whose mapping is to be removed
Returns:
previous value associated with specified key, or null if there was no mapping for key

remove

public V remove(K key,
                Flag... flags)
Specified by:
remove in interface Node<K,V>

clearData

public void clearData()
Description copied from interface: Node
Removes all mappings from the node's data map.

Specified by:
clearData in interface Node<K,V>

clearData

public void clearData(Flag... flags)
Specified by:
clearData in interface Node<K,V>

dataSize

public int dataSize()
Specified by:
dataSize in interface Node<K,V>
Returns:
the number of elements (key/value pairs) in the node's data map.

dataSize

public int dataSize(Flag... flags)
Specified by:
dataSize in interface Node<K,V>

hasChild

public boolean hasChild(Fqn f)
Description copied from interface: Node
Returns true if the child node denoted by the relative Fqn passed in exists.

Specified by:
hasChild in interface Node<K,V>
Parameters:
f - Fqn relative to the current node of the child you are testing the existence of.
Returns:
true if the child node denoted by the relative Fqn passed in exists.

hasChild

public boolean hasChild(Fqn f,
                        Flag... flags)
Specified by:
hasChild in interface Node<K,V>

hasChild

public boolean hasChild(Object o)
Description copied from interface: Node
Returns true if the child node denoted by the Object name passed in exists.

Specified by:
hasChild in interface Node<K,V>
Parameters:
o - name of the child, relative to the current node
Returns:
true if the child node denoted by the name passed in exists.

hasChild

public boolean hasChild(Object o,
                        Flag... flags)
Specified by:
hasChild in interface Node<K,V>

isValid

public boolean isValid()
Description copied from interface: Node
Tests if a node reference is still valid. A node reference may become invalid if it has been removed, invalidated or moved, either locally or remotely. If a node is invalid, it should be fetched again from the cache or a valid parent node. Operations on invalid nodes will throw a NodeNotValidException.

Specified by:
isValid in interface Node<K,V>
Returns:
true if the node is valid.

removeChildren

public void removeChildren()
Specified by:
removeChildren in interface Node<K,V>

removeChildren

public void removeChildren(Flag... flags)
Specified by:
removeChildren in interface Node<K,V>

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

Google Analytics

Copyright © 2010 JBoss, a division of Red Hat. All Rights Reserved.