Use a sublist view rather than removing and adding cards one by one.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3713 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2005-09-27 21:58:10 +00:00
parent 7fb4eafbf8
commit 4fbb911d7c
@@ -22,6 +22,7 @@
package com.threerings.parlor.card.data;
import java.util.Collections;
import java.util.List;
import com.threerings.util.StreamableArrayList;
@@ -91,16 +92,17 @@ public class Deck extends StreamableArrayList
*/
public Hand dealHand (int size)
{
if (size() < size) {
int dsize = size();
if (dsize < size) {
return null;
} else {
Hand hand = new Hand();
int cardsLeft = size();
for (int i = 0; i < size; i++) {
hand.add(remove(--cardsLeft));
}
// use a sublist view to manipulate the top of the deck
List sublist = subList(dsize - size, dsize);
hand.addAll(sublist);
sublist.clear();
return hand;
}