I am currently implementing a way to match a Predicate to a text string
To do that matching I'm filling a Map of < Predicate, String> and then I can retrieve the corresponding String via the predicate.
The problem is that when using a parameterized predicate like in the code below the same predicate match for different parameters (valueToTest not used in the hashing function)
public static Predicate<MyObject> predicateCondition(String valueToTest) {
return myObject -> myObject.value.equals(valueToTest);
}
So currently I need to make one predicate per parameter I would want to test ie :
public static Predicate<MyObject> predicateConditionValue1() {
return myObject -> myObject.value.equals("value1");
}
public static Predicate<MyObject> predicateConditionValue2() {
return myObject -> myObject.value.equals("value2");
}
Would there be another way to avoid duplicating the predicate?