@Test public void findWithoutMatchingMetaData() { clientTagsCache.on(new ClientTagsUpdate("client1", "context1", Collections.singletonMap("location", "Europe"))); clientTagsCache.on(new ClientTagsUpdate("client2", "context1", Collections.singletonMap("location", "Asia"))); Set<ClientStreamIdentification> clientIdentifications = new HashSet<>(); clientIdentifications.add(new ClientStreamIdentification("context1", "client1")); clientIdentifications.add(new ClientStreamIdentification("context1", "client2")); Map<String, MetaDataValue> metaData = Collections.singletonMap("location", MetaDataValue.newBuilder().setTextValue("Africa") .build()); Set<ClientStreamIdentification> targets = testSubject.apply(metaData, clientIdentifications); assertEquals(2, targets.size()); }
@Override public Set<ClientStreamIdentification> apply(Map<String, MetaDataValue> metaDataMap, Set<ClientStreamIdentification> candidates) { if (candidates.size() < 2 || metaDataMap.isEmpty()) { return candidates; } Map<ClientStreamIdentification, Integer> scorePerClient = new HashMap<>(); candidates.forEach(candidate -> scorePerClient.computeIfAbsent(candidate, m -> score(metaDataMap, m))); return getHighestScore(scorePerClient); }
MetaDataBasedTargetSelector implements
        BiFunction<Map<String, MetaDataValue>, Set<ClientStreamIdentification>, Set<ClientStreamIdentification>> { @Override public Set<ClientStreamIdentification> apply(Map<String, MetaDataValue> metaDataMap, Set<ClientStreamIdentification> candidates) { if (candidates.size() < 2 || metaDataMap.isEmpty()) { return candidates; } Map<ClientStreamIdentification, Integer> scorePerClient = new HashMap<>(); candidates.forEach(candidate -> scorePerClient.computeIfAbsent(candidate, m -> score(metaDataMap, m))); return getHighestScore(scorePerClient); } }
MetaDataBasedTargetSelector implements
        BiFunction<Map<String, MetaDataValue>, Set<ClientStreamIdentification>, Set<ClientStreamIdentification>> { @Override public Set<ClientStreamIdentification> apply(Map<String, MetaDataValue> metaDataMap, Set<ClientStreamIdentification> candidates) { if (candidates.size() < 2 || metaDataMap.isEmpty()) { return candidates; } Map<ClientStreamIdentification, Integer> scorePerClient = new HashMap<>(); candidates.forEach(candidate -> scorePerClient.computeIfAbsent(candidate, m -> score(metaDataMap, m))); return getHighestScore(scorePerClient); } MetaDataBasedTargetSelector(ClientTagsCache clientTagsCache); }
MetaDataBasedTargetSelector implements
        BiFunction<Map<String, MetaDataValue>, Set<ClientStreamIdentification>, Set<ClientStreamIdentification>> { @Override public Set<ClientStreamIdentification> apply(Map<String, MetaDataValue> metaDataMap, Set<ClientStreamIdentification> candidates) { if (candidates.size() < 2 || metaDataMap.isEmpty()) { return candidates; } Map<ClientStreamIdentification, Integer> scorePerClient = new HashMap<>(); candidates.forEach(candidate -> scorePerClient.computeIfAbsent(candidate, m -> score(metaDataMap, m))); return getHighestScore(scorePerClient); } MetaDataBasedTargetSelector(ClientTagsCache clientTagsCache); @Override Set<ClientStreamIdentification> apply(Map<String, MetaDataValue> metaDataMap,
                                                 Set<ClientStreamIdentification> candidates); }
MetaDataBasedTargetSelector implements
        BiFunction<Map<String, MetaDataValue>, Set<ClientStreamIdentification>, Set<ClientStreamIdentification>> { @Override public Set<ClientStreamIdentification> apply(Map<String, MetaDataValue> metaDataMap, Set<ClientStreamIdentification> candidates) { if (candidates.size() < 2 || metaDataMap.isEmpty()) { return candidates; } Map<ClientStreamIdentification, Integer> scorePerClient = new HashMap<>(); candidates.forEach(candidate -> scorePerClient.computeIfAbsent(candidate, m -> score(metaDataMap, m))); return getHighestScore(scorePerClient); } MetaDataBasedTargetSelector(ClientTagsCache clientTagsCache); @Override Set<ClientStreamIdentification> apply(Map<String, MetaDataValue> metaDataMap,
                                                 Set<ClientStreamIdentification> candidates);  }