@Test public void testSquash() { List<Tuple3<List<TestAdd>, List<TestSet>, List<TestSetName>>> ops = asList( ops(add(1), null, null), ops(null, set(0, 3), null), ops(null, null, setName("", "test1")), ops(null, null, null), ops(add(12), set(3, 12), setName("test1", "test2")), ops(add(-5), set(12, 123), setName("test2", "test3")) ); State state1 = new State(); state1.init(); ops.forEach(state1::apply); assertState("test3", 8, 123, state1); State state2 = new State(); state2.init(); List<Tuple3<List<TestAdd>, List<TestSet>, List<TestSetName>>> squashed = MERGED.squash(ops); assertEquals(singletonList(ops(add(8), set(0, 123), setName("", "test3"))), squashed); System.out.println(squashed); squashed.forEach(state2::apply); assertEquals(state1, state2); }
@Override public List<D> squash(List<? extends D> ops) { if (ops.isEmpty()) { return emptyList(); } List<D1> squashed1 = otSystem1.squash(collect(ops, getter1)); List<D2> squashed2 = otSystem2.squash(collect(ops, getter2)); return combineLists2(squashed1, squashed2, constructor); }
MergedOTSystem implements OTSystem<D> { @Override public List<D> squash(List<? extends D> ops) { if (ops.isEmpty()) { return emptyList(); } List<D1> squashed1 = otSystem1.squash(collect(ops, getter1)); List<D2> squashed2 = otSystem2.squash(collect(ops, getter2)); return combineLists2(squashed1, squashed2, constructor); } }
MergedOTSystem implements OTSystem<D> { @Override public List<D> squash(List<? extends D> ops) { if (ops.isEmpty()) { return emptyList(); } List<D1> squashed1 = otSystem1.squash(collect(ops, getter1)); List<D2> squashed2 = otSystem2.squash(collect(ops, getter2)); return combineLists2(squashed1, squashed2, constructor); } private  MergedOTSystem(TupleConstructor2<List<D1>, List<D2>, D> constructor,
			Function<D, List<D1>> getter1, OTSystem<D1> otSystem1,
			Function<D, List<D2>> getter2, OTSystem<D2> otSystem2); }
MergedOTSystem implements OTSystem<D> { @Override public List<D> squash(List<? extends D> ops) { if (ops.isEmpty()) { return emptyList(); } List<D1> squashed1 = otSystem1.squash(collect(ops, getter1)); List<D2> squashed2 = otSystem2.squash(collect(ops, getter2)); return combineLists2(squashed1, squashed2, constructor); } private  MergedOTSystem(TupleConstructor2<List<D1>, List<D2>, D> constructor,
			Function<D, List<D1>> getter1, OTSystem<D1> otSystem1,
			Function<D, List<D2>> getter2, OTSystem<D2> otSystem2); static OTSystem<D> mergeOtSystems(TupleConstructor2<List<D1>, List<D2>, D> constructor,
			Function<D, List<D1>> getter1, OTSystem<D1> otSystem1,
			Function<D, List<D2>> getter2, OTSystem<D2> otSystem2); static OTSystem<D> mergeOtSystems(TupleConstructor3<List<D1>, List<D2>, List<D3>, D> constructor,
			Function<D, List<D1>> getter1, OTSystem<D1> otSystem1,
			Function<D, List<D2>> getter2, OTSystem<D2> otSystem2,
			Function<D, List<D3>> getter3, OTSystem<D3> otSystem3); static OTSystem<D> mergeOtSystems(TupleConstructor4<List<D1>, List<D2>, List<D3>, List<D4>, D> constructor,
			Function<D, List<D1>> getter1, OTSystem<D1> otSystem1,
			Function<D, List<D2>> getter2, OTSystem<D2> otSystem2,
			Function<D, List<D3>> getter3, OTSystem<D3> otSystem3,
			Function<D, List<D4>> getter4, OTSystem<D4> otSystem4); static OTSystem<D> mergeOtSystems(TupleConstructor5<List<D1>, List<D2>, List<D3>, List<D4>, List<D5>, D> constructor,
			Function<D, List<D1>> getter1, OTSystem<D1> otSystem1,
			Function<D, List<D2>> getter2, OTSystem<D2> otSystem2,
			Function<D, List<D3>> getter3, OTSystem<D3> otSystem3,
			Function<D, List<D4>> getter4, OTSystem<D4> otSystem4,
			Function<D, List<D5>> getter5, OTSystem<D5> otSystem5); @Override TransformResult<D> transform(List<? extends D> leftDiffs, List<? extends D> rightDiffs); @Override List<D> squash(List<? extends D> ops); @Override boolean isEmpty(D op); @Override List<D> invert(List<O> ops); }
MergedOTSystem implements OTSystem<D> { @Override public List<D> squash(List<? extends D> ops) { if (ops.isEmpty()) { return emptyList(); } List<D1> squashed1 = otSystem1.squash(collect(ops, getter1)); List<D2> squashed2 = otSystem2.squash(collect(ops, getter2)); return combineLists2(squashed1, squashed2, constructor); } private  MergedOTSystem(TupleConstructor2<List<D1>, List<D2>, D> constructor,
			Function<D, List<D1>> getter1, OTSystem<D1> otSystem1,
			Function<D, List<D2>> getter2, OTSystem<D2> otSystem2); static OTSystem<D> mergeOtSystems(TupleConstructor2<List<D1>, List<D2>, D> constructor,
			Function<D, List<D1>> getter1, OTSystem<D1> otSystem1,
			Function<D, List<D2>> getter2, OTSystem<D2> otSystem2); static OTSystem<D> mergeOtSystems(TupleConstructor3<List<D1>, List<D2>, List<D3>, D> constructor,
			Function<D, List<D1>> getter1, OTSystem<D1> otSystem1,
			Function<D, List<D2>> getter2, OTSystem<D2> otSystem2,
			Function<D, List<D3>> getter3, OTSystem<D3> otSystem3); static OTSystem<D> mergeOtSystems(TupleConstructor4<List<D1>, List<D2>, List<D3>, List<D4>, D> constructor,
			Function<D, List<D1>> getter1, OTSystem<D1> otSystem1,
			Function<D, List<D2>> getter2, OTSystem<D2> otSystem2,
			Function<D, List<D3>> getter3, OTSystem<D3> otSystem3,
			Function<D, List<D4>> getter4, OTSystem<D4> otSystem4); static OTSystem<D> mergeOtSystems(TupleConstructor5<List<D1>, List<D2>, List<D3>, List<D4>, List<D5>, D> constructor,
			Function<D, List<D1>> getter1, OTSystem<D1> otSystem1,
			Function<D, List<D2>> getter2, OTSystem<D2> otSystem2,
			Function<D, List<D3>> getter3, OTSystem<D3> otSystem3,
			Function<D, List<D4>> getter4, OTSystem<D4> otSystem4,
			Function<D, List<D5>> getter5, OTSystem<D5> otSystem5); @Override TransformResult<D> transform(List<? extends D> leftDiffs, List<? extends D> rightDiffs); @Override List<D> squash(List<? extends D> ops); @Override boolean isEmpty(D op); @Override List<D> invert(List<O> ops);  }