FlowTableEntry implements FlowTableInterface { public static FlowTableEntry fromString(final String s) { String val = s.toUpperCase(); FlowTableEntry res = new FlowTableEntry(); String[] strWindows = (val.substring( val.indexOf("(") + 1, val.indexOf(")"))).split("&&"); for (String w : strWindows) { res.addWindow(Window.fromString(w.trim())); } String[] strActions = (val.substring( val.indexOf("{") + 1, val.indexOf("}"))).trim().split(";"); for (String a : strActions) { res.addAction(ActionBuilder.build(a.trim())); } return res; } FlowTableEntry();  FlowTableEntry(final byte[] entry); static FlowTableEntry fromString(final String s); @Override String toString(); List<Window> getWindows(); void setWindows(final List<Window> w); boolean addWindow(final Window w); List<AbstractAction> getActions(); void setAction(final List<AbstractAction> a); boolean addAction(final AbstractAction a); Stats getStats(); void setStats(final Stats s); @Override byte[] toByteArray(); @Override int hashCode(); boolean equalWindows(final FlowTableEntry other); @Override boolean equals(final Object obj);  }
@Test public void testFromString() { String s = "IF (P.TYP == 10 && " + "P.50 == 1 && " + "R.10 > 1 && " + "R.12 < 5) {" + " ASK;" + " SET P.10 = 40 + 1;" + " FUNCTION 1 9 8 7 6 5 4 3 2 1 ;" + " DROP;" + " FORWARD_B;" + " FORWARD_U 3;" + " MATCH;" + " SET P.11 = P.12 + P.13; " + "}"; FlowTableEntry expResult = new FlowTableEntry(); expResult.addWindow(new Window() .setLhsLocation(PACKET) .setLhs(6) .setOperator(EQUAL) .setRhsLocation(CONST) .setRhs(10)); expResult.addWindow(new Window() .setLhsLocation(PACKET) .setLhs(50) .setOperator(EQUAL) .setRhsLocation(CONST) .setRhs(1)); expResult.addWindow(new Window() .setLhsLocation(STATUS) .setLhs(10) .setOperator(GREATER) .setRhsLocation(CONST) .setRhs(1)); expResult.addWindow(new Window() .setLhsLocation(STATUS) .setLhs(12) .setOperator(LESS) .setRhsLocation(CONST) .setRhs(5)); expResult.addAction(new AskAction()); expResult.addAction(new SetAction() .setLhsLocation(CONST) .setLhs(40) .setOperator(ADD) .setRhsLocation(CONST) .setRhs(1) .setResLocation(PACKET) .setRes(10)); expResult.addAction(new FunctionAction( new byte[]{5, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1,})); expResult.addAction(new DropAction()); expResult.addAction(new ForwardBroadcastAction()); expResult.addAction(new ForwardUnicastAction(new NodeAddress(3))); expResult.addAction(new MatchAction()); expResult.addAction(new SetAction() .setLhsLocation(PACKET) .setLhs(12) .setOperator(ADD) .setRhsLocation(PACKET) .setRhs(13) .setResLocation(PACKET) .setRes(11)); expResult.setStats(new Stats()); FlowTableEntry result = FlowTableEntry.fromString(s); assertEquals(expResult, result); }