org.gcube.data.trees.data
Class InnerNode

java.lang.Object
  extended by org.gcube.data.trees.data.Node
      extended by org.gcube.data.trees.data.InnerNode
Direct Known Subclasses:
Tree

public class InnerNode
extends Node

An inner Node, i.e. a node which is not a leaf.

Author:
Fabio Simeoni

Nested Class Summary
 
Nested classes/interfaces inherited from class org.gcube.data.trees.data.Node
Node.State
 
Constructor Summary
InnerNode(Edge... edges)
          Constructs an instance with a given edges.
InnerNode(InnerNode n)
          Copy constructor, creates an instance as a clone of a given InnerNode.
InnerNode(String id)
          Constructs an instance with a given identifier.
InnerNode(String id, Edge... edges)
          Constructs an instance with a given identifier and edges.
InnerNode(String id, Map<QName,String> attributes, Edge... edges)
          Constructs an instance with a given identifier, attributes, and edges.
InnerNode(String id, Node.State state, Map<QName,String> attributes, Edge... edges)
          Constructs an instance with a given identifier, state, attributes, and edges.
 
Method Summary
 boolean add(Edge... es)
          Adds one or more edges.
 boolean add(Edge e)
          Adds one edge.
 boolean add(List<Edge> es)
          Adds one or more edges.
<T extends Node>
T
child(Class<T> type, QName l)
          Returns a child of this node with a given label and of a given node type, if exactly one exists.
<T extends Node>
T
child(Class<T> type, String l)
          Returns a child of this node with a given label and of a given node type, if exactly one exists.
<T extends Node>
T
child(Class<T> type, String ns, String l)
          Returns a child of this node with a given label and of a given type, if exactly one exists.
 Node child(QName l)
          Returns a child of this node with a given label, if exactly one exists.
 Node child(String l)
          Returns a child of this node with a given label, if exactly one exists.
 Node child(String ns, String l)
          Returns a child of this node with a given label, if exactly one exists.
 List<Node> children()
          Returns all the children.
<T extends Node>
List<T>
children(Class<T> type)
          Returns all the children of a given node type.
<T extends Node>
List<T>
children(Class<T> type, QName l)
          Returns all the children with a given label and a given node type.
<T extends Node>
List<T>
children(Class<T> type, String l)
          Returns all the children with a given label and a given node type.
<T extends Node>
List<T>
children(Class<T> type, String ns, String l)
          Returns all the children with a given label and given node type.
 List<Node> children(QName l)
          Returns all the children with a given label.
 List<Node> children(String l)
          Returns all the children with a given label.
 List<Node> children(String ns, String l)
          Returns all the children with a given label.
protected static void clearState(Node n)
           
 void delete()
          Marks the node as Node.State.DELETED, removing all its attributes and all its edges.
 InnerNode delta(Node f)
          Returns a node that reflects the delta between this node and a given input node.
<T extends Node>
T
descendant(Class<T> type, String... descendantIDs)
          Returns the descendant of a given node type which can be reached from this node by following a given path of identifiers.
 Node descendant(String... ids)
          Returns the descendant that can be reached from this node by following a given path of node identifiers.
<T extends Node>
List<T>
descendants(Class<T> type, QName... labels)
          Returns all the descendants of a given node type which can be reached from this node by following a given path of labels.
<T extends Node>
List<T>
descendants(Class<T> type, String... labels)
          Returns all the descendants of a given node type that can be reached from this node by following a given sequence of labels.
 List<? extends Node> descendants(QName... labels)
          Returns all the descendants that can be reached from this node by following a given path of labels.
 List<? extends Node> descendants(String... labels)
          Returns all the descendants that can be reached from this node by following a given sequence of labels.
 Edge edge(QName l)
          Returns the edges with a given label, if exactly one exists.
 Edge edge(String l)
          Returns the edges with a given label, if exactly one exists.
 Edge edge(String ns, String l)
          Returns the edges with a given label, if exactly one exists.
 List<Edge> edges()
          Returns all the edges.
 List<Edge> edges(QName l)
          Returns the outgoing edges with a given label.
 List<Edge> edges(String l)
          Returns the outgoing edges with a given label.
 List<Edge> edges(String ns, String l)
          Returns the outgoing edges with a given label.
 boolean equals(Object obj)
          
 List<? extends Node> find(QName... labels)
          Returns all the descendants of this node that can be reached from this node or any other descendant by following a given path of labels.
 List<? extends Node> find(String... labels)
          Returns all the descendants of this node that can be reached from this node or any other descendant by following a given path of labels.
 boolean hasEdge(QName l)
          Indicates whether the node has at least an edge with a given label.
 boolean hasEdge(String l)
          Indicates whether the node has at least an edge with a given label.
 boolean hasEdge(String ns, String l)
          Indicates whether the node has at least an edge with a given label.
 int hashCode()
          
 List<QName> labels()
          Returns the labels of all the outgoing edges.
 List<QName> labels(QName l)
          Returns all the labels that match a given one.
