* \r
*/\r
public class SilkAttribute {\r
- public static final String DEFAULT_TYPE = "default";\r
\r
- public String typeName = DEFAULT_TYPE;\r
+ public String typeName = null;\r
public String name;\r
public boolean isArray = false;\r
\r
//--------------------------------------\r
package org.xerial.silk.schema;\r
\r
+import java.util.ArrayList;\r
import java.util.List;\r
\r
/**\r
public String parent = null;\r
\r
public List<String> mixin;\r
- public List<SilkAttribute> attribute;\r
+ public List<SilkAttribute> attribute = new ArrayList<SilkAttribute>();\r
\r
- public List<SilkIndexTarget> index;\r
+ public List<SilkIndexTarget> index = new ArrayList<SilkIndexTarget>();\r
\r
}\r
//--------------------------------------\r
package org.xerial.silk.schema;\r
\r
+import java.util.ArrayList;\r
import java.util.List;\r
\r
/**\r
\r
public String name = ROOT_MODULE_NAME;\r
\r
- public List<SilkClass> classDef;\r
+ public List<SilkClass> classDef = new ArrayList<SilkClass>();\r
}\r
\r
import java.io.IOException;\r
import java.io.Reader;\r
+import java.io.StringWriter;\r
+import java.util.ArrayList;\r
import java.util.List;\r
+import java.util.Properties;\r
\r
import org.antlr.runtime.ANTLRReaderStream;\r
import org.antlr.runtime.CommonTokenStream;\r
import org.xerial.silk.schema.impl.SilkSchemaParser;\r
import org.xerial.util.StringUtil;\r
import org.xerial.util.antlr.ANTLRUtil;\r
+import org.xerial.util.graph.GraphvizHelper;\r
import org.xerial.util.log.Logger;\r
\r
public class SilkSchema {\r
private static Logger _logger = Logger.getLogger(SilkSchema.class);\r
\r
- public List<SilkModule> module;\r
- public List<SilkRelation> relation;\r
+ public List<SilkModule> module = new ArrayList<SilkModule>();\r
+ public List<SilkRelation> relation = new ArrayList<SilkRelation>();\r
\r
/**\r
* parse the input schema file and return the parse result in the form of\r
\r
}\r
\r
+ public String toGraphviz() {\r
+ StringWriter buf = new StringWriter();\r
+ GraphvizHelper g = new GraphvizHelper(buf);\r
+ g.beginDigraph("G");\r
+ g.graphOption("font=Arial");\r
+\r
+ int moduleCount = 1;\r
+ for (SilkModule eachModule : module) {\r
+ String moduleID = String.format("m%d", moduleCount++);\r
+ g.node(moduleID, eachModule.name);\r
+\r
+ for (SilkClass eachClass : eachModule.classDef) {\r
+ String classID = String.format("c_%s", eachClass.name);\r
+\r
+ g.node(classID, eachClass.name);\r
+ // parent\r
+ if (eachClass.parent != null) {\r
+ String parentID = String.format("c_%s", eachClass.parent);\r
+\r
+ Properties prop = new Properties();\r
+ prop.put("arrowhead", StringUtil.doubleQuote("none"));\r
+ prop.put("arrowtail", StringUtil.doubleQuote("empty"));\r
+ prop.put("colro", "gray");\r
+ g.edge(parentID, classID, prop);\r
+ }\r
+ else {\r
+ // module to class\r
+ g.edge(moduleID, classID);\r
+ }\r
+\r
+ // attributes\r
+ int attributeCount = 1;\r
+ for (SilkAttribute eachAttribute : eachClass.attribute) {\r
+ String attribID = String.format("%s_a%d", classID, attributeCount++);\r
+ {\r
+ String label = eachAttribute.name;\r
+ if (eachAttribute.typeName != null)\r
+ label += String.format(" [%s]", eachAttribute.typeName);\r
+\r
+ Properties prop = new Properties();\r
+ prop.put("label", StringUtil.doubleQuote(label));\r
+ prop.put("shape", "box");\r
+ g.node(attribID, prop);\r
+ }\r
+\r
+ if (eachAttribute.isArray) {\r
+ Properties edgeProp = new Properties();\r
+ edgeProp.put("color", "red");\r
+ g.edge(classID, attribID, edgeProp);\r
+ }\r
+ else\r
+ g.edge(classID, attribID);\r
+\r
+ }\r
+\r
+ }\r
+ }\r
+\r
+ g.endDigraph();\r
+\r
+ g.flush();\r
+\r
+ return buf.toString();\r
+ }\r
+\r
}\r
* @author leo
*
*/
-public class StringUtil
-{
+public class StringUtil {
public static final String SINGLE_QUOTE = "\'";
public static final String DOUBLE_QUOTE = "\"";
public static final String NEW_LINE = System.getProperty("line.separator");
- private StringUtil()
- {}
+ private StringUtil() {}
/**
* Concatenates all elements in the given collection c into a single string
* a concatenator: ex. ", ", "." etc.
* @return a concatenated string
*/
- public static <T> String join(Collection<T> c, String concatinator)
- {
+ public static <T> String join(Collection<T> c, String concatinator) {
if (c == null)
return "";
int size = c.size();
Iterator<T> it = c.iterator();
StringBuilder buf = new StringBuilder();
- for (int i = 0; it.hasNext() && i < size - 1; i++)
- {
+ for (int i = 0; it.hasNext() && i < size - 1; i++) {
Object data = it.next();
if (data != null)
buf.append(data.toString());
* a concatenator: ex. ", ", "." etc.
* @return the concatenated string
*/
- public static String join(Object[] c, String concatinator)
- {
+ public static String join(Object[] c, String concatinator) {
if (c == null)
return "";
int size = c.length;
return "";
StringBuilder buf = new StringBuilder();
- for (int i = 0; i < size - 1; i++)
- {
+ for (int i = 0; i < size - 1; i++) {
Object data = c[i];
buf.append(data != null ? data.toString() : "");
buf.append(concatinator);
* strings.
* @return the quoted message
*/
- public static String quote(String message, String quotationMark)
- {
+ public static String quote(String message, String quotationMark) {
if (message == null)
return message;
- return quotationMark + message + quotationMark;
+ return String.format("%s%s%s", quotationMark, message, quotationMark);
}
- public static String unquote(String message)
- {
+ public static String doubleQuote(String message) {
+ return quote(message, DOUBLE_QUOTE);
+ }
+
+ public static String unquote(String message) {
if (message == null)
return message;
- if (message.length() > 1)
- {
+ if (message.length() > 1) {
if ((message.charAt(0) == '"' && message.charAt(message.length() - 1) == '"')
|| (message.charAt(0) == '\'' && message.charAt(message.length() - 1) == '\''))
return message.substring(1, message.length() - 1);
static Pattern _whiteSpacePattern = Pattern.compile("[ \t\n\r]*");
- static public boolean isWhiteSpace(String s)
- {
+ static public boolean isWhiteSpace(String s) {
Matcher m = _whiteSpacePattern.matcher(s);
return m.matches();
}
- public static String concatinateWithTab(Object... data)
- {
+ public static String concatinateWithTab(Object... data) {
return StringUtil.join(data, "\t");
}
- public static String newline()
- {
+ public static String newline() {
return NEW_LINE;
}
}
* @param <State>\r
* @param <Symbol>\r
*/\r
-public class Automaton<State, Symbol>\r
-{\r
+public class Automaton<State, Symbol> {\r
private List<AutomatonListener<State, Symbol>> listenerList = new ArrayList<AutomatonListener<State, Symbol>>();\r
private IndexedSet<State> stateSet = new IndexedSet<State>();\r
private Set<State> terminalState = new HashSet<State>();\r
private HashMap<State, HashMap<Symbol, State>> transition = new HashMap<State, HashMap<Symbol, State>>();\r
private HashMap<State, State> transitionForOtherInput = new HashMap<State, State>();\r
\r
- private class CursorImpl implements AutomatonCursor<State, Symbol>\r
- {\r
+ private class CursorImpl implements AutomatonCursor<State, Symbol> {\r
State currentState;\r
\r
- public CursorImpl(State initialState)\r
- {\r
+ public CursorImpl(State initialState) {\r
currentState = initialState;\r
}\r
\r
- public boolean canAccept(Symbol input)\r
- {\r
+ public boolean canAccept(Symbol input) {\r
if (canAcceptAnySymbol())\r
return true;\r
\r
return getTransitionTableOf(currentState).containsKey(input);\r
}\r
\r
- public Set<Symbol> getAcceptableSymbolSet()\r
- {\r
+ public Set<Symbol> getAcceptableSymbolSet() {\r
return getAcceptableSymbolSetOf(currentState);\r
}\r
\r
- public boolean canAcceptAnySymbol()\r
- {\r
+ public boolean canAcceptAnySymbol() {\r
return transitionForOtherInput.containsKey(currentState);\r
}\r
\r
- public State getState()\r
- {\r
+ public State getState() {\r
return currentState;\r
}\r
\r
- public boolean isTerminal()\r
- {\r
+ public boolean isTerminal() {\r
return terminalState.contains(currentState);\r
}\r
\r
- public AutomatonCursor<State, Symbol> reset(State state)\r
- {\r
+ public AutomatonCursor<State, Symbol> reset(State state) {\r
if (!hasState(state))\r
- throw new XerialError(XerialErrorCode.INVALID_INPUT, "no such state found: " + state);\r
+ throw new XerialError(XerialErrorCode.INVALID_INPUT, "no such state found: "\r
+ + state);\r
currentState = state;\r
return this;\r
}\r
\r
- public State transit(Symbol input)\r
- {\r
+ public State transit(Symbol input) {\r
Map<Symbol, State> transitionTable = getTransitionTableOf(currentState);\r
State nextState = transitionTable.get(input);\r
if (nextState == null)\r
return otherTransit(input);\r
\r
// notify the transition to listeners\r
- for (AutomatonListener<State, Symbol> each : listenerList)\r
- {\r
+ for (AutomatonListener<State, Symbol> each : listenerList) {\r
each.onTansit(currentState, input, nextState);\r
}\r
\r
return currentState;\r
}\r
\r
- private State otherTransit(Symbol input)\r
- {\r
- if (transitionForOtherInput.containsKey(currentState))\r
- {\r
+ private State otherTransit(Symbol input) {\r
+ if (transitionForOtherInput.containsKey(currentState)) {\r
currentState = transitionForOtherInput.get(currentState);\r
return currentState;\r
}\r
- else\r
- {\r
- throw new XerialError(XerialErrorCode.INVALID_INPUT, "cannot accept the symbol:" + input);\r
+ else {\r
+ throw new XerialError(XerialErrorCode.INVALID_INPUT, "cannot accept the symbol:"\r
+ + input);\r
}\r
}\r
\r
}\r
\r
- private Map<Symbol, State> getTransitionTableOf(State state)\r
- {\r
+ private Map<Symbol, State> getTransitionTableOf(State state) {\r
HashMap<Symbol, State> result = transition.get(state);\r
- if (result == null)\r
- {\r
+ if (result == null) {\r
result = new HashMap<Symbol, State>();\r
transition.put(state, result);\r
}\r
return result;\r
}\r
\r
- public AutomatonCursor<State, Symbol> cursor(State initialState)\r
- {\r
+ public AutomatonCursor<State, Symbol> cursor(State initialState) {\r
return new CursorImpl(initialState);\r
}\r
\r
- public Set<State> getStateSet()\r
- {\r
+ public Set<State> getStateSet() {\r
return stateSet;\r
}\r
\r
- public Set<Symbol> getAcceptableSymbolSetOf(State state)\r
- {\r
+ public Set<Symbol> getAcceptableSymbolSetOf(State state) {\r
if (!hasState(state))\r
- throw new XerialError(XerialErrorCode.INVALID_INPUT, String.format("state %s not found", state));\r
+ throw new XerialError(XerialErrorCode.INVALID_INPUT, String.format(\r
+ "state %s not found", state));\r
\r
return getTransitionTableOf(state).keySet();\r
}\r
\r
- public Set<State> getAdjacentStates(State from)\r
- {\r
+ public Set<State> getAdjacentStates(State from) {\r
HashSet<State> result = new HashSet<State>();\r
if (transitionForOtherInput.containsKey(from))\r
result.add(transitionForOtherInput.get(from));\r
return result;\r
}\r
\r
- public void addState(State state)\r
- {\r
+ public void addState(State state) {\r
stateSet.add(state);\r
}\r
\r
- public void addTerminalState(State state)\r
- {\r
+ public void addTerminalState(State state) {\r
addState(state);\r
terminalState.add(state);\r
}\r
\r
- public void addTransition(State from, Symbol input, State to)\r
- {\r
+ public void addTransition(State from, Symbol input, State to) {\r
addState(from);\r
addState(to);\r
\r
getTransitionTableOf(from).put(input, to);\r
}\r
\r
- public void addStarTransition(State from, State to)\r
- {\r
+ public void addStarTransition(State from, State to) {\r
addState(from);\r
addState(to);\r
\r
transitionForOtherInput.put(from, to);\r
}\r
\r
- public void addListener(AutomatonListener<State, Symbol> listener)\r
- {\r
+ public void addListener(AutomatonListener<State, Symbol> listener) {\r
this.listenerList.add(listener);\r
}\r
\r
- public void remvoeListener(AutomatonListener<State, Symbol> listener)\r
- {\r
+ public void remvoeListener(AutomatonListener<State, Symbol> listener) {\r
this.listenerList.remove(listener);\r
}\r
\r
- public void clearListner()\r
- {\r
+ public void clearListner() {\r
this.listenerList.clear();\r
}\r
\r
- public boolean hasState(State state)\r
- {\r
+ public boolean hasState(State state) {\r
return stateSet.contains(state);\r
}\r
\r
- public String toString()\r
- {\r
+ public String toString() {\r
ArrayList<String> edgeData = new ArrayList<String>();\r
- for (State from : transition.keySet())\r
- {\r
+ for (State from : transition.keySet()) {\r
int fromID = stateSet.getID(from);\r
- for (Entry<Symbol, State> eachTransition : getTransitionTableOf(from).entrySet())\r
- {\r
- edgeData.add(String.format("%s -> %s [%s]", from, eachTransition.getValue(), eachTransition.getKey()));\r
+ for (Entry<Symbol, State> eachTransition : getTransitionTableOf(from).entrySet()) {\r
+ edgeData.add(String.format("%s -> %s [%s]", from, eachTransition.getValue(),\r
+ eachTransition.getKey()));\r
}\r
\r
- if (transitionForOtherInput.containsKey(from))\r
- {\r
- edgeData.add(String.format("%s -> %s [*]", from, transitionForOtherInput.get(from)));\r
+ if (transitionForOtherInput.containsKey(from)) {\r
+ edgeData\r
+ .add(String.format("%s -> %s [*]", from, transitionForOtherInput.get(from)));\r
}\r
}\r
\r
- return String\r
- .format("node:\n%s\nedge:\n%s", StringUtil.join(stateSet, ",\n"), StringUtil.join(edgeData, ",\n"));\r
+ return String.format("node:\n%s\nedge:\n%s", StringUtil.join(stateSet, ",\n"), StringUtil\r
+ .join(edgeData, ",\n"));\r
}\r
\r
- public String toGraphviz()\r
- {\r
+ public String toGraphviz() {\r
StringWriter writer = new StringWriter();\r
GraphvizHelper g = new GraphvizHelper(writer);\r
g.beginDigraph("G");\r
- for (State each : stateSet)\r
- {\r
+ for (State each : stateSet) {\r
g.node(stateSet.getID(each), each.toString());\r
}\r
\r
- for (State from : transition.keySet())\r
- {\r
+ for (State from : transition.keySet()) {\r
int fromID = stateSet.getID(from);\r
- for (Entry<Symbol, State> eachTransition : getTransitionTableOf(from).entrySet())\r
- {\r
- g.edge(fromID, stateSet.getID(eachTransition.getValue()), eachTransition.getKey().toString());\r
+ for (Entry<Symbol, State> eachTransition : getTransitionTableOf(from).entrySet()) {\r
+ g.edge(fromID, stateSet.getID(eachTransition.getValue()), eachTransition.getKey()\r
+ .toString());\r
}\r
\r
- if (transitionForOtherInput.containsKey(from))\r
- {\r
- g.edge(fromID, transitionForOtherInput.get(from), "*");\r
+ if (transitionForOtherInput.containsKey(from)) {\r
+ g.edge(Integer.toString(fromID), transitionForOtherInput.get(from).toString(), "*");\r
}\r
}\r
\r
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Properties;
import java.util.Stack;
+import java.util.Map.Entry;
+
+import org.xerial.util.StringUtil;
/**
* A helper class for generateing Graphviz's dot file
* @author leo
*
*/
-public class GraphvizHelper
-{
+public class GraphvizHelper {
private PrintWriter _out;
private Stack<GraphvizComponent> _componentStack = new Stack<GraphvizComponent>();
/**
*
*/
- public GraphvizHelper(OutputStream out)
- {
+ public GraphvizHelper(OutputStream out) {
_out = new PrintWriter(out);
}
- public GraphvizHelper(Writer out)
- {
+ public GraphvizHelper(Writer out) {
_out = new PrintWriter(out);
}
*
* @param graphName
*/
- public void beginDigraph(String graphName)
- {
+ public void beginDigraph(String graphName) {
pushComponent(new Digraph(graphName));
}
- public void endDigraph()
- {
+ public void endDigraph() {
assert !_componentStack.empty();
GraphvizComponent lastComponent = popComponent();
assert lastComponent instanceof Digraph;
flush();
}
- public void node(Object nodeName, Object label)
- {
- _out.println(String.format("%s [label=\"%s\"];", nodeName.toString(), label.toString()));
+ public void node(String nodeID, String label) {
+ _out.println(String.format("%s [label=\"%s\"];", nodeID, label.toString()));
+ }
+
+ public void node(int nodeID, String label) {
+ _out.println(String.format("%d [label=\"%s\"];", nodeID, label.toString()));
+ }
+
+ public void node(String nodeID, Properties options) {
+ _out.println(String.format("%s [%s]", nodeID, format(options)));
+ }
+
+ private String format(Properties options) {
+ ArrayList<String> buf = new ArrayList<String>(options.size());
+ for (Entry<Object, Object> each : options.entrySet()) {
+ buf.add(String.format("%s=%s", each.getKey(), each.getValue()));
+ }
+
+ return StringUtil.join(buf, ", ");
+ }
+
+ public void graphOption(String option) {
+ _out.println(String.format("graph [%s];", option));
+ }
+
+ public void edge(String fromNodeID, String toNodeID) {
+ _out.println(fromNodeID + " -> " + toNodeID + ";");
+ }
+
+ public void edge(String fromNodeID, String toNodeID, Properties prop) {
+ _out.println(String.format("%s -> %s [%s];", fromNodeID, toNodeID, format(prop)));
}
- public void option(String option)
- {
- _out.println(String.format("[];", option));
+ public void edge(int fromNodeID, int toNodeID) {
+ _out.println(fromNodeID + " -> " + toNodeID + ";");
}
- public void edge(Object nodeFrom, Object nodeTo)
- {
- _out.println(nodeFrom.toString() + " -> " + nodeTo.toString() + ";");
+ public void edge(String fromNodeID, String toNodeID, String label) {
+ _out.println(String.format("%s -> %s [label=\"%s\"];", fromNodeID, toNodeID, label));
}
- public void edge(Object nodeFrom, Object nodeTo, String label)
- {
- _out.println(String.format("%s -> %s [label=\"%s\"];", nodeFrom.toString(), nodeTo.toString(), label));
+ public void edge(int fromNodeID, int toNodeID, String label) {
+ _out.println(String.format("%d -> %d [label=\"%s\"];", fromNodeID, toNodeID, label));
}
- public void endOutput()
- {
- while (!_componentStack.empty())
- {
+ public void endOutput() {
+ while (!_componentStack.empty()) {
GraphvizComponent lastComponent = popComponent();
lastComponent.leave(_out);
}
_out.flush();
}
- public void flush()
- {
+ public void flush() {
_out.flush();
}
- private void pushComponent(GraphvizComponent component)
- {
+ private void pushComponent(GraphvizComponent component) {
_componentStack.add(component);
component.enter(_out);
}
- private GraphvizComponent popComponent()
- {
+ private GraphvizComponent popComponent() {
assert !_componentStack.empty();
return _componentStack.pop();
}
- class GraphvizComponent
- {
+ class GraphvizComponent {
/**
*
*/
- public void enter(PrintWriter out)
- {}
+ public void enter(PrintWriter out) {}
/**
*
*/
- public void leave(PrintWriter out)
- {}
+ public void leave(PrintWriter out) {}
}
- class Digraph extends GraphvizComponent
- {
+ class Digraph extends GraphvizComponent {
private String _graphName;
- public Digraph(String graphName)
- {
+ public Digraph(String graphName) {
_graphName = graphName;
}
@Override
- public void enter(PrintWriter out)
- {
+ public void enter(PrintWriter out) {
out.println("digraph " + _graphName + "{");
}
@Override
- public void leave(PrintWriter out)
- {
+ public void leave(PrintWriter out) {
out.println("}");
}
}\r
\r
// confirm relation\r
- assertNotNull(schema.relation);\r
- assertEquals(1, schema.relation.size());\r
- SilkRelation r = schema.relation.get(0);\r
- assertEquals("Alignment", r.name);\r
- assertEquals(2, r.attribute.size());\r
+ // assertNotNull(schema.relation);\r
+ // assertEquals(1, schema.relation.size());\r
+ // SilkRelation r = schema.relation.get(0);\r
+ // assertEquals("Alignment", r.name);\r
+ // assertEquals(2, r.attribute.size());\r
\r
_logger.info(Lens.toJSON(schema));\r
\r
+ _logger.info(schema.toGraphviz());\r
+\r
}\r
\r
}\r
# region on a genome sequence\r
class Locus\r
:id \r
- integer :start, :end \r
+ integer :start\r
+ integer :end \r
\r
index interval :start, :end\r
index keyword :id\r
# gene data with sequence data\r
class Gene < Locus\r
sequence :sequence \r
+\r
+ # A gene may have many exons and CDSs\r
Exon* :exon\r
CDS* :cds\r
end\r
class Reference < Locus\r
Coordinate :coodinate\r
sequence :sequence \r
+ \r
+ # Reference has many reads\r
+ Read* :read\r
end\r
\r
# short-read data\r
end \r
\r
\r
-# Alignment of reads to a reference genome\r
-relation Alignment\r
- Reference :reference\r
- Read* :read \r
-end\r
-\r
\r
end \r
//--------------------------------------
package org.xerial.util.graph;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.HashSet;
import org.xerial.util.StopWatch;
import org.xerial.util.log.Logger;
-public class LatticeTest
-{
+public class LatticeTest {
private static Logger _logger = Logger.getLogger(LatticeTest.class);
@Before
- public void setUp() throws Exception
- {}
+ public void setUp() throws Exception {}
@After
- public void tearDown() throws Exception
- {}
+ public void tearDown() throws Exception {}
@Test
- public void latticeNode()
- {
+ public void latticeNode() {
Lattice<String> lattice = new Lattice<String>();
LatticeNode<String> emptyNode = lattice.emptyNode();
LatticeNode<String> aNode = emptyNode.next("A");
assertTrue(aNode.contains("A"));
assertFalse(aNode.contains("B"));
assertFalse(aNode.contains("B")); // double check
-
+
HashSet<String> answer = new HashSet<String>();
answer.add("A");
for (String s : acdNode)
assertTrue(answer.contains(s));
-
LatticeNode<String> acdMinusDNode = acdNode.back("D");
assertEquals(acNode, acdMinusDNode);
assertNotSame(acNode, acdNode);
}
@Test
- public void latticePerformance()
- {
+ public void latticePerformance() {
Lattice<String> lattice = new Lattice<String>();
LatticeNode<String> emptyNode = lattice.emptyNode();
int N = 100000;
timer.reset();
- for (int i = 0; i < N; i++)
- {
- emptyNode.next("A").next("B").next("C").next("D").next("E").next("F").back("F").next("F").back("F").back(
- "E").back("D").back("C").back("B").back("A");
+ for (int i = 0; i < N; i++) {
+ emptyNode.next("A").next("B").next("C").next("D").next("E").next("F").back("F").next(
+ "F").back("F").back("E").back("D").back("C").back("B").back("A");
}
_logger.debug(timer.getElapsedTime());
- LatticeNode<String> emptyNode2 = emptyNode.next("A").next("B").next("C").next("D").back("D").back("C")
- .back("B").back("A");
+ LatticeNode<String> emptyNode2 = emptyNode.next("A").next("B").next("C").next("D")
+ .back("D").back("C").back("B").back("A");
assertEquals(emptyNode, emptyNode2);
emptyNode2 = emptyNode.next("A").next("B").back("B").back("A");
assertEquals(emptyNode, emptyNode2);
}
-
+
@Test
- public void latticeCursor()
- {
+ public void latticeCursor() {
Lattice<String> lattice = new Lattice<String>();
LatticeCursor<String> cursor = lattice.cursor();
assertTrue(!cursor.contains("A"));
assertTrue(cursor.contains("B"));
assertTrue(!cursor.contains("C"));
-
+
}
-
-
+
@Test
- public void loopBack()
- {
+ public void loopBack() {
Lattice<String> lattice = new Lattice<String>();
LatticeCursor<String> cursor = lattice.cursor();
cursor.next("A"); // {A}
cursor.next("B"); // {B, D}
_logger.debug(cursor.getNode());
}
-
@Test
- public void pathRepeat()
- {
+ public void pathRepeat() {
Lattice<String> lattice = new Lattice<String>();
LatticeCursor<String> cursor = lattice.cursor();
ArrayList<String> path = new ArrayList<String>();
StopWatch timer = new StopWatch();
int N = 1000;
timer.reset();
- for (int i = 0; i < N; i++)
- {
- for (String each : path)
- {
+ for (int i = 0; i < N; i++) {
+ for (String each : path) {
cursor.next(each);
}
- for (int p = path.size() - 1; p >= 0; --p)
- {
+ for (int p = path.size() - 1; p >= 0; --p) {
cursor.back(path.get(p));
}
}
_logger.debug(timer.getElapsedTime());
-
+
}
}