CubeTwister 2.0alpha141 2011-10-13

ch.randelshofer.rubik.parser
Class Node

java.lang.Object
  extended by javax.swing.tree.DefaultMutableTreeNode
      extended by ch.randelshofer.rubik.parser.Node
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, javax.swing.tree.MutableTreeNode, javax.swing.tree.TreeNode
Direct Known Subclasses:
CommentNode, CommutationNode, ConjugationNode, GroupingNode, InversionNode, MacroNode, MoveNode, NOPNode, PermutationNode, ReflectionNode, RepetitionNode, SequenceNode, StatementNode

public abstract class Node
extends javax.swing.tree.DefaultMutableTreeNode

Abstract superclass for a Node in the parse tree generated by the Parser.

Version:
3.1 2009-01-22 Fixed reflect() method.
3.0 2007-11-15 Upgraded to Java 1.4.
2.1 2007-11-04 Implemented method transformOrientation.
2.0 2005-01-31 Reworked.
1.0 31 January 2005 Created.
Author:
Werner Randelshofer
See Also:
Serialized Form

Field Summary
protected  int endpos
          The end position of the last token in the source code, that is part of this script.
protected  int layerCount
           
protected  int startpos
          The start position of the first token in the source code, that is part of this script.
protected  Symbol symbol
          The Symbol that this node represents.
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Constructor Summary
Node(Symbol symbol, int layerCount, int startpos, int endpos)
          Creates a node which represents a symbol at the indicated position in the source code.
 
Method Summary
 void applyTo(Cube cube, boolean inverse)
          Applies the symbol represented by this node to the cube.
 Node cloneSubtree()
          Returns a deep clone of the subtree starting at this node.
 void dumpTree(int depth)
          Dumps the subtree starting at this Node node.
 java.util.Enumeration enumerateChildrenReversed()
          Enumerates the direct children of this node in reverse order.
 int getBlockTurnCount()
          Gets the block turn count of the subtree starting at this node.
 Node getChildAt(int index)
           
 int getEndPosition()
          Returns the end position of the symbol in the source code.
 int getFaceTurnCount()
          Gets the face turn count of the subtree starting at this node.
 int getLayerTurnCount()
          Gets the layer turn count of the subtree starting at this node.
 int getQuarterTurnCount()
          Gets the quarter turn count of the subtree starting at this node.
 int getStartPosition()
          Returns the start position of the symbol in the source code.
 Symbol getSymbol()
          Returns the ScriptParser symbol that represents this node.
 void inverse()
          Inverses the subtree starting at this node.
 void overwritePositions(int sp, int ep)
          Overwrite start and end positions of this node and the subtree starting at this node.
 void reflect()
          Reflects the subtree starting at this node.
 java.util.Enumeration resolvedEnumeration(boolean inverse)
          Enumerates a resolved version of the subtree starting at this node.
 void setEndPosition(int p)
          Sets the end position of the symbol in the source code.
 void setStartPosition(int p)
          Sets the start position of the symbol in the source code.
 java.util.List toResolvedList()
           
 java.lang.String toString()
          Returns a string representation of this node.
 java.lang.String toString(Notation notation)
          Returns a string representation of this node using the specified notation.
 java.lang.String toString(Notation notation, java.util.List<MacroNode> localMacros)
          Returns a string representation of this node using the specified notation and the specified local macros.
 void transform(int axis, int layerMask, int angle)
          Transformes the subtree starting at this node by the given move.
 void transform(MoveNode move, boolean inverse)
           
 void transformOrientation(int cubeOrientation, boolean inverse)
          Transformes the subtree starting at this node by the given cube orientation.
 void writeTokens(java.io.PrintWriter w, Notation n, java.util.Map<java.lang.String,MacroNode> macroMap)
          Writes the token(s) represented by the subtree starting at this node.
 
Methods inherited from class javax.swing.tree.DefaultMutableTreeNode
add, breadthFirstEnumeration, children, clone, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildBefore, getChildCount, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, insert, isLeaf, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, setUserObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

startpos

protected int startpos
The start position of the first token in the source code, that is part of this script.


endpos

protected int endpos
The end position of the last token in the source code, that is part of this script.


symbol

protected Symbol symbol
The Symbol that this node represents.


layerCount

