ReplaceOperatorTraversal extends Traversal { @Override public Node afterNode(Node original, Parameters p) throws Exception { Parameters instOperators = p.isMap("opRepls") ? p.getMap("opRepls") : operators; String key = original.getOperator(); if (instOperators.containsKey(key)) { if(instOperators.isString(key)) { original.setOperator(instOperators.getString(key)); return original; } else if(instOperators.isList(key)) { if (instOperators.isList(key, String.class)) { List<String> repls = (List<String>) instOperators.getList(key); Node root = null; Node curr = null; for (String r : repls) { if (root == null) { curr = new Node(r); root = curr; } else { curr.addChild(new Node(r)); curr = curr.getChild(0); } } for (Node c : original.getInternalNodes()) { curr.addChild(c); } return root; } } else { throw new IllegalArgumentException("--opReps mapping must contain only Strings or lists of Strings."); } } return original; } ReplaceOperatorTraversal(Retrieval ret);  ReplaceOperatorTraversal(Parameters p); @Override Node afterNode(Node original, Parameters p); @Override void beforeNode(Node object, Parameters queryParams);  }
@Test public void testOpRepls() throws Exception { Parameters repls = Arguments.parse(new String[]{ "--opRepls/dummy1=test1", "--opRepls/dummy2+test2", "--opRepls/dummy2+test3"}); ReplaceOperatorTraversal traversal = new ReplaceOperatorTraversal(Parameters.create()); Node t1 = traversal.afterNode(new Node("dummy1"), repls); Node t2 = traversal.afterNode(new Node("dummy2"), repls); System.err.println(t1.toString()); System.err.println(t2.toString()); assertEquals(t1.getOperator(), "test1"); assertEquals(t2.getOperator(), "test2"); assertEquals(t2.getChild(0).getOperator(), "test3"); }