@Test void test4ary() { ColumnIdentifier c1 = new ColumnIdentifier("c", "1"); ColumnIdentifier c4 = new ColumnIdentifier("c", "4"); ColumnIdentifier c5 = new ColumnIdentifier("c", "5"); ColumnIdentifier c12 = new ColumnIdentifier("c", "12"); ColumnIdentifier d1 = new ColumnIdentifier("d", "1"); ColumnIdentifier d3 = new ColumnIdentifier("d", "3"); ColumnIdentifier d4 = new ColumnIdentifier("d", "4"); InclusionDependency ind = new InclusionDependency(new ColumnPermutation(c4, c12, c1, c5), new ColumnPermutation(d3, d1, d4, d1)); Set<InclusionDependency> expectedInds = ImmutableSet.of( new InclusionDependency(new ColumnPermutation(c4, c1, c5), new ColumnPermutation(d3, d4, d1)), new InclusionDependency(new ColumnPermutation(c4, c12, c1), new ColumnPermutation(d3, d1, d4))); 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);  }