I really don't like asking here, but this time I've searched, I've read the docs, I've asked for help in other places and apparently nobody knows how to fix my problem.
I use the BiMap
from google Guava for my java application, because I have a situation where I need the key for a specific value (also both key and value are unique). In the not-inversed view the key is a long
, the value an own class (which also implements hashCode
and equals
).
Now, I have a specific entry from which I only know the value (however, I know that this entry exists, I made some checks that you can see below as well). But if I inverse the map and use the known value as a key, the value that is returned is always null
. To ensure it is this particular point where the problem is, I hardcoded some debug lines: https://hastebin.com/gisojogune.cs
(Unfortunately I can't paste it elsewhere because I'm on mobile atm)
I'd be glad if anyone would be able to help me, because I gotta finish this until tomorrow. Yay.
Thanks, Johnny
Edit: In the link, the other Map
is supposed to be called requests
. Don't mind that.
From the scarce information you provided it's very hard to help, but this line is suspicious:
var link = requests.get(aLong); // this should be the same instance that is assigned to the key 458653247347884035L
If aLong
is different than 458653247347884035L
(but I'm not sure if that's what you meant), then it's not possible1 for a BiMap
to contain two identical Link
s with a different key. If that's what you meant, then probably there's something wrong with your hashCode
/equals
logic.
1 As a proof, try to run this little snippet:
String link = "same-instance";
BiMap<Long, String> requesters = HashBiMap.create();
requesters.put(1L, link);
requesters.put(2L, link);
You'll get the following exception:
java.lang.IllegalArgumentException: value already present: same-instance