org.modeshape.graph.connector.base
Class MapNode

java.lang.Object
  extended by org.modeshape.graph.connector.base.MapNode
All Implemented Interfaces:
Serializable, Cloneable, Node
Direct Known Subclasses:
InfinispanNode, InMemoryNode, JBossCacheNode

public class MapNode
extends Object
implements Node, Serializable, Cloneable

A Node implementation used by the hashed-based connector (see MapWorkspace and MapTransaction), which stores all node state keyed by the node's hash (or identifier).

Strictly speaking, this class is not immutable or thread safe. However, the persisted state cannot be changed. Instead, any changes made to the object are stored in a transient area and are made "persistable"via the freeze() method.

The MapTransaction maintains an unfrozen, changed instance within it transactional state, and always puts the frozen, read-only representation inside the

See Also:
Serialized Form

Nested Class Summary
protected  class MapNode.Changes
           
 
Field Summary
protected  MapNode.Changes changes
          The changes made to this object, making it unfrozen
 
Constructor Summary
  MapNode(UUID uuid)
          Create a root node with the supplied UUID.
  MapNode(UUID uuid, Path.Segment name, UUID parent, Iterable<Property> properties, List<UUID> children)
          Create a new node instance.
  MapNode(UUID uuid, Path.Segment name, UUID parent, Map<Name,Property> properties, List<UUID> children)
          Create a new node instance.
protected MapNode(UUID uuid, Path.Segment name, UUID parent, Map<Name,Property> properties, List<UUID> children, int version)
          Create a new node instance.
 
Method Summary
 MapNode clone()
           This method never clones the changes.
 boolean equals(Object obj)
          
 MapNode freeze()
          Return the frozen node with all internal state reflective of any changes.
 List<UUID> getChildren()
           
 Path.Segment getName()
          Returns the name of this node along with its SNS index within its parent's children
 UUID getParent()
           
 Map<Name,Property> getProperties()
          Returns properties of this node.
 Property getProperty(Name name)
          Returns the property with the supplied name.
 UUID getUuid()
          Returns the UUID for this node
 int getVersion()
          Get the version number of this node.
protected  boolean hasChanges()
          Determine if this node has any unsaved changes.
 int hashCode()
          
protected  MapNode.Changes newChanges()
          Create the MapNode.Changes implementation.
 String toString()
          
 MapNode withChild(int index, UUID child)
          Create a copy of this node except adding the supplied node into the existing children at the specified index.
 MapNode withChild(UUID child)
          Create a copy of this node except adding the supplied node at the end of the existing children.
 MapNode withName(Path.Segment name)
          Create a copy of this node except using the supplied name.
 MapNode withoutChild(UUID child)
          Create a copy of this node except without the supplied child node.
 MapNode withoutChildren()
          Create a copy of this node except with none of the children.
 MapNode withoutProperties()
           
 MapNode withoutProperty(Name propertyName)
          Create a copy of this node except with the new property.
 MapNode withParent(UUID parent)
          Create a copy of this node except using the supplied parent.
 MapNode withProperties(Iterable<Property> propertiesToSet, Iterable<Name> propertiesToRemove, boolean removeAllExisting)
          Create a copy of this node except with the changes to the properties.
 MapNode withProperty(Property property)
          Create a copy of this node except with the new property.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

changes

protected transient MapNode.Changes changes
The changes made to this object, making it unfrozen

Constructor Detail

MapNode

public MapNode(UUID uuid,
               Path.Segment name,
               UUID parent,
               Map<Name,Property> properties,
               List<UUID> children)
Create a new node instance.

Parameters:
uuid - the UUID of the node; may not be null
name - the name of the node; may be null only if the parent is also null
parent - the UUID of the parent node; may be null only if the name is null
properties - the unmodifiable map of properties; may be null or empty
children - the unmodificable list of child UUIDs; may be null or empty

MapNode

protected MapNode(UUID uuid,
                  Path.Segment name,
                  UUID parent,
                  Map<Name,Property> properties,
                  List<UUID> children,
                  int version)
Create a new node instance.

Parameters:
uuid - the UUID of the node; may not be null
name - the name of the node; may be null only if the parent is also null
parent - the UUID of the parent node; may be null only if the name is null
properties - the unmodifiable map of properties; may be null or empty
children - the unmodificable list of child UUIDs; may be null or empty
version - the version number

MapNode

public MapNode(UUID uuid,
               Path.Segment name,
               UUID parent,
               Iterable<Property> properties,
               List<UUID> children)
Create a new node instance.

