org.nsdl.mptstore.query.component
Class MappableNodePattern<T extends Node>

java.lang.Object
  extended by org.nsdl.mptstore.query.component.MappableNodePattern<T>
Type Parameters:
T - The type of node that is described by the pattern. Typically, this is one of SubjectNode, PredicateNode, ObjectNode, or just Node if the exact node type is unimportant or unknown.
All Implemented Interfaces:
NodePattern<T>

public class MappableNodePattern<T extends Node>
extends java.lang.Object
implements NodePattern<T>

Represents node pattern that can be mapped to a database object.

Since a triple pattern may be mapped ap a specific table in the MPT model, a mappable pattern node, then, can retain a mapping to a specific column of a specific table. Such a node has the following properties

Author:
birkland

Nested Class Summary
static class MappableNodePattern.Types
          Types of MappableNodePattern.
 
Constructor Summary
MappableNodePattern(NodePattern<? extends T> nodePattern)
          Create a mappable node pattern from an existing node pattern.
MappableNodePattern(NodePattern<? extends T> nodePattern, java.lang.Class<T> patternType)
          Create a mappable node pattern from an existing node pattern.
MappableNodePattern(java.lang.String variable, java.lang.String type)
          Create a node pattern that is a variable.
MappableNodePattern(T node)
          Create a node pattern given a node value.
 
Method Summary
 void bindTo(MPTable t)
          Bind this node pattern to the given table.
 void bindTo(MPTable t, java.lang.String type)
          Bind this node pattern to the given table and optionally set the type.
 MPTable boundTable()
          Return the table to which this pattern is bound.
 boolean equals(java.lang.Object p)
          Equality of Triple Pattern.
 T getNode()
          Get the node value of this pattern, or null if this pattern does not represent a variable.
 java.lang.String getVarName()
          Get the variable name of this pattern, or null if this pattern does not represent a variable.
 int hashCode()
          Get a hash code for this mappable node pattern.
 boolean isVariable()
          Tell whether this node pattern is variable.
 java.lang.String mappedName()
          Return the table/alias and column identifier of the RDBMS location of this value or literal.
 java.lang.String toString()
          Get a string representation of this mappable node pattern.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MappableNodePattern

public MappableNodePattern(java.lang.String variable,
                           java.lang.String type)
Create a node pattern that is a variable.

Parameters:
variable - any string representing the variable's name (e.g. "$value", "?person").
type - the type of node this variable represents, which should be s, p, or o.

MappableNodePattern

public MappableNodePattern(T node)
Create a node pattern given a node value.

Parameters:
node - Node representing this pattern's value

MappableNodePattern

public MappableNodePattern(NodePattern<? extends T> nodePattern)
Create a mappable node pattern from an existing node pattern. If the given pattern is variable, the type of this mappable node pattern will be set to null.

Parameters:
nodePattern - the node pattern to base this one on.

MappableNodePattern

public MappableNodePattern(NodePattern<? extends T> nodePattern,
                           java.lang.Class<T> patternType)
Create a mappable node pattern from an existing node pattern. If the given pattern is variable, the type of this mappable node pattern will be set to null.

Parameters:
nodePattern - the node pattern to create the mappable pattern from.
patternType - constraint on the type of node allowed by this pattern.
Method Detail

isVariable

public boolean isVariable()
Tell whether this node pattern is variable.

Specified by:
isVariable in interface NodePattern<T extends Node>
Returns:
true if it is variable, false otherwise.

bindTo

public void bindTo(MPTable t)
Bind this node pattern to the given table.

Parameters:
t - the table.

bindTo

public void bindTo(MPTable t,
                   java.lang.String type)
Bind this node pattern to the given table and optionally set the type.

Parameters:
t - the table.
type - the new type for this node pattern. This should be s, p, o, or null if the type shouldn't be set.

mappedName

public java.lang.String mappedName()
Return the table/alias and column identifier of the RDBMS location of this value or literal.

Returns:
the mapped name.

boundTable

public MPTable boundTable()
Return the table to which this pattern is bound.

Returns:
the table this is bound to.

getNode

public T getNode()
Get the node value of this pattern, or null if this pattern does not represent a variable.

Specified by:
getNode in interface NodePattern<T extends Node>
Returns:
the node value

getVarName

public java.lang.String getVarName()
Get the variable name of this pattern, or null if this pattern does not represent a variable.

Specified by:
getVarName in interface NodePattern<T extends Node>
Returns:
the variable name

equals

public boolean equals(java.lang.Object p)
Equality of Triple Pattern.

Equality of triple patterns follow the following rules:

Overrides:
equals in class java.lang.Object
Parameters:
p - the object to compare this one to.
Returns:
whether the objects are equal according to the above rules.

toString

public java.lang.String toString()
Get a string representation of this mappable node pattern. If variable, this is the variable. Otherwise, it's the node's string representation.

Overrides:
toString in class java.lang.Object
Returns:
the string representation.

hashCode

public int hashCode()
Get a hash code for this mappable node pattern. If variable, the hash code is that of the variable string. Otherwise, it's the hash code of the node.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code.