package io.github.factoryfx.factory.validation;

import java.util.HashSet;
import java.util.List;
import java.util.function.Function;

import io.github.factoryfx.factory.util.LanguageText;

public class UniqueListBy<T, V> implements Validation<List<T>> {

    private final Function<T, V> mapper;

    public UniqueListBy(Function<T,V> mapper){
        this.mapper = mapper;
    }

    @Override
    public ValidationResult validate(List<T> list) {
        boolean error=false;
        HashSet<V> set = new HashSet<>();
        for (T item : list) {
            if (!set.add(mapper.apply(item))) {
                error = true;
            }
        }
        return new ValidationResult(error,new LanguageText().en("List contains duplicate entries").de("Liste enthält doppelte Einträge"));
    }
}

@@ -289,16 +289,61 @@
  mapper;
+%0A    private final LanguageText errorMessage;
 %0A%0A    pu
@@ -371,16 +371,17 @@
 ction%3CT,
+ 
 V%3E mappe
@@ -386,38 +386,282 @@
 per)
-%7B%0A        this.mapper = mapper
+ %7B%0A        this(mapper, new LanguageText().en(%22List contains duplicate entries%22).de(%22Liste enth%C3%A4lt doppelte Eintr%C3%A4ge%22));%0A    %7D%0A%0A    public UniqueListBy(Function%3CT, V%3E mapper, LanguageText errorMessage) %7B%0A        this.mapper = mapper;%0A        this.errorMessage = errorMessage
 ;%0A  
@@ -661,24 +661,25 @@
 age;%0A    %7D%0A%0A
+%0A
     @Overrid
@@ -754,17 +754,19 @@
 an error
-=
+ = 
 false;%0A 
@@ -984,102 +984,21 @@
 ror,
-new LanguageText().en(%22List contains duplicate entries%22).de(%22Liste enth%C3%A4lt doppelte Eintr%C3%A4ge%22)
+ errorMessage
 );%0A 

add custom message to UniqueListBy validation