A healthy swig of google-collections

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@839 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Dave Hoover
2009-05-23 01:33:28 +00:00
parent 1bfaa30761
commit 3c5c5e6ba5
25 changed files with 142 additions and 118 deletions
@@ -34,6 +34,8 @@ import java.awt.event.MouseEvent;
import javax.swing.event.MouseInputAdapter;
import com.google.common.collect.Lists;
import com.samskivert.util.ObserverList;
import com.samskivert.util.Predicate;
import com.samskivert.util.QuickSort;
@@ -259,8 +261,8 @@ public abstract class CardPanel extends VirtualMediaPanel
public void clearHandSelection ()
{
CardSprite[] sprites = getSelectedHandSprites();
for (int i = 0; i < sprites.length; i++) {
deselectHandSprite(sprites[i]);
for (CardSprite sprite : sprites) {
deselectHandSprite(sprite);
}
}
@@ -394,11 +396,11 @@ public abstract class CardPanel extends VirtualMediaPanel
{
// fly each sprite over, removing it from the hand immediately and from the board when it
// finishes its path
for (int i = 0; i < cards.length; i++) {
removeFromHand(cards[i]);
for (CardSprite card : cards) {
removeFromHand(card);
LinePath flight = new LinePath(dest, flightDuration);
cards[i].addSpriteObserver(_pathEndRemover);
cards[i].moveAndFadeOut(flight, flightDuration, fadePortion);
card.addSpriteObserver(_pathEndRemover);
card.moveAndFadeOut(flight, flightDuration, fadePortion);
}
// adjust the hand to cover the hole
@@ -433,21 +435,21 @@ public abstract class CardPanel extends VirtualMediaPanel
// then set the layers and fly the cards in
int size = _handSprites.size();
for (int i = 0; i < sprites.length; i++) {
int idx = _handSprites.indexOf(sprites[i]);
sprites[i].setLocation(src.x, src.y);
sprites[i].setRenderOrder(idx);
sprites[i].addSpriteObserver(_handSpriteObserver);
addSprite(sprites[i]);
for (CardSprite sprite : sprites) {
int idx = _handSprites.indexOf(sprite);
sprite.setLocation(src.x, src.y);
sprite.setRenderOrder(idx);
sprite.addSpriteObserver(_handSpriteObserver);
addSprite(sprite);
// create a path sequence containing flight, pause, and drop
ArrayList<Path> paths = new ArrayList<Path>();
ArrayList<Path> paths = Lists.newArrayList();
Point hp2 = new Point(getHandX(size, idx), _handLocation.y),
hp1 = new Point(hp2.x, hp2.y - _selectedCardOffset);
paths.add(new LinePath(hp1, flightDuration));
paths.add(new LinePath(hp1, pauseDuration));
paths.add(new LinePath(hp2, dropDuration));
sprites[i].moveAndFadeIn(new PathSequence(paths), flightDuration +
sprite.moveAndFadeIn(new PathSequence(paths), flightDuration +
pauseDuration + dropDuration, fadePortion);
}
}
@@ -587,11 +589,11 @@ public abstract class CardPanel extends VirtualMediaPanel
public void flyFromBoard (CardSprite[] cards, Point dest, long flightDuration,
float fadePortion)
{
for (int i = 0; i < cards.length; i++) {
for (CardSprite card : cards) {
LinePath flight = new LinePath(dest, flightDuration);
cards[i].addSpriteObserver(_pathEndRemover);
cards[i].moveAndFadeOut(flight, flightDuration, fadePortion);
_boardSprites.remove(cards[i]);
card.addSpriteObserver(_pathEndRemover);
card.moveAndFadeOut(flight, flightDuration, fadePortion);
_boardSprites.remove(card);
}
}
@@ -608,13 +610,13 @@ public abstract class CardPanel extends VirtualMediaPanel
public void flyFromBoard (CardSprite[] cards, Point dest1, Point dest2, long flightDuration,
float fadePortion)
{
for (int i = 0; i < cards.length; i++) {
for (CardSprite card : cards) {
PathSequence flight = new PathSequence(
new LinePath(dest1, flightDuration/2),
new LinePath(dest1, dest2, flightDuration/2));
cards[i].addSpriteObserver(_pathEndRemover);
cards[i].moveAndFadeOut(flight, flightDuration, fadePortion);
_boardSprites.remove(cards[i]);
card.addSpriteObserver(_pathEndRemover);
card.moveAndFadeOut(flight, flightDuration, fadePortion);
_boardSprites.remove(card);
}
}
@@ -1072,11 +1074,10 @@ public abstract class CardPanel extends VirtualMediaPanel
protected CardSprite _activeCardSprite;
/** The sprites for cards within the hand. */
protected ArrayList<CardSprite> _handSprites = new ArrayList<CardSprite>();
protected ArrayList<CardSprite> _handSprites = Lists.newArrayList();
/** The sprites for cards within the hand that have been selected. */
protected ArrayList<CardSprite> _selectedHandSprites =
new ArrayList<CardSprite>();
protected ArrayList<CardSprite> _selectedHandSprites = Lists.newArrayList();
/** The current selection mode for the hand. */
protected int _handSelectionMode;
@@ -1103,7 +1104,7 @@ public abstract class CardPanel extends VirtualMediaPanel
protected int _selectedCardOffset;
/** The sprites for cards on the board. */
protected ArrayList<CardSprite> _boardSprites = new ArrayList<CardSprite>();
protected ArrayList<CardSprite> _boardSprites = Lists.newArrayList();
/** The hand sprite observer instance. */
protected HandSpriteObserver _handSpriteObserver = new HandSpriteObserver();
@@ -21,10 +21,11 @@
package com.threerings.parlor.card.trick.server;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.google.common.collect.Lists;
import com.samskivert.util.ArrayUtil;
import com.samskivert.util.Interval;
import com.samskivert.util.RandomUtil;
@@ -451,7 +452,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
*/
protected Card pickRandomPlayableCard (Hand hand)
{
List<Card> playableCards = new ArrayList<Card>();
List<Card> playableCards = Lists.newArrayList();
for (int i = 0; i < hand.size(); i++) {
Card card = hand.get(i);
if (_trickCardGame.isCardPlayable(hand, card)) {
@@ -25,6 +25,7 @@ import java.util.HashSet;
import java.util.List;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.samskivert.util.ArrayIntSet;
import com.samskivert.util.ListUtil;
@@ -129,8 +130,8 @@ public class Table
@ActionScript(omit=true)
public boolean isEmpty ()
{
for (int i = 0; i < bodyOids.length; i++) {
if (bodyOids[i] != 0) {
for (int bodyOid : bodyOids) {
if (bodyOid != 0) {
return false;
}
}
@@ -144,8 +145,8 @@ public class Table
{
int count = 0;
if (players != null) {
for (int ii = 0; ii < players.length; ii++) {
if (players[ii] != null) {
for (Name player : players) {
if (player != null) {
count++;
}
}
@@ -270,7 +271,7 @@ public class Table
public void addBannedUser (Name player)
{
if (_bannedUsers == null) {
_bannedUsers = new HashSet<Name>();
_bannedUsers = Sets.newHashSet();
}
_bannedUsers.add(player);
@@ -373,10 +374,10 @@ public class Table
} else {
// for a team game, make sure each team has the minimum players
int[][] teams = tconfig.teamMemberIndices;
for (int ii=0; ii < teams.length; ii++) {
for (int[] team : teams) {
int teamCount = 0;
for (int jj=0; jj < teams[ii].length; jj++) {
if (players[teams[ii][jj]] != null) {
for (int jj=0; jj < team.length; jj++) {
if (players[team[jj]] != null) {
teamCount++;
}
}
@@ -21,9 +21,10 @@
package com.threerings.parlor.game.data;
import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.Lists;
import com.threerings.util.Name;
import com.threerings.crowd.data.PlaceConfig;
@@ -121,7 +122,7 @@ public abstract class GameConfig extends PlaceConfig
*/
public List<String> getDescription ()
{
return new ArrayList<String>(); // nothing by default
return Lists.newArrayList(); // nothing by default
}
/**
@@ -99,7 +99,7 @@ public class RatingRepository extends DepotRepository
*/
public List<RatingRecord> getRatings (int playerId, long since, int count)
{
ArrayList<QueryClause> clauses = new ArrayList<QueryClause>();
ArrayList<QueryClause> clauses = Lists.newArrayList();
if (since > 0L) {
Timestamp when = new Timestamp(System.currentTimeMillis() - since);
clauses.add(new Where(new And(new Equals(RatingRecord.PLAYER_ID, playerId),
@@ -30,6 +30,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import com.google.common.collect.Lists;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -146,7 +147,7 @@ public class TourneyRepository extends JORARepository
throws PersistenceException
{
ArrayList<TourneyRecord> recordList = loadAll(_ttable, "");
ArrayList<TourneyConfig> configList = new ArrayList<TourneyConfig>(recordList.size());
ArrayList<TourneyConfig> configList = Lists.newArrayListWithCapacity(recordList.size());
for (TourneyRecord record : recordList) {
configList.add(record.getTourneyConfig());
}
@@ -31,6 +31,8 @@ import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import com.google.common.collect.Maps;
import com.samskivert.swing.util.SwingUtil;
import com.threerings.util.Name;
@@ -213,7 +215,7 @@ public class TurnDisplay extends JPanel
protected TurnGameObject _turnObj;
/** A mapping of the labels currently associated with each player. */
protected HashMap<Name,JLabel> _labels = new HashMap<Name,JLabel>();
protected HashMap<Name,JLabel> _labels = Maps.newHashMap();
/** The game-specified player icons. */
protected Icon[] _playerIcons;
@@ -21,11 +21,12 @@
package com.threerings.parlor.util;
import java.util.ArrayList;
import java.util.List;
import java.awt.Component;
import com.google.common.collect.Lists;
import com.samskivert.util.CollectionUtil;
import com.samskivert.util.Interval;
import com.samskivert.util.RandomUtil;
@@ -118,10 +119,10 @@ public class RobotPlayer extends Interval
protected long _robotDelay = DEFAULT_ROBOT_DELAY;
/** The list of available key press action commands. */
protected List<String> _press = new ArrayList<String>();
protected List<String> _press = Lists.newArrayList();
/** The list of available key release action commands. */
protected List<String> _release = new ArrayList<String>();
protected List<String> _release = Lists.newArrayList();
/** The key translator that describes available keys and commands. */
protected KeyTranslator _xlate;