@Test public void testTransform() throws OTTransformException { List<Tuple3<List<TestAdd>, List<TestSet>, List<TestSetName>>> left = asList( new Tuple3<>(asList(add(12), add(13), add(-2)), emptyList(), emptyList()), new Tuple3<>(emptyList(), asList(set(0, 10), set(10, 14)), emptyList()), new Tuple3<>(emptyList(), emptyList(), asList(setName("", "left1"), setName("left1", "left2"))), new Tuple3<>(asList(add(100), add(23)), asList(set(14, 50), set(50, 3)), asList(setName("left2", "left3"), setName("left3", "left4"))) ); List<Tuple3<List<TestAdd>, List<TestSet>, List<TestSetName>>> right = asList( new Tuple3<>(emptyList(), asList(set(0, 3), set(3, 13)), emptyList()), new Tuple3<>(emptyList(), emptyList(), asList(setName("", "right1"), setName("right1", "right2"))), new Tuple3<>(asList(add(-4), add(43)), emptyList(), emptyList()), new Tuple3<>(asList(add(1000), add(-123)), asList(set(13, 11), set(11, 22)), asList(setName("right2", "right3"), setName("right3", "right4"))) ); State stateLeft = new State(); stateLeft.init(); State stateRight = new State(); stateRight.init(); left.forEach(stateLeft::apply); right.forEach(stateRight::apply); assertState("left4", 146, 3, stateLeft); assertState("right4", 916, 22, stateRight); TransformResult<Tuple3<List<TestAdd>, List<TestSet>, List<TestSetName>>> transform = MERGED.transform(left, right); System.out.println(transform.left); System.out.println(transform.right); transform.left.forEach(stateLeft::apply); transform.right.forEach(stateRight::apply); assertEquals(stateLeft, stateRight); }
@Override public TransformResult<D> transform(List<? extends D> leftDiffs, List<? extends D> rightDiffs) throws OTTransformException { List<D1> leftDiffs1 = collect(leftDiffs, getter1); List<D2> leftDiffs2 = collect(leftDiffs, getter2); List<D1> rightDiffs1 = collect(rightDiffs, getter1); List<D2> rightDiffs2 = collect(rightDiffs, getter2); TransformResult<D1> transform1 = otSystem1.transform(leftDiffs1, rightDiffs1); TransformResult<D2> transform2 = otSystem2.transform(leftDiffs2, rightDiffs2); List<D> left = combineLists2(transform1.left, transform2.left, constructor); List<D> right = combineLists2(transform1.right, transform2.right, constructor); return TransformResult.of(left, right); }
MergedOTSystem implements OTSystem<D> { @Override public TransformResult<D> transform(List<? extends D> leftDiffs, List<? extends D> rightDiffs) throws OTTransformException { List<D1> leftDiffs1 = collect(leftDiffs, getter1); List<D2> leftDiffs2 = collect(leftDiffs, getter2); List<D1> rightDiffs1 = collect(rightDiffs, getter1); List<D2> rightDiffs2 = collect(rightDiffs, getter2); TransformResult<D1> transform1 = otSystem1.transform(leftDiffs1, rightDiffs1); TransformResult<D2> transform2 = otSystem2.transform(leftDiffs2, rightDiffs2); List<D> left = combineLists2(transform1.left, transform2.left, constructor); List<D> right = combineLists2(transform1.right, transform2.right, constructor); return TransformResult.of(left, right); } }
MergedOTSystem implements OTSystem<D> { @Override public TransformResult<D> transform(List<? extends D> leftDiffs, List<? extends D> rightDiffs) throws OTTransformException { List<D1> leftDiffs1 = collect(leftDiffs, getter1); List<D2> leftDiffs2 = collect(leftDiffs, getter2); List<D1> rightDiffs1 = collect(rightDiffs, getter1); List<D2> rightDiffs2 = collect(rightDiffs, getter2); TransformResult<D1> transform1 = otSystem1.transform(leftDiffs1, rightDiffs1); TransformResult<D2> transform2 = otSystem2.transform(leftDiffs2, rightDiffs2); List<D> left = combineLists2(transform1.left, transform2.left, constructor); List<D> right = combineLists2(transform1.right, transform2.right, constructor); return TransformResult.of(left, right); } 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 TransformResult<D> transform(List<? extends D> leftDiffs, List<? extends D> rightDiffs) throws OTTransformException { List<D1> leftDiffs1 = collect(leftDiffs, getter1); List<D2> leftDiffs2 = collect(leftDiffs, getter2); List<D1> rightDiffs1 = collect(rightDiffs, getter1); List<D2> rightDiffs2 = collect(rightDiffs, getter2); TransformResult<D1> transform1 = otSystem1.transform(leftDiffs1, rightDiffs1); TransformResult<D2> transform2 = otSystem2.transform(leftDiffs2, rightDiffs2); List<D> left = combineLists2(transform1.left, transform2.left, constructor); List<D> right = combineLists2(transform1.right, transform2.right, constructor); return TransformResult.of(left, right); } 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 TransformResult<D> transform(List<? extends D> leftDiffs, List<? extends D> rightDiffs) throws OTTransformException { List<D1> leftDiffs1 = collect(leftDiffs, getter1); List<D2> leftDiffs2 = collect(leftDiffs, getter2); List<D1> rightDiffs1 = collect(rightDiffs, getter1); List<D2> rightDiffs2 = collect(rightDiffs, getter2); TransformResult<D1> transform1 = otSystem1.transform(leftDiffs1, rightDiffs1); TransformResult<D2> transform2 = otSystem2.transform(leftDiffs2, rightDiffs2); List<D> left = combineLists2(transform1.left, transform2.left, constructor); List<D> right = combineLists2(transform1.right, transform2.right, constructor); return TransformResult.of(left, right); } 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);  }