MultiSet satisfies your first requirement.
> two other questions:
>
> 1- is there a Pair structure in Guava ?
> 2- is there a Tuple structure in Guava ?
The Guava developers have opted against introducing Pair-style structures. AFAIK, the reason being that such a structure does not convey the proper context of why object 1 and object 2 are paired up.
Instead, you should look at why you're trying to combine your two objects in each set element and create a class that expresses the contract between the two objects properly.
Eg. If it's a username and password, you might want to make a Credentials class which provides accessors for a username and password, and then use a MultiSet<Credentials>. At least then your code explains the contract rather than tying the objects in some generic way that may make little sense to you later on. It also provides you with a perfect place for documenting this contract with JavaDoc and allows you to sensibly extend upon your structures without needing to refactor all the code that uses your MultiSet.
I think you're thinking of SetMultimap, rather than Multiset.
(SetMultimap is roughly a Map<K, Set<V>>; Multiset is roughly a Map<K,
Integer>.)
>> two other questions:
>>
>> 1- is there a Pair structure in Guava ?
>> 2- is there a Tuple structure in Guava ?
>
> The Guava developers have opted against introducing Pair-style structures. AFAIK, the reason being that such a structure does not convey the proper context of why object 1 and object 2 are paired up.
>
> Instead, you should look at why you're trying to combine your two objects in each set element and create a class that expresses the contract between the two objects properly.
> Eg. If it's a username and password, you might want to make a Credentials class which provides accessors for a username and password, and then use a MultiSet<Credentials>. At least then your code explains the contract rather than tying the objects in some generic way that may make little sense to you later on. It also provides you with a perfect place for documenting this contract with JavaDoc and allows you to sensibly extend upon your structures without needing to refactor all the code that uses your MultiSet.
Exactly.
As if a collection such as a SetMultimap conveys any context as to why
its items are 'collected'.
I understand other reasons for not including a Pair or Tuple type in
Guava, but in the religious debate on whether or not to protect
inexperienced developers from shooting themselves and others in the
foot versus increasing developer productivity, I am pro-productivity.
That said, for me, the productivity argument only holds for tuples as
long as all developers understand where using tuples really hampers
readability.
Maybe Guava's stance on this should go in a faq somewhere, along with
the whole functional programming debate. As much as I'd love to argue
about this endlessly, maybe it would cut down on some noise? :)
--
Johan