com.sparsity.sparksee.algorithms
Class Context

java.lang.Object
  extended by com.sparsity.sparksee.algorithms.Context
All Implemented Interfaces:
java.io.Closeable

public class Context
extends java.lang.Object
implements java.io.Closeable

Context class.

It provides a very similar functionality than the Traversal classes. The main difference is Context returns a resulting collection whereas Traversal provides an iterator behaviour.

Check out the 'Algorithms' section in the SPARKSEE User Manual for more details on this.

Author:
Sparsity Technologies http://www.sparsity-technologies.com

Constructor Summary
Context(Session s, long node)
          Creates a new instance.
 
Method Summary
 void addAllEdgeTypes(EdgesDirection d)
          Allows for traversing all edge types of the graph.
 void addAllNodeTypes()
          Allows for traversing all node types of the graph.
 void addEdgeType(int t, EdgesDirection d)
          Allows for traversing edges of the given type.
 void addNodeType(int t)
          Allows for traversing nodes of the given type.
 void close()
          Closes the Context instance.
 Objects compute()
          Gets the resulting collection of nodes.
static Objects compute(Session s, long node, TypeList nodeTypes, TypeList edgeTypes, EdgesDirection dir, int maxhops, boolean include)
          Helper method to easily compute a context from a node.
 void excludeEdges(Objects edges)
          Set which edges can't be used.
 void excludeNodes(Objects nodes)
          Set which nodes can't be used.
 boolean isClosed()
          Gets if Context instance has been closed or not.
 void setMaximumHops(int maxhops, boolean include)
          Sets the maximum hops restriction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Context

public Context(Session s,
               long node)
Creates a new instance.

Parameters:
s - [in] Session to get the graph from and perform operation.
node - [in] Node to start traversal from.
Method Detail

addEdgeType

public void addEdgeType(int t,
                        EdgesDirection d)
Allows for traversing edges of the given type.

Parameters:
t - [in] Edge type.
d - [in] Edge direction.

excludeNodes

public void excludeNodes(Objects nodes)
Set which nodes can't be used.

This will replace any previously specified set of excluded nodes. Should only be used to exclude the usage of specific nodes from allowed node types because it's less efficient than not allowing a node type.

Parameters:
nodes - [in] A set of node identifiers that must be kept intact until the destruction of the class.

compute

public Objects compute()
Gets the resulting collection of nodes.

Returns:
The resulting collection of nodes.

addAllEdgeTypes

public void addAllEdgeTypes(EdgesDirection d)
Allows for traversing all edge types of the graph.

Parameters:
d - [in] Edge direction.

addNodeType

public void addNodeType(int t)
Allows for traversing nodes of the given type.

Parameters:
t - null

compute

public static Objects compute(Session s,
                              long node,
                              TypeList nodeTypes,
                              TypeList edgeTypes,
                              EdgesDirection dir,
                              int maxhops,
                              boolean include)
Helper method to easily compute a context from a node.

Parameters:
s - [in] Session to get the graph from and perform operation.
node - [in] Node to start traversal from.
nodeTypes - [in] Allowed node type list. NULL means all node types are allowed.
edgeTypes - [in] Allowed edge type list. NULL means all edge types are allowed.
dir - [in] Allowed direction for the allowed edge types.
maxhops - [in] The maximum hops restriction. It must be positive or zero. Zero, the default value, means unlimited.
include - [in] If TRUE, the resulting collection will include those nodes at distance less or equal than the given one, otherwise it will just include those nodes at distance equal than the given one. This parameter just makes sense if maxhops is different from 0; in that case it includes all nodes no matters the distance.

close

public void close()
Closes the Context instance.

It must be called to ensure the integrity of all data.

Specified by:
close in interface java.io.Closeable

addAllNodeTypes

public void addAllNodeTypes()
Allows for traversing all node types of the graph.


setMaximumHops

public void setMaximumHops(int maxhops,
                           boolean include)
Sets the maximum hops restriction.

All paths longer than the maximum hops restriction will be ignored.

Parameters:
maxhops - [in] The maximum hops restriction. It must be positive or zero. Zero, the default value, means unlimited.
include - [in] If TRUE, the resulting collection will include those nodes at distance less or equal than the given one, otherwise it will just include those nodes at distance equal than the given one. This parameter just makes sense if maxhops is different from 0; in that case it includes all nodes no matters the distance.

excludeEdges

public void excludeEdges(Objects edges)
Set which edges can't be used.

This will replace any previously specified set of excluded edges. Should only be used to exclude the usage of specific edges from allowed edge types because it's less efficient than not allowing an edge type.

Parameters:
edges - [in] A set of edge identifiers that must be kept intact until the destruction of the class.

isClosed

public boolean isClosed()
Gets if Context instance has been closed or not.

Returns:
TRUE if the Context instance has been closed, FALSE otherwise.
See Also:
close()