Parameters:
uuid - the UUID of the node; may not be null
name - the name of the node; may be null only if the parent is also null
parent - the UUID of the parent node; may be null only if the name is null
properties - the properties that are to be copied into the new node; may be null or empty
children - the unmodificable list of child UUIDs; may be null or empty

MapNode

public MapNode(UUID uuid)
Create a root node with the supplied UUID.

Parameters:
uuid - the UUID of the root node; may not be null
Method Detail

getVersion

public int getVersion()
Get the version number of this node.

Returns:
the version number

getUuid

public UUID getUuid()
Returns the UUID for this node

Specified by:
getUuid in interface Node
Returns:
the UUID for this node
See Also:
Node.getUuid()

getName

public Path.Segment getName()
Returns the name of this node along with its SNS index within its parent's children

Specified by:
getName in interface Node
Returns:
the name of this node along with its SNS index within its parent's children, or null for the root node
See Also:
Node.getName()

getProperties

public Map<Name,Property> getProperties()
Returns properties of this node.

Specified by:
getProperties in interface Node
Returns:
an immutable map of properties keyed by their name.
See Also:
Node.getProperties()

getProperty

public Property getProperty(Name name)
Returns the property with the supplied name.

Specified by:
getProperty in interface Node
Parameters:
name - the name of the property
Returns:
the property, or null if this node has no such property
See Also:
Node.getProperty(org.modeshape.graph.property.Name)

getParent

public UUID getParent()
Returns:
parent

getChildren

public List<UUID> getChildren()
Returns:
children

hashCode

public int hashCode()

Overrides:
hashCode in class Object
See Also:
Object.hashCode()

equals

public boolean equals(Object obj)

Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

toString

public String toString()

Overrides:
toString in class Object
See Also:
Object.toString()

clone

public MapNode clone()

This method never clones the changes.

Overrides:
clone in class Object
See Also:
Object.clone()

hasChanges

protected boolean hasChanges()
Determine if this node has any unsaved changes.

Returns:
true if there are unsaved changes, or false otherwise

newChanges

protected MapNode.Changes newChanges()
Create the MapNode.Changes implementation. Subclasses that require a specialized class should overwrite this method. Note that this method does not modify any internal state; it should just instantiate and return the correct Changes class.

Returns:
the changes object.

freeze

public MapNode freeze()
Return the frozen node with all internal state reflective of any changes. If this node has no changes, this method simply returns this same node. Otherwise, this method creates a new node that has no changes and that mirrors this node's current state, and this new node will have an incremented version number.

Returns:
the unfrozen node; never null

withParent

public MapNode withParent(UUID parent)
Create a copy of this node except using the supplied parent.

Parameters:
parent - Sets parent to the specified value.
Returns:
the new map node; never null

withName

public MapNode withName(Path.Segment name)
Create a copy of this node except using the supplied name.

Parameters:
name - Sets name to the specified value.
Returns:
the new map node; never null

withChild

public MapNode withChild(UUID child)
Create a copy of this node except adding the supplied node at the end of the existing children.

Parameters:
child - the UUID of the child that is to be added; may not be null
Returns:
the new map node; never null

withChild

public MapNode withChild(int index,
                         UUID child)
Create a copy of this node except adding the supplied node into the existing children at the specified index.

Parameters:
index - the index at which the child is to appear
child - the UUID of the child that is to be added at the end of the existing children
Returns:
the new map node; never null

withoutChild

public MapNode withoutChild(UUID child)
Create a copy of this node except without the supplied child node.

Parameters:
child - the UUID of the child that is to be removed; may not be null
Returns:
the new map node; never null

withoutChildren

public MapNode withoutChildren()
Create a copy of this node except with none of the children.

Returns:
the new map node; never null

withProperties

public MapNode withProperties(Iterable<Property> propertiesToSet,
                              Iterable<Name> propertiesToRemove,
                              boolean removeAllExisting)
Create a copy of this node except with the changes to the properties.

Parameters:
propertiesToSet - the properties that are to be set; may be null if no properties are to be set
propertiesToRemove - the names of the properties that are to be removed; may be null if no properties are to be removed
removeAllExisting - true if all existing properties should be removed
Returns:
the unfrozen map node; never null

withProperty

public MapNode withProperty(Property property)
Create a copy of this node except with the new property.

Parameters:
property - the property to set
Returns:
this map node

withoutProperty

public MapNode withoutProperty(Name propertyName)
Create a copy of this node except with the new property.

Parameters:
propertyName - the name of the property that is to be removed
Returns:
this map node, or this node if the named properties does not exist on this node

withoutProperties

public MapNode withoutProperties()


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