--
guava-...@googlegroups.com.
http://groups.google.com/group/guava-discuss?hl=en
unsubscribe: guava-discus...@googlegroups.com
This list is for discussion; for help, post to Stack Overflow instead:
http://stackoverflow.com/questions/ask
Use the tag "guava".
[Sorry, this message got held as possible-spam (perhaps you are not a group member, Willi?). I've just gone and approved a few messages that had accumulated and whitelisted their senders for all future messages.]Comparators have rules -- they have to be reflexive, antisymmetric, and transitive (see Comparator documentation for details).
I think the original author may want to consider Collections.shuffle() instead.Tobias
--
A disadvantage of Ordering.arbitrary() is that it can very occasionally throw AssertionError.
Also, what might be an advantage or disadvantage is that if you order the same objects twice with the same Ordering.arbitrary(), you always get the same result, rather than a different random permutation.
[Sorry, this message got held as possible-spam (perhaps you are not a group member, Willi?).
I've just gone and approved a few messages that had accumulated and whitelisted their senders for all future messages.]Comparators have rules -- they have to be reflexive, antisymmetric, and transitive (see Comparator documentation for details). What you probably want is Ordering.arbitrary(), which does exist. Note that it is identity-based, so won't recognize two equal Objects as equivalent (you could run objects through an Interner first if that is a concern).
Tobias
I'm not sure what you mean with "group"ing your collection, but is your collection is a List and each group is a sublist?
If so, you should be able to do
Collections.shuffle(myList.subList(start, end));
Then why don't you shuffle first, and then subsequently sort by BusinessEntity.isPaying() alone?
Alternatively, how about using 2 lists?
Joshua
On Jul 26, 2010 8:16 AM, "Willi Schönborn" <w.scho...@googlemail.com> wrote:
> On 26/07/10 03:42, Tobias Thierer wrote:
>> Then why don't you shuffle first, and then subsequently sort by
>> BusinessEntity.isPaying() alone?
> I'm so dumb.
>>
>> Tobias
>>
>> On Thu, Jul 22, 2010 at 6:01 PM, Willi Schönborn
>> <w.scho...@googlemail.com <mailto:w.scho...@googlemail.com>> wrote:
>>
>> On 22/07/10 02:55, Tobias Thierer wrote:
>>> I'm not sure what you mean with "group"ing your collection, but
>>> is your collection is a List and each group is a sublist?
>> No, what i mean is using e.g. a comparator which sorts by a
>> boolean member (e.g. BusinessEntity.isPaying()) which
>> moves paying business entites to the top and non-paying to the
>> bottom. In combination with
>>
>>>
>>> If so, you should be able to do
>>>
>>> Collections.shuffle(myList.subList(start, end));
>> This is no solutation for me, because i don't now the indices.
>>
>>>
>>> Tobias
>>>
>>> On Wed, Jul 21, 2010 at 7:58 PM, Willi Schönborn
>>> <w.scho...@googlemail.com
>>>> <mailto:guava-...@googlegroups.com>.
>>>> http://groups.google.com/group/guava-discuss?hl=en
>>>> unsubscribe: guava-discus...@googlegroups.com
>>>> <mailto:guava-discus...@googlegroups.com>
>>>>
>>>> This list is for discussion; for help, post to Stack
>>>> Overflow instead:
>>>> http://stackoverflow.com/questions/ask
>>>> Use the tag "guava".
>>>
>>> --
>>> guava-...@googlegroups.com
>>> <mailto:guava-...@googlegroups.com>.
>>> http://groups.google.com/group/guava-discuss?hl=en
>>> unsubscribe: guava-discus...@googlegroups.com
>>> <mailto:guava-discuss%2Bunsu...@googlegroups.com>
>>>
>>> This list is for discussion; for help, post to Stack Overflow
>>> instead:
>>> http://stackoverflow.com/questions/ask
>>> Use the tag "guava".
>>>
>>>
>>> --
>>> guava-...@googlegroups.com
>>> <mailto:guava-...@googlegroups.com>.
>>> http://groups.google.com/group/guava-discuss?hl=en
>>> unsubscribe: guava-discus...@googlegroups.com
>>> <mailto:guava-discus...@googlegroups.com>
>>>
>>> This list is for discussion; for help, post to Stack Overflow
>>> instead:
>>> http://stackoverflow.com/questions/ask
>>> Use the tag "guava".
>>
>> --
>> guava-...@googlegroups.com
>> <mailto:guava-...@googlegroups.com>.
>> http://groups.google.com/group/guava-discuss?hl=en
>> unsubscribe: guava-discus...@googlegroups.com
>> <mailto:guava-discuss%2Bunsu...@googlegroups.com>
Heh. Good old radix (shuffling N elements is the same as sorting on a random permutation of 1...N numbers, so there are two "digits"/columns on which to sort, your boolean one, and the random number).Nobody knows how many years it took for some random (pun intended) sorting machine operator (late 19th century, or early 20th) to realize that sorting the digits in right-to-left order was much better (the old way, sorting on the most important digit first, meant that piles with equal values for that digit had to be separated and sorted independently).
I would still expect this trick to work with an unstable sort. You're not guaranteed to get the same random ordering, but why would that matter?
Joshua
>>>>> unsubscribe: guava-discus...@googlegroups.com<guava-discuss%2Bunsu...@googlegroups.com>
>>>>>
>>>>> This list is for discussion; for help, post to Stack Overflow instead:
>>>>> http://stackoverflow.com/questions/ask
>>>>> Use the tag "guava".
>>>>>
>>>>
>>>> --
>>>> guava-...@googlegroups.com.
>>>> http://groups.google.com/group/guava-discuss?hl=en
>>>> unsubscribe: guava-discus...@googlegroups.com
>>>>
>>>> This list is for discussion; for help, post to Stack Overflow instead:
>>>> http://stackoverflow.com/questions/ask
>>>> Use the tag "guava".
>>>>
>>>>
>>>> --
>>>> guava-...@googlegroups.com.
>>>> http://groups.google.com/group/guava-discuss?hl=en
>>>> unsubscribe: guava-discus...@googlegroups.com<guava-discuss%2Bunsu...@googlegroups.com>
>>>>
>>>> This list is for discussion; for help, post to Stack Overflow instead:
>>>> http://stackoverflow.com/questions/ask
>>>> Use the tag "guava".
>>>>
>>>
>>> --
>>> guava-...@googlegroups.com.
>>> http://groups.google.com/group/guava-discuss?hl=en
>>> unsubscribe: guava-discus...@googlegroups.com
>>>
>>> This list is for discussion; for help, post to Stack Overflow instead:
>>> http://stackoverflow.com/questions/ask
>>> Use the tag "guava".
>>>
>>>
>>> --
>>> guava-...@googlegroups.com.
>>> http://groups.google.com/group/guava-discuss?hl=en
>>> unsubscribe: guava-discus...@googlegroups.com<guava-discuss%2Bunsu...@googlegroups.com>
I would still expect this trick to work with an unstable sort. You're not guaranteed to get the same random ordering, but why would that matter?