@Test public void composeWithIdentity() { assertThat(compose(IDENTITY), sameInstance(IDENTITY)); assertThat(compose(IDENTITY, IDENTITY), sameInstance(IDENTITY)); assertThat( compose(IDENTITY, setSrcIp(Ip.parse("1.2.3.4"))), equalTo(setSrcIp(Ip.parse("1.2.3.4")))); assertThat( compose(setSrcIp(Ip.parse("1.2.3.4")), IDENTITY), equalTo(setSrcIp(Ip.parse("1.2.3.4")))); }
public static Transition compose(Transition... transitions) { if (Stream.of(transitions).anyMatch(t -> t == ZERO)) { return ZERO; } Stream<Transition> flatTransitions = Stream.of(transitions) .flatMap( t -> t instanceof Composite ? ((Composite) t).getTransitions().stream() : Stream.of(t)); List<Transition> nonIdentityTransitions = flatTransitions .filter(transition -> transition != IDENTITY) .collect(ImmutableList.toImmutableList()); if (nonIdentityTransitions.isEmpty()) { return IDENTITY; } List<Transition> mergedTransitions = mergeCompositeTransitions(nonIdentityTransitions); if (mergedTransitions.size() == 1) { return mergedTransitions.get(0); } return new Composite(mergedTransitions); }
Transitions { public static Transition compose(Transition... transitions) { if (Stream.of(transitions).anyMatch(t -> t == ZERO)) { return ZERO; } Stream<Transition> flatTransitions = Stream.of(transitions) .flatMap( t -> t instanceof Composite ? ((Composite) t).getTransitions().stream() : Stream.of(t)); List<Transition> nonIdentityTransitions = flatTransitions .filter(transition -> transition != IDENTITY) .collect(ImmutableList.toImmutableList()); if (nonIdentityTransitions.isEmpty()) { return IDENTITY; } List<Transition> mergedTransitions = mergeCompositeTransitions(nonIdentityTransitions); if (mergedTransitions.size() == 1) { return mergedTransitions.get(0); } return new Composite(mergedTransitions); } }
Transitions { public static Transition compose(Transition... transitions) { if (Stream.of(transitions).anyMatch(t -> t == ZERO)) { return ZERO; } Stream<Transition> flatTransitions = Stream.of(transitions) .flatMap( t -> t instanceof Composite ? ((Composite) t).getTransitions().stream() : Stream.of(t)); List<Transition> nonIdentityTransitions = flatTransitions .filter(transition -> transition != IDENTITY) .collect(ImmutableList.toImmutableList()); if (nonIdentityTransitions.isEmpty()) { return IDENTITY; } List<Transition> mergedTransitions = mergeCompositeTransitions(nonIdentityTransitions); if (mergedTransitions.size() == 1) { return mergedTransitions.get(0); } return new Composite(mergedTransitions); } private  Transitions(); }
Transitions { public static Transition compose(Transition... transitions) { if (Stream.of(transitions).anyMatch(t -> t == ZERO)) { return ZERO; } Stream<Transition> flatTransitions = Stream.of(transitions) .flatMap( t -> t instanceof Composite ? ((Composite) t).getTransitions().stream() : Stream.of(t)); List<Transition> nonIdentityTransitions = flatTransitions .filter(transition -> transition != IDENTITY) .collect(ImmutableList.toImmutableList()); if (nonIdentityTransitions.isEmpty()) { return IDENTITY; } List<Transition> mergedTransitions = mergeCompositeTransitions(nonIdentityTransitions); if (mergedTransitions.size() == 1) { return mergedTransitions.get(0); } return new Composite(mergedTransitions); } private  Transitions(); static Transition branch(BDD guard, Transition thn, Transition els); static Transition compose(Transition... transitions); static @Nullable Transition mergeComposed(Transition t1, Transition t2); static Transition constraint(BDD bdd); static Transition eraseAndSet(BDD var, BDD value); static Transition eraseAndSet(BDDInteger var, BDD value); @Deprecated static Transition or(); static Transition or(Transition... transitions); static Transition addLastHopConstraint(
      @Nullable LastHopOutgoingInterfaceManager mgr,
      String sendingNode,
      String sendingIface,
      String recvNode,
      String recvIface); static Transition addNoLastHopConstraint(
      @Nullable LastHopOutgoingInterfaceManager mgr, String recvNode, String recvIface); static Transition addOutgoingOriginalFlowFiltersConstraint(
      BDDOutgoingOriginalFlowFilterManager mgr); static Transition addOriginatingFromDeviceConstraint(BDDSourceManager mgr); static Transition addSourceInterfaceConstraint(BDDSourceManager mgr, String iface); static Transition removeNodeSpecificConstraints(
      String node,
      @Nullable LastHopOutgoingInterfaceManager lastHopMgr,
      BDDOutgoingOriginalFlowFilterManager originalFlowFilterMgr,
      BDDSourceManager sourceMgr); @VisibleForTesting static Transition removeOutgoingInterfaceConstraints(
      BDDOutgoingOriginalFlowFilterManager mgr); @VisibleForTesting static Transition removeSourceConstraint(BDDSourceManager mgr); static Transition reverse(Transition transition); }
Transitions { public static Transition compose(Transition... transitions) { if (Stream.of(transitions).anyMatch(t -> t == ZERO)) { return ZERO; } Stream<Transition> flatTransitions = Stream.of(transitions) .flatMap( t -> t instanceof Composite ? ((Composite) t).getTransitions().stream() : Stream.of(t)); List<Transition> nonIdentityTransitions = flatTransitions .filter(transition -> transition != IDENTITY) .collect(ImmutableList.toImmutableList()); if (nonIdentityTransitions.isEmpty()) { return IDENTITY; } List<Transition> mergedTransitions = mergeCompositeTransitions(nonIdentityTransitions); if (mergedTransitions.size() == 1) { return mergedTransitions.get(0); } return new Composite(mergedTransitions); } private  Transitions(); static Transition branch(BDD guard, Transition thn, Transition els); static Transition compose(Transition... transitions); static @Nullable Transition mergeComposed(Transition t1, Transition t2); static Transition constraint(BDD bdd); static Transition eraseAndSet(BDD var, BDD value); static Transition eraseAndSet(BDDInteger var, BDD value); @Deprecated static Transition or(); static Transition or(Transition... transitions); static Transition addLastHopConstraint(
      @Nullable LastHopOutgoingInterfaceManager mgr,
      String sendingNode,
      String sendingIface,
      String recvNode,
      String recvIface); static Transition addNoLastHopConstraint(
      @Nullable LastHopOutgoingInterfaceManager mgr, String recvNode, String recvIface); static Transition addOutgoingOriginalFlowFiltersConstraint(
      BDDOutgoingOriginalFlowFilterManager mgr); static Transition addOriginatingFromDeviceConstraint(BDDSourceManager mgr); static Transition addSourceInterfaceConstraint(BDDSourceManager mgr, String iface); static Transition removeNodeSpecificConstraints(
      String node,
      @Nullable LastHopOutgoingInterfaceManager lastHopMgr,
      BDDOutgoingOriginalFlowFilterManager originalFlowFilterMgr,
      BDDSourceManager sourceMgr); @VisibleForTesting static Transition removeOutgoingInterfaceConstraints(
      BDDOutgoingOriginalFlowFilterManager mgr); @VisibleForTesting static Transition removeSourceConstraint(BDDSourceManager mgr); static Transition reverse(Transition transition); static final Transition IDENTITY; static final Transition ZERO; }