org.gcube.data.trees.data
Class Leaf

java.lang.Object
  extended by org.gcube.data.trees.data.Node
      extended by org.gcube.data.trees.data.Leaf

public class Leaf
extends Node

A leaf Node.

Author:
Fabio Simeoni

Nested Class Summary
 
Nested classes/interfaces inherited from class org.gcube.data.trees.data.Node
Node.State
 
Constructor Summary
Leaf(Leaf leaf)
          Copy constructor, creates an instance as a clone of a given Leaf.
Leaf(String id)
          Creates an instance with a given identifier.
Leaf(String v, Map<QName,String> attributes)
          Creates an instance with given attributes and a given value.
Leaf(String id, Node.State state, String v, Map<QName,String> attributes)
          Creates an instance with a given identifier, given attributes, and a given value.
Leaf(String id, String v)
          Creates an instance with a given identifier and a given value.
 
Method Summary
 void delete()
          Marks the node as Node.State.DELETED, removing all its attributes and replacing its value with null.
protected  Leaf delta(Node f)
          Returns a node that reflects the delta between this node and a given input node.
 boolean equals(Object obj)
          
 int hashCode()
          
 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.
 String value()
          Returns the inner value.
 void value(String v)
          Sets the inner value.
 
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

Leaf

public Leaf(Leaf leaf)
Copy constructor, creates an instance as a clone of a given Leaf.

Parameters:
leaf - the leaf.

Leaf

public Leaf(String id)
Creates an instance with a given identifier.

Parameters:
id - the identifier.

Leaf

public Leaf(String id,
            String v)
Creates an instance with a given identifier and a given value.

Parameters:
id - the identifier.
v - the value.

Leaf

public Leaf(String v,
            Map<QName,String> attributes)
Creates an instance with given attributes and a given value. * @param v the value.

Parameters:
attributes - the attributes.

Leaf

public Leaf(String id,
            Node.State state,
            String v,
            Map<QName,String> attributes)
Creates an instance with a given identifier, given attributes, and a given value.

Parameters:
id - the identifier.
v - the value.
attributes - the attributes.
Method Detail

value

public String value()
Returns the inner value.

Returns:
the value.

value

public void value(String v)
           throws IllegalArgumentException
Sets the inner value.

Parameters:
v - the value.
Throws:
IllegalArgumentException

delete

public void delete()
Marks the node as Node.State.DELETED, removing all its attributes and replacing its value with null.

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 which do no exist in this node;
  • modifies all the attributes of the delta node that differ in value from those in this node;
  • changes the value of this node to the value of the delta node.

    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 a leaf, or has an unexpected state, or its identifier differs form this node's, or more generally its attributes do not relate to those of this node as expected

  • delta

    protected Leaf delta(Node f)
                  throws IllegalArgumentException
    Returns a node that reflects the delta between this node and a given input node.

    The delta node can only be computed if the input node has the same identifier as this node. For all purposes, in fact, the input node is expected to be (or simply look 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 - if this node has no identifier or it has a different type or a different identifier than this node.

    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.