I have two collections like below:
Set<String> attributes = Sets.newHashSet("aaa", "bbb", "ccc", "ddd");
Set<String> activeAttributes = Sets.newHashSet("eee", "lll", "ccc", "mmm");
The idea to convert these collections to a map, given that attributes
collection should be used as keys of this map and activeAttributes
should be used during calculating value (In case activeAttributes
contains value from collection attributes
then "true", otherwise "false" parameter should be set):
As example:
({aaa -> false, bbb -> false, ccc -> true, ddd -> false })
I've tried to create a Guava function that converts list to collection of Map.Entry:
private static class ActiveAttributesFunction implements Function<String, Map.Entry<String, Boolean>> {
private Set<String> activeAttributes;
public ActiveAttributesFunction (Set<String> activeAttributes) {
this.activeAttributes = activeAttributes;
}
@Override
public Map.Entry<String, Boolean> apply(String input) {
return Maps.immutableEntry(input, activeAttributes.contains(input));
}
}
But, this function will require to convert this list of entries to map.
Please suggest in which way this can be simplified?