protected int layerCount
Constructor Detail

Node

public Node(Symbol symbol,
            int layerCount,
            int startpos,
            int endpos)
Creates a node which represents a symbol at the indicated position in the source code.

Parameters:
startpos - The start position of the symbol.
endpos - The end position of the symbol.
Method Detail

getStartPosition

public int getStartPosition()
Returns the start position of the symbol in the source code.


setStartPosition

public void setStartPosition(int p)
Sets the start position of the symbol in the source code.


getEndPosition

public int getEndPosition()
Returns the end position of the symbol in the source code.


setEndPosition

public void setEndPosition(int p)
Sets the end position of the symbol in the source code.


overwritePositions

public void overwritePositions(int sp,
                               int ep)
Overwrite start and end positions of this node and the subtree starting at this node.


applyTo

public void applyTo(Cube cube,
                    boolean inverse)
Applies the symbol represented by this node to the cube.

Parameters:
cube - A cube to be transformed by this symbol.
inverse - If true, the transform will be done in inverse order.

getSymbol

public Symbol getSymbol()
Returns the ScriptParser symbol that represents this node.


dumpTree

public void dumpTree(int depth)
Dumps the subtree starting at this Node node. Use for debugging only.

Parameters:
depth - The number of spaces used for indenting.

toString

public java.lang.String toString()
Returns a string representation of this node. Use for debugging only.

Overrides:
toString in class javax.swing.tree.DefaultMutableTreeNode

toString

public final java.lang.String toString(Notation notation)
                                throws java.io.IOException
Returns a string representation of this node using the specified notation.

Throws:
java.io.IOException

toString

public final java.lang.String toString(Notation notation,
                                       java.util.List<MacroNode> localMacros)
                                throws java.io.IOException
Returns a string representation of this node using the specified notation and the specified local macros.

Throws:
java.io.IOException

transform

public void transform(int axis,
                      int layerMask,
                      int angle)
Transformes the subtree starting at this node by the given move. Does nothing if the transformation can not be done.


transform

public void transform(MoveNode move,
                      boolean inverse)

transformOrientation

public void transformOrientation(int cubeOrientation,
                                 boolean inverse)
Transformes the subtree starting at this node by the given cube orientation. Does nothing if the orientation can not be done.


inverse

public void inverse()
Inverses the subtree starting at this node.


reflect

public void reflect()
Reflects the subtree starting at this node.


resolvedEnumeration

public java.util.Enumeration resolvedEnumeration(boolean inverse)
Enumerates a resolved version of the subtree starting at this node. All elements of the enumeration except of MoveNode's and PermutationNode's may be safely ignored.

All nodes of the enumeration must be temporary, that is are explicitly created for this enumeration.

The enumeration must not be empty!

Parameters:
inverse - Set to true if you wish to get an inverted enumeration.

enumerateChildrenReversed

public java.util.Enumeration enumerateChildrenReversed()
Enumerates the direct children of this node in reverse order.


getLayerTurnCount

public int getLayerTurnCount()
Gets the layer turn count of the subtree starting at this node.


getBlockTurnCount

public int getBlockTurnCount()
Gets the block turn count of the subtree starting at this node.


getFaceTurnCount

public int getFaceTurnCount()
Gets the face turn count of the subtree starting at this node.


getQuarterTurnCount

public int getQuarterTurnCount()
Gets the quarter turn count of the subtree starting at this node.


writeTokens

public void writeTokens(java.io.PrintWriter w,
                        Notation n,
                        java.util.Map<java.lang.String,MacroNode> macroMap)
                 throws java.io.IOException
Writes the token(s) represented by the subtree starting at this node. The syntax and the string representations of the tokens are provided by the parser.

Parameters:
w - This is where the tokens are written to.
n - The notation which provides the tokens.
macroMap - Local macros which are preserved by the translation.
Throws:
java.io.IOException

cloneSubtree

public Node cloneSubtree()
Returns a deep clone of the subtree starting at this node.


toResolvedList

public java.util.List toResolvedList()

getChildAt

public Node getChildAt(int index)
Specified by:
getChildAt in interface javax.swing.tree.TreeNode
Overrides:
getChildAt in class javax.swing.tree.DefaultMutableTreeNode

(c) Werner Randelshofer.
All rights reserved.