edu.neu.ccs.demeter.dj
Class Traversal

java.lang.Object
  |
  +--edu.neu.ccs.demeter.aplib.Traversal
        |
        +--edu.neu.ccs.demeter.dj.Traversal
Direct Known Subclasses:
TraversalGraph

public class Traversal
extends Traversal

A compact, efficient representation of a set of paths through a class graph that can be used to traverse an object graph.


Nested Class Summary
 
Nested classes inherited from class edu.neu.ccs.demeter.aplib.Traversal
Traversal.EdgeSet, Traversal.NodeSet
 
Constructor Summary
Traversal(Strategy s, ClassGraph cg)
          Compute the traversal determined by s and cg.
Traversal(String s, ClassGraph cg)
          Compute the traversal determined by strategy s and cg.
 
Method Summary
 List asList(Object o)
          A fixed-size List backed by the object graph rooted at o.
 boolean equals(Object t)
           
 Object fetch(Object o)
          Fetch the object in the object graph rooted at o corresponding to the target(s) of the traversal.
 List gather(Object o)
          Gather into a list the objects in the object graph rooted at o corresponding to the target(s) of the traversal.
 Traversal.EdgeSet getEdgeSet(String key)
          The set of copies of the class graph edge with the given key in the traversal, or null if there are none.
 List getEdgeSets()
          An unmodifiable list of EdgeSet objects representing the edges in the traversal.
 List getFinishSet()
          An unmodifiable List of NodeSet objects representing the finish set of the traversal (Tf).
 Traversal.NodeSet getFinishSet(Object v)
          A NodeSet representing the finish set of tokens (indices) for the class graph node v, or null if v has no finish tokens in the traversal.
 Traversal.NodeSet getNodeSet(Object v)
          The set of copies of class graph node v in the traversal, or null if there are none.
 List getNodeSets()
          An unmodifiable list of NodeSet objects representing the nodes in the traversal.
 List getStartSet()
          An unmodifiable List of NodeSet objects representing the start set of the traversal (Ts).
 Traversal.NodeSet getStartSet(Object v)
          A NodeSet representing the start set of tokens (indices) for the class graph node v, or null if v has no start tokens in the traversal.
 Strategy getStrategy()
          The strategy expression used to compute the traversal.
static String getVersion()
          The DJ version string.
 int hashCode()
           
 ObjectGraphSlice slice(Object o)
          The slice of the object graph rooted at o determined by the traversal.
 ClassGraph toClassGraph()
          Make a class graph with just the classes and edges in the traversal.
 String toString()
           
 Object traverse(Object o, Visitor v)
          Traverse the object graph rooted at o according to the traversal, visiting v at each node and returning the value of v.getReturnValue() at the end of the traversal.
 Object traverse(Object o, Visitor[] v)
          Traverse the object graph rooted at o according to the traversal, visiting the visitors in array v in sequence at each node and returning the value of v[0].getReturnValue() at the end of the traversal.
 
Methods inherited from class edu.neu.ccs.demeter.aplib.Traversal
compute, compute, edgeKey, getAlternationEdgeSet, getClassGraph, getConstructionEdgeSet, getEdgeSet, getInheritanceEdgeSet, intersect, toCompactString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Traversal

public Traversal(Strategy s,
                 ClassGraph cg)
Compute the traversal determined by s and cg.

Throws:
TraversalException - if the resulting traversal is empty.

Traversal

public Traversal(String s,
                 ClassGraph cg)
Compute the traversal determined by strategy s and cg.

Throws:
TraversalException - if the resulting traversal is empty.
Method Detail

getVersion

public static String getVersion()
The DJ version string.


getStrategy

public Strategy getStrategy()
The strategy expression used to compute the traversal.


slice

public ObjectGraphSlice slice(Object o)
The slice of the object graph rooted at o determined by the traversal.


traverse

public Object traverse(Object o,
                       Visitor v)
Traverse the object graph rooted at o according to the traversal, visiting v at each node and returning the value of v.getReturnValue() at the end of the traversal.


traverse

public Object traverse(Object o,
                       Visitor[] v)
Traverse the object graph rooted at o according to the traversal, visiting the visitors in array v in sequence at each node and returning the value of v[0].getReturnValue() at the end of the traversal.


fetch

public Object fetch(Object o)
             throws FetchException
Fetch the object in the object graph rooted at o corresponding to the target(s) of the traversal.

FetchException

gather

public List gather(Object o)
Gather into a list the objects in the object graph rooted at o corresponding to the target(s) of the traversal.


asList

public List asList(Object o)
A fixed-size List backed by the object graph rooted at o. The elements of the list are the objects reachable by the strategy in the object graph with the given root whose class is a target of the strategy. Note that this list (like the List returned by Arrays.asList, but unlike the List returned by gather()) is write-through, i.e. modifying it will modify the underlying object graph, and vice versa.

Throws:
TraversalSourceException - if the type of o is not a source of the strategy.

toClassGraph

public ClassGraph toClassGraph()
Make a class graph with just the classes and edges in the traversal.


getNodeSets

public List getNodeSets()
Description copied from class: Traversal
An unmodifiable list of NodeSet objects representing the nodes in the traversal.

Specified by:
getNodeSets in class Traversal
See Also:
Traversal.NodeSet

getNodeSet

public Traversal.NodeSet getNodeSet(Object v)
Description copied from class: Traversal
The set of copies of class graph node v in the traversal, or null if there are none.

Specified by:
getNodeSet in class Traversal

getStartSet

public List getStartSet()
Description copied from class: Traversal
An unmodifiable List of NodeSet objects representing the start set of the traversal (Ts).

Specified by:
getStartSet in class Traversal

getStartSet

public Traversal.NodeSet getStartSet(Object v)
Description copied from class: Traversal
A NodeSet representing the start set of tokens (indices) for the class graph node v, or null if v has no start tokens in the traversal.

Specified by:
getStartSet in class Traversal

getFinishSet

public List getFinishSet()
Description copied from class: Traversal
An unmodifiable List of NodeSet objects representing the finish set of the traversal (Tf).

Specified by:
getFinishSet in class Traversal

getFinishSet

public Traversal.NodeSet getFinishSet(Object v)
Description copied from class: Traversal
A NodeSet representing the finish set of tokens (indices) for the class graph node v, or null if v has no finish tokens in the traversal.

Specified by:
getFinishSet in class Traversal

getEdgeSets

public List getEdgeSets()
Description copied from class: Traversal
An unmodifiable list of EdgeSet objects representing the edges in the traversal.

Specified by:
getEdgeSets in class Traversal
See Also:
Traversal.EdgeSet

getEdgeSet

public Traversal.EdgeSet getEdgeSet(String key)
Description copied from class: Traversal
The set of copies of the class graph edge with the given key in the traversal, or null if there are none.

Specified by:
getEdgeSet in class Traversal

toString

public String toString()
Overrides:
toString in class Object

equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object