FlowTableEntry implements FlowTableInterface { @Override public String toString() { StringBuilder out = new StringBuilder("if ("); windows.stream().map((Window w) -> { StringBuilder part = new StringBuilder(); part.append(w.toString()); return part; }).filter((part) -> (!part.toString().isEmpty())).forEach((part) -> { if (out.toString().equals("if (")) { out.append(part); } else { out.append(" && ").append(part); } }); if (!out.toString().isEmpty()) { out.append(") { "); actions.stream().forEach((a) -> { out.append(a.toString()).append("; "); }); out.append("} (") .append(getStats().toString()) .append(')'); } return out.toString().toUpperCase(); } 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 testToString() { FlowTableEntry instance = new FlowTableEntry(); instance.addWindow(new Window() .setLhsLocation(PACKET) .setLhs(6) .setOperator(EQUAL) .setRhsLocation(CONST) .setRhs(10)); instance.addWindow(new Window() .setLhsLocation(PACKET) .setLhs(50) .setOperator(EQUAL) .setRhsLocation(CONST) .setRhs(1)); instance.addWindow(new Window() .setLhsLocation(STATUS) .setLhs(10) .setOperator(GREATER) .setRhsLocation(CONST) .setRhs(1)); instance.addWindow(new Window() .setLhsLocation(STATUS) .setLhs(12) .setOperator(LESS) .setRhsLocation(CONST) .setRhs(5)); instance.addAction(new AskAction()); instance.addAction(new SetAction() .setLhsLocation(CONST) .setLhs(40) .setOperator(ADD) .setRhsLocation(CONST) .setRhs(1) .setResLocation(PACKET) .setRes(10)); instance.addAction(new FunctionAction( new byte[]{5, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1,})); instance.addAction(new DropAction()); instance.addAction(new ForwardBroadcastAction()); instance.addAction(new ForwardUnicastAction(new NodeAddress(3))); instance.addAction(new MatchAction()); instance.addAction(new SetAction() .setLhsLocation(PACKET) .setLhs(12) .setOperator(ADD) .setRhsLocation(PACKET) .setRhs(13) .setResLocation(PACKET) .setRes(11)); String expResult = "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; " + "} (TTL: 254, U: 0)"; String result = instance.toString(); assertEquals(expResult, result); }