public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Node)) { return false; } Node r = (Node) o; return (type == r.type) && (value != null ? value.equals(r.value) : r.value == null) && (next != null ? next.equals(r.next) : r.next == null); }
public String toString() { StringBuilder buf = new StringBuilder(); switch (type) { case LITERAL: buf.append("LITERAL(" + value + ")"); break; default: buf.append(super.toString()); } buf.append(printNext()); return buf.toString(); } }
Node E() throws ScanException { Node t = T(); if (t == null) { return null; } Node eOpt = Eopt(); if (eOpt != null) { t.setNext(eOpt); } return t; }
Node T() throws ScanException { Token t = getCurentToken(); expectNotNull(t, "a LITERAL or '%'"); switch (t.getType()) { case Token.LITERAL: advanceTokenPointer(); return new Node(Node.LITERAL, t.getValue()); case Token.PERCENT: advanceTokenPointer(); // System.out.println("% token found"); FormatInfo fi; Token u = getCurentToken(); FormattingNode c; expectNotNull(u, "a FORMAT_MODIFIER, SIMPLE_KEYWORD or COMPOUND_KEYWORD"); if (u.getType() == Token.FORMAT_MODIFIER) { fi = FormatInfo.valueOf((String) u.getValue()); advanceTokenPointer(); c = C(); c.setFormatInfo(fi); } else { c = C(); } return c; default: return null; } }
switch (n.type) { case Node.LITERAL: addToList(new LiteralConverter<E>((String) n.getValue())); break; case Node.COMPOSITE_KEYWORD:
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (formatInfo != null ? formatInfo.hashCode() : 0); return result; } }
@Test public void keywordGluedToLitteral() throws Exception { Parser<Object> p = new Parser("%x{}a"); Node t = p.parse(); SimpleKeywordNode witness = new SimpleKeywordNode("x"); witness.setOptions(new ArrayList<String>()); witness.next = new Node(Node.LITERAL, "a"); assertEquals(witness, t); }
switch (n.type) { case Node.LITERAL: addToList(new LiteralConverter<E>((String) n.getValue())); break; case Node.COMPOSITE:
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (formatInfo != null ? formatInfo.hashCode() : 0); return result; } }
public boolean equals(Object o) { if(!super.equals(o)) { return false; } if (!(o instanceof CompositeNode)) { return false; } CompositeNode r = (CompositeNode) o; return (childNode != null) ? childNode.equals(r.childNode) : (r.childNode == null); }
@Test public void testCompositeFormatting() throws Exception { Parser<Object> p = new Parser("hello%5(XYZ)"); Node t = p.parse(); Node witness = new Node(Node.LITERAL, "hello"); CompositeNode composite = new CompositeNode(BARE); composite.setFormatInfo(new FormatInfo(5, Integer.MAX_VALUE)); Node child = new Node(Node.LITERAL, "XYZ"); composite.setChildNode(child); witness.next = composite; assertEquals(witness, t); }
switch (n.type) { case Node.LITERAL: addToList(new LiteralConverter<E>((String) n.getValue())); break; case Node.COMPOSITE_KEYWORD:
Node E() throws ScanException { Node t = T(); if (t == null) { return null; } Node eOpt = Eopt(); if (eOpt != null) { t.setNext(eOpt); } return t; }
public String toString() { StringBuffer buf = new StringBuffer(); switch (type) { case LITERAL: buf.append("LITERAL(" + value + ")"); break; default: buf.append(super.toString()); } buf.append(printNext()); return buf.toString(); } }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (formatInfo != null ? formatInfo.hashCode() : 0); return result; } }
public boolean equals(Object o) { if (!super.equals(o)) { return false; } if(!(o instanceof FormattingNode)) { return false; } FormattingNode r = (FormattingNode) o; return (formatInfo != null ? formatInfo.equals(r.formatInfo) : r.formatInfo == null); }
@Test public void testKeyword() throws Exception { { Parser<Object> p = new Parser("hello%xyz"); Node t = p.parse(); Node witness = new Node(Node.LITERAL, "hello"); witness.next = new SimpleKeywordNode("xyz"); assertEquals(witness, t); } { Parser<Object> p = new Parser("hello%xyz{x}"); Node t = p.parse(); Node witness = new Node(Node.LITERAL, "hello"); SimpleKeywordNode n = new SimpleKeywordNode("xyz"); List<String> optionList = new ArrayList<String>(); optionList.add("x"); n.setOptions(optionList); witness.next = n; assertEquals(witness, t); } }
switch (n.type) { case Node.LITERAL: addToList(new LiteralConverter<E>((String) n.getValue())); break; case Node.COMPOSITE_KEYWORD:
Node E() throws ScanException { Node t = T(); if (t == null) { return null; } Node eOpt = Eopt(); if (eOpt != null) { t.setNext(eOpt); } return t; }