I have a class with member variables:
class Filter{
private String key;
private String operator;
private Object value;
}
And List of Type Filter as below:
[
{
key: status,
operator:equal,
value: active
},
{
key: status,
operator:equal,
value: inactive
},
{
key: name,
operator:equal,
value: jhon
},
{
key: id,
operator:equal,
value: 123
}
]
I want to transform the above List into a new List as below where if the key is same key: status
then in new list need to have only one entry with value is in list type value: [active, inactive]
and operator will be IN
[
{
key: status,
operator:in,
value: [active, inactive]
},
{
key: name,
operator:equal,
value: jhon
},
{
key: id,
operator:equal,
value: 123
}
]
What is the best and efficient way to achieve this solution, preferably using Java 8 stream and lambdas? Wanted to avoid traditional for loop.