I have a MultiMap and need the best possible way to get an EntrySet of a MultiMap using one of the values in the list. Right now, I’m iterating through the entry set of the whole map and checking if the value of the list contains my needed values. This works for a limited number of inputs on the map, but its now turned into 800ms – 1 second work, which just wont cut it. Thanks for the help in advanced.
Example:
public static void main(String[] args) {
MultiMap multi = new MultiHashMap();
multi.put("Key1", new ArrayList<String>(Arrays.asList(new String[] { "Value1", "Value2", "Value3" })));
}
I want to be able to get Key1, Value1, Value2 and Value3 by only inputting Value1 and Value2 as arguments
Also, if it’s any help, this is from a cache after reading a data source
[Edited to allow for group of values to be tested simultaneously]
[Edited again now that the question has been clarified]
This implementation avoids explicit loops, and is written in a more functional manner using Guava extensions:
A test program:
The output:
[1=a, 4=a, 5=c]
I’d be curious to know how inefficient it is.