TextUnitBatchMatcher { public Function<TextUnitForBatchMatcher, List<TextUnitDTO>> matchByNameAndPluralPrefix(List<TextUnitDTO> existingTextUnits) { Function<TextUnitForBatchMatcher, Optional<List<TextUnitDTO>>> matchByPluralPrefixAndUsed = createMatchByPluralPrefixAndUsed(existingTextUnits); Function<TextUnitForBatchMatcher, Optional<List<TextUnitDTO>>> matchByNameAndUsed = createMatchByNameAndUsed(existingTextUnits).andThen(Optionals::optionalToOptionalList); Function<TextUnitForBatchMatcher, Optional<List<TextUnitDTO>>> matchByPluralPrefixAndUnused = createMatchByPluralPrefixAndUnused(existingTextUnits); Function<TextUnitForBatchMatcher, Optional<List<TextUnitDTO>>> matchByNameAndUnused = createMatchByNameAndUnused(existingTextUnits).andThen(Optionals::optionalToOptionalList); Predicate<List<TextUnitDTO>> notAlreadyMatchedInList = notAlreadyMatchedInList("global"); return textUnitForBatchMatcher -> { return Optionals.or(textUnitForBatchMatcher, matchByPluralPrefixAndUsed, matchByNameAndUsed, matchByNameAndUnused). filter(notAlreadyMatchedInList).orElse(Collections.emptyList()); }; }  Function<TextUnitForBatchMatcher, Optional<TextUnitDTO>> match(List<TextUnitDTO> existingTextUnits); Function<TextUnitForBatchMatcher, List<TextUnitDTO>> matchByNameAndPluralPrefix(List<TextUnitDTO> existingTextUnits);  }
@Test public void testMatchByNameAndPluralPrefix() { Function<TextUnitForBatchMatcher, List<TextUnitDTO>> textUnitForBatchMatcherListFunction = textUnitBatchMatcher.matchByNameAndPluralPrefix(Collections.emptyList()); textUnitForBatchMatcherListFunction.apply(createTextUnitForBatchMatcher("test")); }