@Test void testMultipleDuplications() { ColumnIdentifier a1 = new ColumnIdentifier("R", "A1"); ColumnIdentifier a2 = new ColumnIdentifier("R", "A2"); ColumnIdentifier b1 = new ColumnIdentifier("S", "B1"); ColumnIdentifier b2 = new ColumnIdentifier("S", "B2"); ColumnIdentifier b3 = new ColumnIdentifier("S", "B3"); ColumnIdentifier b4 = new ColumnIdentifier("S", "B4"); InclusionDependency ind = new InclusionDependency( new ColumnPermutation(a1, a1, a2, a2), new ColumnPermutation(b1, b2, b3, b4)); Set<InclusionDependency> expectedInds = ImmutableSet.of( new InclusionDependency(new ColumnPermutation(a1, a2), new ColumnPermutation(b1, b3)), new InclusionDependency(new ColumnPermutation(a1, a2), new ColumnPermutation(b1, b4)), new InclusionDependency(new ColumnPermutation(a1, a2), new ColumnPermutation(b2, b3)), new InclusionDependency(new ColumnPermutation(a1, a2), new ColumnPermutation(b2, b4))); Set<InclusionDependency> dedupedInds = IndDeduplicator.deduplicateColumnIdentifier(ind); assertThat(dedupedInds).isEqualTo(expectedInds); }
public static Set<InclusionDependency> deduplicateColumnIdentifier(InclusionDependency ind) { Set<InclusionDependency> dedupedInds = new HashSet<>(); Set<Integer> dependantIndices = getDuplicateIndices(ind.getDependant().getColumnIdentifiers()); Set<Integer> referencedIndices = getDuplicateIndices(ind.getReferenced().getColumnIdentifiers()); if (dependantIndices.isEmpty() && referencedIndices.isEmpty()) { dedupedInds.add(ind); } else { dedupedInds.addAll(deduplicateColumnIdentifier(ind, dependantIndices)); dedupedInds.addAll(deduplicateColumnIdentifier(ind, referencedIndices)); } if (dedupedInds.size() == 1) { return dedupedInds; } Set<InclusionDependency> nextDedupedInds = new HashSet<>(dedupedInds); do { dedupedInds = new HashSet<>(nextDedupedInds); nextDedupedInds = new HashSet<>(); for (InclusionDependency dedupedInd : dedupedInds) { nextDedupedInds.addAll(deduplicateColumnIdentifier(dedupedInd)); } } while (!nextDedupedInds.equals(dedupedInds)); return dedupedInds; }
IndDeduplicator { public static Set<InclusionDependency> deduplicateColumnIdentifier(InclusionDependency ind) { Set<InclusionDependency> dedupedInds = new HashSet<>(); Set<Integer> dependantIndices = getDuplicateIndices(ind.getDependant().getColumnIdentifiers()); Set<Integer> referencedIndices = getDuplicateIndices(ind.getReferenced().getColumnIdentifiers()); if (dependantIndices.isEmpty() && referencedIndices.isEmpty()) { dedupedInds.add(ind); } else { dedupedInds.addAll(deduplicateColumnIdentifier(ind, dependantIndices)); dedupedInds.addAll(deduplicateColumnIdentifier(ind, referencedIndices)); } if (dedupedInds.size() == 1) { return dedupedInds; } Set<InclusionDependency> nextDedupedInds = new HashSet<>(dedupedInds); do { dedupedInds = new HashSet<>(nextDedupedInds); nextDedupedInds = new HashSet<>(); for (InclusionDependency dedupedInd : dedupedInds) { nextDedupedInds.addAll(deduplicateColumnIdentifier(dedupedInd)); } } while (!nextDedupedInds.equals(dedupedInds)); return dedupedInds; } }
IndDeduplicator { public static Set<InclusionDependency> deduplicateColumnIdentifier(InclusionDependency ind) { Set<InclusionDependency> dedupedInds = new HashSet<>(); Set<Integer> dependantIndices = getDuplicateIndices(ind.getDependant().getColumnIdentifiers()); Set<Integer> referencedIndices = getDuplicateIndices(ind.getReferenced().getColumnIdentifiers()); if (dependantIndices.isEmpty() && referencedIndices.isEmpty()) { dedupedInds.add(ind); } else { dedupedInds.addAll(deduplicateColumnIdentifier(ind, dependantIndices)); dedupedInds.addAll(deduplicateColumnIdentifier(ind, referencedIndices)); } if (dedupedInds.size() == 1) { return dedupedInds; } Set<InclusionDependency> nextDedupedInds = new HashSet<>(dedupedInds); do { dedupedInds = new HashSet<>(nextDedupedInds); nextDedupedInds = new HashSet<>(); for (InclusionDependency dedupedInd : dedupedInds) { nextDedupedInds.addAll(deduplicateColumnIdentifier(dedupedInd)); } } while (!nextDedupedInds.equals(dedupedInds)); return dedupedInds; }  }
IndDeduplicator { public static Set<InclusionDependency> deduplicateColumnIdentifier(InclusionDependency ind) { Set<InclusionDependency> dedupedInds = new HashSet<>(); Set<Integer> dependantIndices = getDuplicateIndices(ind.getDependant().getColumnIdentifiers()); Set<Integer> referencedIndices = getDuplicateIndices(ind.getReferenced().getColumnIdentifiers()); if (dependantIndices.isEmpty() && referencedIndices.isEmpty()) { dedupedInds.add(ind); } else { dedupedInds.addAll(deduplicateColumnIdentifier(ind, dependantIndices)); dedupedInds.addAll(deduplicateColumnIdentifier(ind, referencedIndices)); } if (dedupedInds.size() == 1) { return dedupedInds; } Set<InclusionDependency> nextDedupedInds = new HashSet<>(dedupedInds); do { dedupedInds = new HashSet<>(nextDedupedInds); nextDedupedInds = new HashSet<>(); for (InclusionDependency dedupedInd : dedupedInds) { nextDedupedInds.addAll(deduplicateColumnIdentifier(dedupedInd)); } } while (!nextDedupedInds.equals(dedupedInds)); return dedupedInds; }  static Set<InclusionDependency> deduplicateColumnIdentifier(InclusionDependency ind); }
IndDeduplicator { public static Set<InclusionDependency> deduplicateColumnIdentifier(InclusionDependency ind) { Set<InclusionDependency> dedupedInds = new HashSet<>(); Set<Integer> dependantIndices = getDuplicateIndices(ind.getDependant().getColumnIdentifiers()); Set<Integer> referencedIndices = getDuplicateIndices(ind.getReferenced().getColumnIdentifiers()); if (dependantIndices.isEmpty() && referencedIndices.isEmpty()) { dedupedInds.add(ind); } else { dedupedInds.addAll(deduplicateColumnIdentifier(ind, dependantIndices)); dedupedInds.addAll(deduplicateColumnIdentifier(ind, referencedIndices)); } if (dedupedInds.size() == 1) { return dedupedInds; } Set<InclusionDependency> nextDedupedInds = new HashSet<>(dedupedInds); do { dedupedInds = new HashSet<>(nextDedupedInds); nextDedupedInds = new HashSet<>(); for (InclusionDependency dedupedInd : dedupedInds) { nextDedupedInds.addAll(deduplicateColumnIdentifier(dedupedInd)); } } while (!nextDedupedInds.equals(dedupedInds)); return dedupedInds; }  static Set<InclusionDependency> deduplicateColumnIdentifier(InclusionDependency ind);  }