TopicDiff { public TopicDiff merge(TopicDiff other) { String confict = this.conflict(other); if (confict != null) { throw new IllegalArgumentException("Conflict: " + confict); } Map<String, Difference> union = new HashMap<>(this.differences); union.putAll(other.differences); return new TopicDiff(union, other.objectMeta); } private  TopicDiff(Map<String, Difference> differences, ObjectMeta objectMeta); static TopicDiff diff(Topic source, Topic target); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); boolean isEmpty(); boolean changesNumPartitions(); int numPartitionsDelta(); boolean changesConfig(); boolean changesReplicationFactor(); Topic apply(Topic topic); String conflict(TopicDiff other); boolean conflicts(TopicDiff other); TopicDiff merge(TopicDiff other);  }
@Test public void testMerge() { TopicDiff diffAB = TopicDiff.diff(topicA, topicB); Topic topicD = new Topic.Builder(topicA.getTopicName(), topicA.getNumPartitions(), topicB.getConfig()).build(); TopicDiff diffAD = TopicDiff.diff(topicA, topicD); TopicDiff merged = diffAB.merge(diffAD); Topic end = merged.apply(topicA); assertThat(end, is(new Topic.Builder(topicA.getTopicName(), topicB.getNumPartitions(), topicB.getConfig()).build())); Map<String, String> configX = new HashMap<>(); configX.put("x", "24"); configX.put("b", "2"); configX.put("c", "tres"); Topic topicX = new Topic.Builder(topicA.getTopicName(), topicA.getNumPartitions(), configX).build(); TopicDiff diffAX = TopicDiff.diff(topicA, topicX); merged = diffAB.merge(diffAX); end = merged.apply(topicA); Map<String, String> configEnd = new HashMap<>(); configEnd.put("b", "two"); configEnd.put("c", "tres"); configEnd.put("d", "4"); configEnd.put("x", "24"); assertThat(end, is(new Topic.Builder(topicA.getTopicName(), topicB.getNumPartitions(), configEnd).build())); }