@Test public void testMatchByPluralPrefixNoPlural() { List<TextUnitDTO> existingTextUnitDTOs = Arrays.asList( createTextUnitDTO("name-0"), createTextUnitDTO("name-1")); Function<TextUnitForBatchMatcher, Optional<List<TextUnitDTO>>> matchByPluralPrefix = textUnitBatchMatcher.createMatchByPluralPrefixAndUsed(existingTextUnitDTOs); Optional<List<TextUnitDTO>> result = matchByPluralPrefix.apply(createPluralTextUnitForBatchMatcher("name-0")); assertFalse(result.isPresent()); }
Function<TextUnitForBatchMatcher, Optional<List<TextUnitDTO>>> createMatchByPluralPrefixAndUsed(List<TextUnitDTO> existingTextUnits) { logger.debug("Create the map to match by prefix and used text units"); Map<String, List<TextUnitDTO>> pluralPrefixToUsedTextUnitDTOsMap = existingTextUnits.stream() .filter(TextUnitDTO::isUsed) .filter(t -> t.getPluralForm() != null) .collect(groupingBy(o -> pluralNameParser.getPrefix(o.getPluralFormOther()))); Predicate<TextUnitDTO> byPluralPreifxNotAlreadyMatched = notAlreadyMatched("byPluralPrefixAndUsed"); logger.debug("createMatchByPluralPrefixAndUsed"); return (textUnitForBatchMatcher) -> { Optional<List<TextUnitDTO>> optionalTextUnitDTOS = Optional.empty(); if (textUnitForBatchMatcher.isNamePluralPrefix()) { List<TextUnitDTO> textUnitDTOS = Optional.ofNullable(pluralPrefixToUsedTextUnitDTOsMap.get(textUnitForBatchMatcher.getName())).orElseGet(ArrayList::new); List<TextUnitDTO> filtered = textUnitDTOS.stream() .filter(byPluralPreifxNotAlreadyMatched) .collect(Collectors.toList()); if (!filtered.isEmpty()) { optionalTextUnitDTOS = Optional.of(filtered); } } return optionalTextUnitDTOS; }; }
TextUnitBatchMatcher { Function<TextUnitForBatchMatcher, Optional<List<TextUnitDTO>>> createMatchByPluralPrefixAndUsed(List<TextUnitDTO> existingTextUnits) { logger.debug("Create the map to match by prefix and used text units"); Map<String, List<TextUnitDTO>> pluralPrefixToUsedTextUnitDTOsMap = existingTextUnits.stream() .filter(TextUnitDTO::isUsed) .filter(t -> t.getPluralForm() != null) .collect(groupingBy(o -> pluralNameParser.getPrefix(o.getPluralFormOther()))); Predicate<TextUnitDTO> byPluralPreifxNotAlreadyMatched = notAlreadyMatched("byPluralPrefixAndUsed"); logger.debug("createMatchByPluralPrefixAndUsed"); return (textUnitForBatchMatcher) -> { Optional<List<TextUnitDTO>> optionalTextUnitDTOS = Optional.empty(); if (textUnitForBatchMatcher.isNamePluralPrefix()) { List<TextUnitDTO> textUnitDTOS = Optional.ofNullable(pluralPrefixToUsedTextUnitDTOsMap.get(textUnitForBatchMatcher.getName())).orElseGet(ArrayList::new); List<TextUnitDTO> filtered = textUnitDTOS.stream() .filter(byPluralPreifxNotAlreadyMatched) .collect(Collectors.toList()); if (!filtered.isEmpty()) { optionalTextUnitDTOS = Optional.of(filtered); } } return optionalTextUnitDTOS; }; } }
TextUnitBatchMatcher { Function<TextUnitForBatchMatcher, Optional<List<TextUnitDTO>>> createMatchByPluralPrefixAndUsed(List<TextUnitDTO> existingTextUnits) { logger.debug("Create the map to match by prefix and used text units"); Map<String, List<TextUnitDTO>> pluralPrefixToUsedTextUnitDTOsMap = existingTextUnits.stream() .filter(TextUnitDTO::isUsed) .filter(t -> t.getPluralForm() != null) .collect(groupingBy(o -> pluralNameParser.getPrefix(o.getPluralFormOther()))); Predicate<TextUnitDTO> byPluralPreifxNotAlreadyMatched = notAlreadyMatched("byPluralPrefixAndUsed"); logger.debug("createMatchByPluralPrefixAndUsed"); return (textUnitForBatchMatcher) -> { Optional<List<TextUnitDTO>> optionalTextUnitDTOS = Optional.empty(); if (textUnitForBatchMatcher.isNamePluralPrefix()) { List<TextUnitDTO> textUnitDTOS = Optional.ofNullable(pluralPrefixToUsedTextUnitDTOsMap.get(textUnitForBatchMatcher.getName())).orElseGet(ArrayList::new); List<TextUnitDTO> filtered = textUnitDTOS.stream() .filter(byPluralPreifxNotAlreadyMatched) .collect(Collectors.toList()); if (!filtered.isEmpty()) { optionalTextUnitDTOS = Optional.of(filtered); } } return optionalTextUnitDTOS; }; }  }
TextUnitBatchMatcher { Function<TextUnitForBatchMatcher, Optional<List<TextUnitDTO>>> createMatchByPluralPrefixAndUsed(List<TextUnitDTO> existingTextUnits) { logger.debug("Create the map to match by prefix and used text units"); Map<String, List<TextUnitDTO>> pluralPrefixToUsedTextUnitDTOsMap = existingTextUnits.stream() .filter(TextUnitDTO::isUsed) .filter(t -> t.getPluralForm() != null) .collect(groupingBy(o -> pluralNameParser.getPrefix(o.getPluralFormOther()))); Predicate<TextUnitDTO> byPluralPreifxNotAlreadyMatched = notAlreadyMatched("byPluralPrefixAndUsed"); logger.debug("createMatchByPluralPrefixAndUsed"); return (textUnitForBatchMatcher) -> { Optional<List<TextUnitDTO>> optionalTextUnitDTOS = Optional.empty(); if (textUnitForBatchMatcher.isNamePluralPrefix()) { List<TextUnitDTO> textUnitDTOS = Optional.ofNullable(pluralPrefixToUsedTextUnitDTOsMap.get(textUnitForBatchMatcher.getName())).orElseGet(ArrayList::new); List<TextUnitDTO> filtered = textUnitDTOS.stream() .filter(byPluralPreifxNotAlreadyMatched) .collect(Collectors.toList()); if (!filtered.isEmpty()) { optionalTextUnitDTOS = Optional.of(filtered); } } return optionalTextUnitDTOS; }; }  Function<TextUnitForBatchMatcher, Optional<TextUnitDTO>> match(List<TextUnitDTO> existingTextUnits); Function<TextUnitForBatchMatcher, List<TextUnitDTO>> matchByNameAndPluralPrefix(List<TextUnitDTO> existingTextUnits); }
TextUnitBatchMatcher { Function<TextUnitForBatchMatcher, Optional<List<TextUnitDTO>>> createMatchByPluralPrefixAndUsed(List<TextUnitDTO> existingTextUnits) { logger.debug("Create the map to match by prefix and used text units"); Map<String, List<TextUnitDTO>> pluralPrefixToUsedTextUnitDTOsMap = existingTextUnits.stream() .filter(TextUnitDTO::isUsed) .filter(t -> t.getPluralForm() != null) .collect(groupingBy(o -> pluralNameParser.getPrefix(o.getPluralFormOther()))); Predicate<TextUnitDTO> byPluralPreifxNotAlreadyMatched = notAlreadyMatched("byPluralPrefixAndUsed"); logger.debug("createMatchByPluralPrefixAndUsed"); return (textUnitForBatchMatcher) -> { Optional<List<TextUnitDTO>> optionalTextUnitDTOS = Optional.empty(); if (textUnitForBatchMatcher.isNamePluralPrefix()) { List<TextUnitDTO> textUnitDTOS = Optional.ofNullable(pluralPrefixToUsedTextUnitDTOsMap.get(textUnitForBatchMatcher.getName())).orElseGet(ArrayList::new); List<TextUnitDTO> filtered = textUnitDTOS.stream() .filter(byPluralPreifxNotAlreadyMatched) .collect(Collectors.toList()); if (!filtered.isEmpty()) { optionalTextUnitDTOS = Optional.of(filtered); } } return optionalTextUnitDTOS; }; }  Function<TextUnitForBatchMatcher, Optional<TextUnitDTO>> match(List<TextUnitDTO> existingTextUnits); Function<TextUnitForBatchMatcher, List<TextUnitDTO>> matchByNameAndPluralPrefix(List<TextUnitDTO> existingTextUnits);  }