So there is 1 class, and 1 Enum. The Enum is for instance:
public enum E {
E1, E2, E3
}
The class:
public class A {
private E e;
private String name;
public A (E e, String name){
this.e = e;
this.name = name;
}
public E getE(){
return E;
}
public String getName(){
return name;
}
}
Given is a List< A >. What I want is to filter the list (with stream) depending on their name and their enum-attribute. Filtered are only A's that don't have the maximum name length compared to the other objects that have the same enum-attribute.
The output should be a Map< E, List< A>>. List because there could be more than one object with the same name length.
Sample:
List<A> input = Arrays.asList(new A(E.E1, "abcd"), new A(E.E1, "xyz"), new A(E.E2, "abcd"), new A(E.E2, "wxyz"), new A(E.E3, "xyzb"));
This should return:
E1 = "abcd" // because "xyz" has length 3
E2 = "abcd", "wxyz" // as both have length 4, e.g. max length
E3 = "xyzb" // because it is the only object
One of my solution was you can group the list with "groupingBy" into their respective enum group. At the end you have then for instance 3 keys with a list of A's as value. Eventually you simply have to delete all the values that have a name shorter than the maximum name length. But only in their respective key