CubeTwister 2.0alpha142 2012-02-11

ch.randelshofer.rubik.parser
Class CubeMarkupNotation

java.lang.Object
  extended by ch.randelshofer.rubik.parser.CubeMarkupNotation
All Implemented Interfaces:
Notation

public class CubeMarkupNotation
extends java.lang.Object
implements Notation

CubeMarkupNotation reads its notation definition from a CubeMarkup XML 3 file.

Version:
3.2.1 2010-10-06 Fixes possible NPE in method readNotationXMLElement.
3.2 2009-01-04 Disable permutation support if tokens are missing.
3.1 2009-01-03 Added "getName" method.
3.0.1 2008-08-25 Notation may support up to 32 layers instead of only 5.
3.0 2008-01-03 Migrated from JDK 1.1 to 1.4.
2.1 2007-09-10 Updated method isTokenFor.
1.0 05 February 2005 Created.
Author:
Werner Randelshofer

Constructor Summary
CubeMarkupNotation(Cube cube)
          Creates a new instance.
 
Method Summary
 void configureMoveFromToken(MoveNode twist, java.lang.String twistToken)
          Configures a MoveNode from the specified move token.
 void dumpNotation()
           
 java.lang.String getEquivalentMacro(Cube cube, java.util.Map localMacros)
          Returns a macro which performs the same transformation as the cube parameter.
 int getLayerCount()
          Returns the number of layers supported by this notation.
 java.util.List<MacroNode> getMacros()
          Returns the macros defined by this notation.
 java.lang.String getName()
           
 Symbol getSymbolFor(java.lang.String token, Symbol compositeSymbol)
          Returns a symbol for the specified token.
 Syntax getSyntax(Symbol s)
          Returns the syntax for the specified symbol.
 java.lang.String getToken(Move s)
          Returns a token for the specified move.
 java.lang.String getToken(Symbol s)
          Returns a token for the specified symbol.
 boolean isSupported(Symbol s)
          Returns true, if this notation supports the specified symbol.
 boolean isToken(java.lang.String token)
          Returns true, if the specified String is a token of this notation.
 boolean isTokenFor(java.lang.String token, Symbol symbol)
          Returns true, if the specified String is a token for the specified symbol.
 void readXML(nanoxml.XMLElement doc)
          Configures this CubeMarkupNotation by the default Notation found in the XMLElement.
 void readXML(nanoxml.XMLElement doc, java.lang.String notationName)
          Configures this CubeMarkupNotation by the first Notation element found in the XMLElement which has the specified notation name.
 java.lang.String toVerboseString()
           
 void writeToken(java.io.PrintStream w, Symbol symbol)
           
 void writeToken(java.io.PrintWriter w, int axis, int layerMask, int angle)
          Writes a token for the specified transformation to the print writer.
 void writeToken(java.io.PrintWriter w, Symbol symbol)
          Writes a token for the specified symbol to the print writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CubeMarkupNotation

public CubeMarkupNotation(Cube cube)
Creates a new instance.

Method Detail

readXML

public void readXML(nanoxml.XMLElement doc)
             throws nanoxml.XMLParseException
Configures this CubeMarkupNotation by the default Notation found in the XMLElement. The CubeMarkup 4 DTD must be used.

Throws:
nanoxml.XMLParseException

readXML

public void readXML(nanoxml.XMLElement doc,
                    java.lang.String notationName)
             throws nanoxml.XMLParseException
Configures this CubeMarkupNotation by the first Notation element found in the XMLElement which has the specified notation name. The CubeMarkup 4 DTD must be used.

Throws:
nanoxml.XMLParseException

toVerboseString

public java.lang.String toVerboseString()

configureMoveFromToken

public void configureMoveFromToken(MoveNode twist,
                                   java.lang.String twistToken)
Description copied from interface: Notation
Configures a MoveNode from the specified move token.

Specified by:
configureMoveFromToken in interface Notation

getName

public java.lang.String getName()

getEquivalentMacro

public java.lang.String getEquivalentMacro(Cube cube,
                                           java.util.Map localMacros)
Description copied from interface: Notation
Returns a macro which performs the same transformation as the cube parameter. Returns null if no macro is available.

Specified by:
getEquivalentMacro in interface Notation
Parameters:
cube - A transformed cube.
localMacros - A Map with local macros.

getSymbolFor

public Symbol getSymbolFor(java.lang.String token,
                           Symbol compositeSymbol)
Description copied from interface: Notation
Returns a symbol for the specified token. The compositeSymbol must be specified do disambiguate tokens. If the compositeSymbol is null, then the token must be unambiguous. Returns null, if the token is not a token for the specified compositeSymbol.

Specified by:
getSymbolFor in interface Notation

getSyntax

public Syntax getSyntax(Symbol s)
Description copied from interface: Notation
Returns the syntax for the specified symbol. Note: This makes only sense for composite symbols.

Specified by:
getSyntax in interface Notation

getToken

public java.lang.String getToken(Symbol s)
Description copied from interface: Notation
Returns a token for the specified symbol. If the symbol has more than one token, the first token is returned. Returns null, if symbol is not supported.

Specified by:
getToken in interface Notation

isSupported

public boolean isSupported(Symbol s)
Description copied from interface: Notation
Returns true, if this notation supports the specified symbol.

Specified by:
isSupported in interface Notation

isToken

public boolean isToken(java.lang.String token)
Description copied from interface: Notation
Returns true, if the specified String is a token of this notation.

Specified by:
isToken in interface Notation

isTokenFor

public boolean isTokenFor(java.lang.String token,
                          Symbol symbol)
Returns true, if the specified String is a token for the specified symbol.

Specified by:
isTokenFor in interface Notation

writeToken

public void writeToken(java.io.PrintWriter w,
                       Symbol symbol)
                throws java.io.IOException
Description copied from interface: Notation
Writes a token for the specified symbol to the print writer.

Specified by:
writeToken in interface Notation
Throws:
java.io.IOException - If the symbol is not supported by the notation, and if no alternative symbols could be found.

writeToken

public void writeToken(java.io.PrintStream w,
                       Symbol symbol)

writeToken

public void writeToken(java.io.PrintWriter w,
                       int axis,
                       int layerMask,
                       int angle)
                throws java.io.IOException
Description copied from interface: Notation
Writes a token for the specified transformation to the print writer.

Specified by:
writeToken in interface Notation
Throws:
java.io.IOException

dumpNotation

public void dumpNotation()

getLayerCount

public int getLayerCount()
Description copied from interface: Notation
Returns the number of layers supported by this notation.

Specified by:
getLayerCount in interface Notation

getToken

public java.lang.String getToken(Move s)
Description copied from interface: Notation
Returns a token for the specified move. If the move has more than one token, the first token is returned. Returns null, if move is not supported.

Specified by:
getToken in interface Notation

getMacros

public java.util.List<MacroNode> getMacros()
Description copied from interface: Notation
Returns the macros defined by this notation.

Specified by:
getMacros in interface Notation
Returns:
macros.

(c) Werner Randelshofer.
All rights reserved.