change it to
public HashBiMap<String,HashSet<FileObject>> wordToFiles = HashBiMap.create ();
But still it looks very strange. I think you should use another collection. From BiMap
documentation (HashBiMap
impelements BiMap
):
A bimap (or "bidirectional map") is a
map that preserves the uniqueness of
its values as well as that of its
keys. This constraint enables bimaps
to support an "inverse view", which is
another bimap containing the same
entries as this bimap but with
reversed keys and values.
I don't know the problem you want to solve but after looking at your code I can suggest to consider using Multimaps. From its docs:
A collection similar to a Map, but
which may associate multiple values
with a single key. If you call put(K,
V) twice, with the same key but
different values, the multimap
contains mappings from the key to both
values.
For example, you can do something like this:
Multimap<String, FileObject> wordToFiles = HashMultimap.create();
wordToFiles.put("first", somefile);
wordToFiles.put("first", anotherfile);
for (FileObject file : wordToFiles.get("first"){
doSomethingWithFile (file);
}