protected static void markAsNew(Node n)
           
 boolean remove(Edge... es)
          Removes one or more edges.
 boolean remove(Edge e)
          Removes an edge.
 boolean remove(List<Edge> es)
          Removes one or more edges.
 List<Node> remove(String... childIDs)
          Removes one or more children.
 Node remove(String childID)
          Removes a child.
 long size()
          Returns the size of the tree rooted in this node, in bytes.
 String toString()
          
 void update(Node delta)
          Applies the changes captured by the delta node in input (cf.
 
Methods inherited from class org.gcube.data.trees.data.Node
ancestors, ancestorsAndSelf, attribute, attribute, attributes, hasAttribute, hasAttribute, id, parent, removeAttribute, removeAttribute, setAttribute, setAttribute, setParent, state, state, uri, uri
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InnerNode

public InnerNode(InnerNode n)
Copy constructor, creates an instance as a clone of a given InnerNode.

Parameters:
n - the node

InnerNode

public InnerNode(String id)
Constructs an instance with a given identifier.

Parameters:
id - the identifier

InnerNode

public InnerNode(String id,
                 Edge... edges)
Constructs an instance with a given identifier and edges.

Parameters:
id - the identifier
edges - the edges

InnerNode

public InnerNode(Edge... edges)
Constructs an instance with a given edges.

Parameters:
edges - the edges

InnerNode

public InnerNode(String id,
                 Map<QName,String> attributes,
                 Edge... edges)
Constructs an instance with a given identifier, attributes, and edges.

Parameters:
id - the identifier
attributes - the attributes
edges - the edges

InnerNode

public InnerNode(String id,
                 Node.State state,
                 Map<QName,String> attributes,
                 Edge... edges)
Constructs an instance with a given identifier, state, attributes, and edges.

Parameters:
id - the identifier
state - the state
attributes - the attributes
edges - the edges
Method Detail

children

public List<Node> children()
Returns all the children.

Returns:
the children

children

public <T extends Node> List<T> children(Class<T> type)
Returns all the children of a given node type.

Parameters:
type - the node type
Returns:
the children

children

public List<Node> children(QName l)
Returns all the children with a given label.

Parameters:
l - the label
Returns:
the children

children

public <T extends Node> List<T> children(Class<T> type,
                                         QName l)
Returns all the children with a given label and a given node type.

Parameters:
type - the node type
l - the label
Returns:
the children

children

public List<Node> children(String l)
                    throws IllegalArgumentException
Returns all the children with a given label.

Parameters:
l - the local name of the label
Returns:
the children
Throws:
IllegalArgumentException - if the label's local name is null

children

public <T extends Node> List<T> children(Class<T> type,
                                         String l)
                              throws IllegalArgumentException
Returns all the children with a given label and a given node type.

Parameters:
type - the node type
l - the local name of the label
Returns:
the children
Throws:
IllegalArgumentException - if the label's local name is null

children

public List<Node> children(String ns,
                           String l)
                    throws IllegalArgumentException
Returns all the children with a given label.

Parameters:
ns - the namespace of the label
l - the local name of the label
Returns:
the children
Throws:
IllegalArgumentException - if the label's local name is null

children

public <T extends Node> List<T> children(Class<T> type,
                                         String ns,
                                         String l)
Returns all the children with a given label and given node type.

Parameters:
type - the node type
ns - the namespace of the label
l - the local name of the label
Returns:
the children

descendant

public Node descendant(String... ids)
                throws IllegalStateException
Returns the descendant that can be reached from this node by following a given path of node identifiers.

Parameters:
ids - the identifiers that comprise the path
Returns:
the descendant
Throws:
IllegalStateException - if the sequence does not lead to a descendant.

descendant

public <T extends Node> T descendant(Class<T> type,
                                     String... descendantIDs)
                          throws IllegalStateException
Returns the descendant of a given node type which can be reached from this node by following a given path of identifiers.

Parameters:
type - the tree type
descendantIDs - the identifiers that comprise the path
Returns:
the descendant
Throws:
IllegalStateException - if the sequence does not lead to a descendant of the given type

descendants

public List<? extends Node> descendants(QName... labels)
Returns all the descendants that can be reached from this node by following a given path of labels.

Parameters:
labels - the labels that comprise the path
Returns:
the descendants

descendants

public <T extends Node> List<T> descendants(Class<T> type,
                                            QName... labels)
                                 throws IllegalArgumentException
Returns all the descendants of a given node type which can be reached from this node by following a given path of labels.

Parameters:
type - the node type
labels - the labels that comprise the path
Returns:
the descendants
Throws:
IllegalArgumentException - if no labels are specified

descendants

public List<? extends Node> descendants(String... labels)
Returns all the descendants that can be reached from this node by following a given sequence of labels.

Parameters:
labels - the local names of the labels
Returns:
the descendants
Throws:
IllegalArgumentException - if no labels are specified

descendants

public <T extends Node> List<T> descendants(Class<T> type,
                                            String... labels)
Returns all the descendants of a given node type that can be reached from this node by following a given sequence of labels.

Parameters:
type - the node type
labels - the local names of the labels
Returns:
the descendants

child

public Node child(QName l)
           throws IllegalStateException
Returns a child of this node with a given label, if exactly one exists.

Parameters:
l - the label
Returns:
the child
Throws:
IllegalStateException - if the node has zero or more than one children with the given label

child

public <T extends Node> T child(Class<T> type,
                                QName l)
                     throws IllegalStateException
Returns a child of this node with a given label and of a given node type, if exactly one exists.

Parameters:
type - the node type
l - the label
Returns:
the child
Throws:
IllegalStateException - if the node has zero or more than one children with the given label and of the given type

child

public Node child(String l)
           throws IllegalArgumentException,
                  IllegalStateException
Returns a child of this node with a given label, if exactly one exists.

Parameters:
l - the local name of the label
Returns:
the child
Throws:
IllegalArgumentException - if the label's local name is null
IllegalStateException - if the node has zero or more than one children with the given label

child

public <T extends Node> T child(Class<T> type,
                                String l)
                     throws IllegalArgumentException,
                            IllegalStateException
Returns a child of this node with a given label and of a given node type, if exactly one exists.

Parameters:
type - the node type
l - the local name of the label.
Returns:
the child
Throws:
IllegalArgumentException - if the label's local name is null
IllegalStateException - if the node has zero or more than one children with the given label and of the given type

child

public Node child(String ns,
                  String l)
           throws IllegalArgumentException,
                  IllegalStateException
Returns a child of this node with a given label, if exactly one exists.

Parameters:
ns - the namespace of the label
l - the local name of the label
Returns:
the child
Throws:
IllegalArgumentException - if the label's local name is null
IllegalStateException - if the node has zero or more than one children with the given label

child

public <T extends Node> T child(Class<T> type,
                                String ns,
                                String l)
                     throws IllegalArgumentException,
                            IllegalStateException
Returns a child of this node with a given label and of a given type, if exactly one exists.

Parameters:
type - the node type.
ns - the namespace of the label
l - the local name of the label
Returns:
the child
Throws:
IllegalArgumentException - if the label's local name is null
IllegalStateException - if the node has zero or more than one children with the given label and of the given type

edges

public List<Edge> edges()
Returns all the edges.

Returns:
the edges

edges

public List<Edge> edges(QName l)
Returns the outgoing edges with a given label.

Parameters:
l - the label
Returns:
the edges

edges

public List<Edge> edges(String ns,
                        String l)
                 throws IllegalArgumentException
Returns the outgoing edges with a given label.

Parameters:
ns - the namespace of the label
l - the local name of the label
Returns:
the edges
Throws:
IllegalArgumentException - if the label's local name is null

edges

public List<Edge> edges(String l)
                 throws IllegalArgumentException
Returns the outgoing edges with a given label.

Parameters:
l - the local name of the label
Returns:
the edges
Throws:
IllegalArgumentException - if the label's local name is null

hasEdge

public boolean hasEdge(QName l)
Indicates whether the node has at least an edge with a given label.

Parameters:
l - the label
Returns:
true if it does, false otherwise

hasEdge

public boolean hasEdge(String l)
                throws IllegalArgumentException
Indicates whether the node has at least an edge with a given label.

Parameters:
l - the local name of the label
Returns:
true if it does, false otherwise
Throws:
IllegalArgumentException - if the label's local name is null

hasEdge

public boolean hasEdge(String ns,
                       String l)
                throws IllegalArgumentException
Indicates whether the node has at least an edge with a given label.

Parameters:
ns - the namespace of the label
l - the local name of the label
Returns:
true if it does, false otherwise
Throws:
IllegalArgumentException - if the label's local name is null

edge

public Edge edge(QName l)
          throws IllegalStateException
Returns the edges with a given label, if exactly one exists.

Parameters:
l - the label
Returns:
the edge
Throws:
IllegalStateException - if there no edge or more than one edge with a give label

edge

public Edge edge(String l)
          throws IllegalStateException,
                 IllegalArgumentException
Returns the edges with a given label, if exactly one exists.

Parameters:
l - the local name of the label
Returns:
the edge
Throws:
IllegalStateException - if there no edge or more than one edge with a give label
IllegalArgumentException - if the label's local name is null

edge

public Edge edge(String ns,
                 String l)
          throws IllegalStateException,
                 IllegalArgumentException
Returns the edges with a given label, if exactly one exists.

Parameters:
ns - the namespace of the label
l - local name of the label
Returns:
the edge
Throws:
IllegalStateException - if there no edge or more than one edge with a give label
IllegalArgumentException - if the label's local name is null

labels

public List<QName> labels()
Returns the labels of all the outgoing edges.

Returns:
the labels

labels

public List<QName> labels(QName l)
Returns all the labels that match a given one.

Parameters:
l - the label to match
Returns:
the matching labels

remove

public boolean remove(List<Edge> es)
Removes one or more edges.

Parameters:
es - the edges
Returns:
true if any edge was actually removed, false otherwise

remove

public boolean remove(Edge e)
Removes an edge.

Parameters:
e - the edge
Returns:
true if the edge was actually removed, false otherwise

remove

public boolean remove(Edge... es)
Removes one or more edges.

Parameters:
es - the edges
Returns:
true if any edge was actually removed, false otherwise

remove

public Node remove(String childID)
            throws IllegalStateException
Removes a child.

Parameters:
childID - the child's identifier
Returns:
true if the child was actually removed, false otherwise
Throws:
IllegalStateException - if the child does not exist

remove

public List<Node> remove(String... childIDs)
Removes one or more children.

Parameters:
childIDs - the children's identifiers
Returns:
the children actually removed

find

public List<? extends Node> find(QName... labels)
Returns all the descendants of this node that can be reached from this node or any other descendant by following a given path of labels.

Parameters:
labels - the labels that comprise the path
Returns:
the descendants

find

public List<? extends Node> find(String... labels)
Returns all the descendants of this node that can be reached from this node or any other descendant by following a given path of labels.

Parameters:
labels - the labels that comprise the path
Returns:
the descendants

add

public boolean add(List<Edge> es)
Adds one or more edges.

Parameters:
es - the edges
Returns:
true if any edge was actually added, false otherwise

add

public boolean add(Edge e)
Adds one edge.

Parameters:
e - the edge
Returns:
true if the edge was actually added, false otherwise

add

public boolean add(Edge... es)
Adds one or more edges.

Parameters:
es - the edges
Returns:
true if any edge was actually added, false otherwise

delete

public void delete()
Marks the node as Node.State.DELETED, removing all its attributes and all its edges.

Overrides:
delete in class Node

update

public void update(Node delta)
            throws IllegalStateException,
                   IllegalArgumentException
Applies the changes captured by the delta node in input (cf. delta(Node)).

This operation acts as the inverse of delta(Node). In particular:

  • removes all the attributes of the delta node with a value of null;
  • adds all the attributes of the delta node with a non-null value whihc do no exist in this node;
  • modifies all the attributes of the delta node that differ in value from those in this node;
  • removes all the children of this node that are marked as Node.State.DELETEDin the delta node;
  • adds all the children of the delta node that are marked as Node.State.NEW (clearing the mark);
  • updates recursively the children of this node that occurs in the delta node with a state of Node.State.MODIFIED.

    Overrides:
    update in class Node
    Parameters:
    delta - the delta node
    Throws:
    IllegalStateException - if this node has no identifier
    IllegalArgumentException - if the delta node is not an inner node, or has has an unexpected state, or its identifier differs form this node's, or more generally its attributes and children do not relate to those of this node as expected

  • delta

    public InnerNode delta(Node f)
                    throws IllegalArgumentException,
                           IllegalStateException
    Returns a node that reflects the delta between this node and a given input node.

    The delta node is computed under the expectation that the the input node is (or simply looks like) a future version of this node, as if it was originally cloned from this node and had evolved since.

    Under this assumption, the delta node has:

    Overrides:
    delta in class Node
    Parameters:
    f - the input node
    Throws:
    IllegalArgumentException - in the following circumstances:
    • this node or one its descendants has no identifier;
    • the descendants of this node and the input node which have the same identifier have instead different types;
    • there are descendants of the input node that have no counterpart below this node but do have identifiers.
    IllegalStateException - if this node has no identifier.

    clearState

    protected static void clearState(Node n)
                              throws IllegalStateException
    Throws:
    IllegalStateException

    markAsNew

    protected static void markAsNew(Node n)
                             throws IllegalStateException
    Throws:
    IllegalStateException

    size

    public long size()
    Returns the size of the tree rooted in this node, in bytes.

    Specified by:
    size in class Node
    Returns:
    the size.

    toString

    public String toString()

    Overrides:
    toString in class Object

    equals

    public boolean equals(Object obj)

    Overrides:
    equals in class Node

    hashCode

    public int hashCode()

    Overrides:
    hashCode in class Node


    Copyright © 2012. All Rights Reserved.