I have the following BiMap collections:
BiMap<String,String> accessIds = HashBiMap.create();
accessIds.put("FOO","accessId 1"); //This access Id is common to both FOO and BAR
BiMap<String,String> merchants = HashBiMap.create();
merchants.put("FOO", "merchant 1"); //Both FOO and BAR each have unique merchants
merchants.put("BAR", "merchant 2");
These are 2 of the 4 total collections I currently have. All 4 collections share the same keys, but different values.
The question I have is: How can I ensure that I can get merchant 2 when I have an accessIds key of FOO?
Before someone points out that these two collections do not, in fact, share the same keys, please remember that a BiMap enforces unique values so I am unable to list "BAR","accessId 1" in the collection.
I’m not convinced that BiMap is the right collection, but I do make use of its inverse() method. If there is a collection better suited ( or some other method that I am overlooking ) please let me know.
FYI: I use Guava-14.0-rc1 for the BiMap collection.
Based on your comment, in your workflow, the Access ID is a key, not a value, that in at least one case has several associated values instead of one.
You could use a
Multimapfor your Access IDS, assuming you can then select which value to retain as the key for accessing the otherMaps (orBiMaps, though it’s unclear through your example why they areBiMaps, but I guess that’s unrelated).If you cannot use immutable structures, you can also build a regular
MultimapforaccessIds(for example using aHashMultimap) and inverse it usingMultimaps.invertFrom().