Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does guava have a Map implementation that takes custom hash/equals functions?

Tags:

java

guava

Anyone know if Guava has an equivalent version to Functionaljava's HashMap?

like image 633
ebaxt Avatar asked Feb 22 '12 11:02

ebaxt


People also ask

How does map equals work?

Map equals() method in Java with Examples Map. equals() method in Java is used to check for equality between two maps. It verifies whether the elements of one map passed as a parameter is equal to the elements of this map or not.


1 Answers

As far as I know, no.

But you can wrap all your keys in Equivalence.Wrapper instances using the Equivalence strategy you need:

Equivalence<K> equiv = ...
Map<Equivalence.Wrapper<K>, V> map = ...

map.put(equiv.wrap(key), value);

Of course this means you need an additional object for every entry in your map. Thus I think a map implementation like you suggest would be nice to have.

like image 82
Philipp Wendler Avatar answered Sep 18 '22 18:09

Philipp Wendler