RelatedGroupCriteriaScorer implements CriterionScorer { @Override public Map<EntityPair, Double> getScores(final Set<CouplingInstance> instances) { Map<EntityPair, Double> result = new HashMap<>(); for (CouplingInstance instance : instances) { if (premium != 0d) { for (int i = 0; i < instance.getAllNanoentities().size() - 1; i++) { for (int j = i + 1; j < instance.getAllNanoentities().size(); j++) { result.put(new EntityPair(instance.getAllNanoentities().get(i), instance.getAllNanoentities().get(j)), premium); } } } if (penalty != 0 && penaltyToAll) { setPenaltyToOtherFields(result, instance, allNanoentities); } if (penalty != 0 && penaltyToOtherGroups) { List<Nanoentity> allNanoentitiesInInstances = instances.stream().flatMap(i -> i.getAllNanoentities().stream()).collect(Collectors.toList()); setPenaltyToOtherFields(result, instance, allNanoentitiesInInstances); } } return result; } RelatedGroupCriteriaScorer(final double penalty, final double premium, final Iterable<Nanoentity> iterable, final boolean penaltyToOtherGroups,
			final boolean penaltyToAll);  RelatedGroupCriteriaScorer(final double premium);  RelatedGroupCriteriaScorer(final double penalty, final double premium);  RelatedGroupCriteriaScorer(final double penalty, final double premium, final Iterable<Nanoentity> allEntities); @Override Map<EntityPair, Double> getScores(final Set<CouplingInstance> instances);  }
@Test public void testRelatedGroups() { CouplingInstance group1 = new CouplingInstance(); CouplingInstance group2 = new CouplingInstance(); CouplingInstance group3 = new CouplingInstance(); Nanoentity nanoentity1a = createNanoEntity("1A"); Nanoentity nanoentity1b = createNanoEntity("1B"); group1.setNanoentities(Arrays.asList(nanoentity1a, nanoentity1b)); Nanoentity nanoentity2a = createNanoEntity("2A"); Nanoentity nanoentity2b = createNanoEntity("2B"); group2.setNanoentities(Arrays.asList(nanoentity2a, nanoentity2b)); Nanoentity nanoentity3a = createNanoEntity("3A"); Nanoentity nanoentity3b = createNanoEntity("3B"); group3.setNanoentities(Arrays.asList(nanoentity3a, nanoentity3b)); Nanoentity other = createNanoEntity("other"); RelatedGroupCriteriaScorer scorer = new RelatedGroupCriteriaScorer(PENALTY, PREMIUM, Arrays.asList(nanoentity1a, nanoentity1b, nanoentity2a, nanoentity2b, nanoentity3a, nanoentity3b, other)); Map<EntityPair, Double> scores = scorer.getScores(new HashSet<CouplingInstance>(Arrays.asList(group1, group2, group3))); assertThat(scores.get(new EntityPair(nanoentity1a, nanoentity1b)), is(equalTo(PREMIUM))); assertThat(scores.get(new EntityPair(nanoentity2a, nanoentity2b)), is(equalTo(PREMIUM))); assertThat(scores.get(new EntityPair(nanoentity3a, nanoentity3b)), is(equalTo(PREMIUM))); assertThat(scores.get(new EntityPair(nanoentity1a, nanoentity2b)), is(equalTo(PENALTY))); assertThat(scores.get(new EntityPair(nanoentity1a, nanoentity2a)), is(equalTo(PENALTY))); assertThat(scores.get(new EntityPair(nanoentity1a, nanoentity3b)), is(equalTo(PENALTY))); assertThat(scores.get(new EntityPair(nanoentity1a, nanoentity3a)), is(equalTo(PENALTY))); assertThat(scores.get(new EntityPair(nanoentity1b, nanoentity2a)), is(equalTo(PENALTY))); assertThat(scores.get(new EntityPair(nanoentity1b, nanoentity2b)), is(equalTo(PENALTY))); assertThat(scores.get(new EntityPair(nanoentity1b, nanoentity3a)), is(equalTo(PENALTY))); assertThat(scores.get(new EntityPair(nanoentity1b, nanoentity3b)), is(equalTo(PENALTY))); assertThat(scores.get(new EntityPair(nanoentity2a, nanoentity3a)), is(equalTo(PENALTY))); assertThat(scores.get(new EntityPair(nanoentity2a, nanoentity3b)), is(equalTo(PENALTY))); assertThat(scores.get(new EntityPair(nanoentity2b, nanoentity3a)), is(equalTo(PENALTY))); assertThat(scores.get(new EntityPair(nanoentity2b, nanoentity3b)), is(equalTo(PENALTY))); assertThat(scores.get(new EntityPair(nanoentity1a, other)), is(equalTo(PENALTY))); assertThat(scores.get(new EntityPair(nanoentity1b, other)), is(equalTo(PENALTY))); assertThat(scores.get(new EntityPair(nanoentity2a, other)), is(equalTo(PENALTY))); assertThat(scores.get(new EntityPair(nanoentity2b, other)), is(equalTo(PENALTY))); assertThat(scores.get(new EntityPair(nanoentity3a, other)), is(equalTo(PENALTY))); assertThat(scores.get(new EntityPair(nanoentity3b, other)), is(equalTo(PENALTY))); }