TextUnitBatchMatcher { Predicate<TextUnitDTO> notAlreadyMatched(String context) { ConcurrentHashSet<Long> alreadyMappedTmTextUnitIds = new ConcurrentHashSet<>(); return (textUnitDTO) -> { boolean notAlreadyMatched = !alreadyMappedTmTextUnitIds.contains(textUnitDTO.getTmTextUnitId()); if (notAlreadyMatched) { logger.debug("Text unit: {} ({}) not matched yet in context: {}", textUnitDTO.getTmTextUnitId(), textUnitDTO.getName(), context); alreadyMappedTmTextUnitIds.add(textUnitDTO.getTmTextUnitId()); } else { logger.debug("Text unit: {}, ({}) is already matched in context: {}, can't used it", textUnitDTO.getTmTextUnitId(), textUnitDTO.getName(), context); } return notAlreadyMatched; }; }  Function<TextUnitForBatchMatcher, Optional<TextUnitDTO>> match(List<TextUnitDTO> existingTextUnits); Function<TextUnitForBatchMatcher, List<TextUnitDTO>> matchByNameAndPluralPrefix(List<TextUnitDTO> existingTextUnits);  }
@Test public void testNotAlreadyMatched() { Predicate<TextUnitDTO> notAlreadyMatched = textUnitBatchMatcher.notAlreadyMatched("test"); TextUnitDTO textUnitDTO = new TextUnitDTO(); textUnitDTO.setTmTextUnitId(1000L); assertTrue(notAlreadyMatched.test(textUnitDTO)); assertFalse(notAlreadyMatched.test(textUnitDTO)); }