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:
@@ -22,6 +22,7 @@
|
|||||||
package com.threerings.parlor.card.data;
|
package com.threerings.parlor.card.data;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.threerings.util.StreamableArrayList;
|
import com.threerings.util.StreamableArrayList;
|
||||||
|
|
||||||
@@ -91,16 +92,17 @@ public class Deck extends StreamableArrayList
|
|||||||
*/
|
*/
|
||||||
public Hand dealHand (int size)
|
public Hand dealHand (int size)
|
||||||
{
|
{
|
||||||
if (size() < size) {
|
int dsize = size();
|
||||||
|
if (dsize < size) {
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Hand hand = new Hand();
|
Hand hand = new Hand();
|
||||||
|
|
||||||
int cardsLeft = size();
|
// use a sublist view to manipulate the top of the deck
|
||||||
for (int i = 0; i < size; i++) {
|
List sublist = subList(dsize - size, dsize);
|
||||||
hand.add(remove(--cardsLeft));
|
hand.addAll(sublist);
|
||||||
}
|
sublist.clear();
|
||||||
|
|
||||||
return hand;
|
return hand;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user