summaryrefslogtreecommitdiffstats
path: root/src/jrummikub
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-06-07 16:59:06 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-06-07 16:59:06 +0200
commit244abb7e7320355d0c4aad4a7ba267f11d358563 (patch)
treedd612c5022132d77a9b4f7f1c85f95ce83e2789a /src/jrummikub
parentaf3661fea084df6e089c2597dc4b311c77f39e4f (diff)
downloadJRummikub-244abb7e7320355d0c4aad4a7ba267f11d358563.tar
JRummikub-244abb7e7320355d0c4aad4a7ba267f11d358563.zip
Make model fully serializable
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@381 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub')
-rw-r--r--src/jrummikub/model/GameSettings.java31
-rw-r--r--src/jrummikub/model/GameState.java7
-rw-r--r--src/jrummikub/model/Hand.java21
-rw-r--r--src/jrummikub/model/IPlayer.java4
-rw-r--r--src/jrummikub/model/IRoundState.java26
-rw-r--r--src/jrummikub/model/IStoneTray.java4
-rw-r--r--src/jrummikub/model/Player.java2
-rw-r--r--src/jrummikub/model/PlayerSettings.java16
-rw-r--r--src/jrummikub/model/Position.java5
-rw-r--r--src/jrummikub/model/RoundState.java5
-rw-r--r--src/jrummikub/model/Score.java18
-rw-r--r--src/jrummikub/model/Stone.java25
-rw-r--r--src/jrummikub/model/StoneHeap.java13
-rw-r--r--src/jrummikub/model/StoneTray.java1
-rw-r--r--src/jrummikub/model/Table.java13
-rw-r--r--src/jrummikub/util/Pair.java14
16 files changed, 119 insertions, 86 deletions
diff --git a/src/jrummikub/model/GameSettings.java b/src/jrummikub/model/GameSettings.java
index 2a8ae0b..671b57c 100644
--- a/src/jrummikub/model/GameSettings.java
+++ b/src/jrummikub/model/GameSettings.java
@@ -2,6 +2,7 @@ package jrummikub.model;
import static jrummikub.model.StoneColor.*;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@@ -11,8 +12,10 @@ import java.util.Set;
/**
* The overall game settings
*/
-public class GameSettings {
- private List<PlayerSettings> players = new ArrayList<PlayerSettings>();
+public class GameSettings implements Serializable {
+ private static final long serialVersionUID = -7221346125938175643L;
+
+ private ArrayList<PlayerSettings> players = new ArrayList<PlayerSettings>();
private int initialMeldThreshold;
private int jokerPoints;
@@ -21,7 +24,7 @@ public class GameSettings {
private int stoneSetNumber;
private int numberOfStonesDealt;
private boolean noLimits;
- private Set<StoneColor> stoneColors;
+ private HashSet<StoneColor> stoneColors;
/**
* Creates new GameSettings with default values
@@ -34,8 +37,8 @@ public class GameSettings {
stoneSetNumber = 2;
numberOfStonesDealt = 14;
noLimits = false;
- stoneColors = new HashSet<StoneColor>(Arrays.asList(BLACK, BLUE,
- ORANGE, RED));
+ stoneColors = new HashSet<StoneColor>(Arrays.asList(BLACK, BLUE, ORANGE,
+ RED));
}
/**
@@ -51,7 +54,7 @@ public class GameSettings {
* Sets the initial meld threshold
*
* @param value
- * the value to set
+ * the value to set
*/
public void setInitialMeldThreshold(int value) {
initialMeldThreshold = value;
@@ -70,7 +73,7 @@ public class GameSettings {
* Sets the points counted for a joker
*
* @param value
- * the value to set
+ * the value to set
*/
public void setJokerPoints(int value) {
jokerPoints = value;
@@ -89,7 +92,7 @@ public class GameSettings {
* Sets the number of jokers in game
*
* @param value
- * how many jokers will be used
+ * how many jokers will be used
*/
public void setJokerNumber(int value) {
jokerNumber = value;
@@ -117,7 +120,7 @@ public class GameSettings {
* Set the highest stone value in use
*
* @param highestValue
- * highest stone value
+ * highest stone value
*/
public void setHighestValue(int highestValue) {
this.highestValue = highestValue;
@@ -136,7 +139,7 @@ public class GameSettings {
* Set the number of sets of stones in use
*
* @param stoneSets
- * sets of stones in use
+ * sets of stones in use
*/
public void setStoneSetNumber(int stoneSets) {
this.stoneSetNumber = stoneSets;
@@ -155,7 +158,7 @@ public class GameSettings {
* Set whether "No-Limits" rules are used
*
* @param noLimits
- * use no limit rules
+ * use no limit rules
*/
public void setNoLimits(boolean noLimits) {
this.noLimits = noLimits;
@@ -174,10 +177,10 @@ public class GameSettings {
* Set stone colors used
*
* @param stoneColors
- * used stone colors
+ * used stone colors
*/
public void setStoneColors(Set<StoneColor> stoneColors) {
- this.stoneColors = stoneColors;
+ this.stoneColors = new HashSet<StoneColor>(stoneColors);
}
/**
@@ -193,7 +196,7 @@ public class GameSettings {
* Set number of stones dealt at game start
*
* @param number
- * how many Stones will be dealt initially
+ * how many Stones will be dealt initially
*/
public void setNumberOfStonesDealt(int number) {
numberOfStonesDealt = number;
diff --git a/src/jrummikub/model/GameState.java b/src/jrummikub/model/GameState.java
index 35de4f1..8311977 100644
--- a/src/jrummikub/model/GameState.java
+++ b/src/jrummikub/model/GameState.java
@@ -1,5 +1,6 @@
package jrummikub.model;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -7,9 +8,11 @@ import java.util.List;
/**
* Class that stores information for a game of multiple rounds
*/
-public class GameState {
+public class GameState implements Serializable {
+ private static final long serialVersionUID = -5787975403310108391L;
+
private int firstRoundFirstPlayer;
- private List<Score> scores = new ArrayList<Score>();
+ private ArrayList<Score> scores = new ArrayList<Score>();
/**
* Gets the number of the first player of the first round
diff --git a/src/jrummikub/model/Hand.java b/src/jrummikub/model/Hand.java
index 812a4e4..681241a 100644
--- a/src/jrummikub/model/Hand.java
+++ b/src/jrummikub/model/Hand.java
@@ -1,7 +1,6 @@
package jrummikub.model;
-import static jrummikub.model.StoneTray.Direction.LEFT;
-import static jrummikub.model.StoneTray.Direction.RIGHT;
+import static jrummikub.model.StoneTray.Direction.*;
import java.util.ArrayList;
import java.util.Iterator;
@@ -13,6 +12,8 @@ import jrummikub.util.Pair;
/** Class managing a {@link Player}'s {@link Stone}s */
public class Hand extends StoneTray<Stone> implements IHand {
+ private static final long serialVersionUID = 192210056255744909L;
+
/**
* The width of the hand
*/
@@ -43,8 +44,8 @@ public class Hand extends StoneTray<Stone> implements IHand {
}
@Override
- protected Pair<Position, Direction> fixInvalidDrop(Stone stone,
- Position pos, Direction dir) {
+ protected Pair<Position, Direction> fixInvalidDrop(Stone stone, Position pos,
+ Direction dir) {
double x = pos.getX();
double y = pos.getY();
@@ -55,11 +56,9 @@ public class Hand extends StoneTray<Stone> implements IHand {
return new Pair<Position, Direction>(new Position(0, y), RIGHT);
} else {
if (getFreeRowSpace((int) y) == 0) {
- return new Pair<Position, Direction>(new Position(0, y + 1),
- RIGHT);
+ return new Pair<Position, Direction>(new Position(0, y + 1), RIGHT);
} else {
- return new Pair<Position, Direction>(
- new Position(WIDTH - 1, y), LEFT);
+ return new Pair<Position, Direction>(new Position(WIDTH - 1, y), LEFT);
}
}
}
@@ -85,8 +84,7 @@ public class Hand extends StoneTray<Stone> implements IHand {
List<Stone> stones = new ArrayList<Stone>();
- for (Iterator<Pair<Stone, Position>> iter = this.iterator(); iter
- .hasNext();) {
+ for (Iterator<Pair<Stone, Position>> iter = this.iterator(); iter.hasNext();) {
stones.add(iter.next().getFirst());
}
@@ -104,8 +102,7 @@ public class Hand extends StoneTray<Stone> implements IHand {
public int getIdenticalStoneCount() {
List<Stone> stones = new ArrayList<Stone>();
- for (Iterator<Pair<Stone, Position>> iter = this.iterator(); iter
- .hasNext();) {
+ for (Iterator<Pair<Stone, Position>> iter = this.iterator(); iter.hasNext();) {
stones.add(iter.next().getFirst());
}
diff --git a/src/jrummikub/model/IPlayer.java b/src/jrummikub/model/IPlayer.java
index 03b5da4..25471b8 100644
--- a/src/jrummikub/model/IPlayer.java
+++ b/src/jrummikub/model/IPlayer.java
@@ -1,9 +1,11 @@
package jrummikub.model;
+import java.io.Serializable;
+
/**
* Interface for {@link Player} model
*/
-public interface IPlayer {
+public interface IPlayer extends Serializable {
/**
* Get the current hand of the player
diff --git a/src/jrummikub/model/IRoundState.java b/src/jrummikub/model/IRoundState.java
index 1f6da15..d394694 100644
--- a/src/jrummikub/model/IRoundState.java
+++ b/src/jrummikub/model/IRoundState.java
@@ -1,9 +1,11 @@
package jrummikub.model;
+import java.io.Serializable;
+
/**
* Interface for {@link RoundState} model
*/
-public interface IRoundState {
+public interface IRoundState extends Serializable {
/**
* Get the current {@link GameSettings}
@@ -23,7 +25,7 @@ public interface IRoundState {
* Sets the current {@link Table}
*
* @param table
- * The new Table
+ * The new Table
*/
public void setTable(ITable table);
@@ -55,7 +57,7 @@ public interface IRoundState {
* Returns the player that would be the active player after i turns
*
* @param i
- * number of turns
+ * number of turns
* @return player active after i turns
*/
public IPlayer getNthNextPlayer(int i);
@@ -64,25 +66,25 @@ public interface IRoundState {
* Returns the nth player
*
* @param i
- * player number
+ * player number
* @return nth player
*/
public IPlayer getNthPlayer(int i);
/**
- * Sets the player that will make the last turn before the round ends when
- * the heap is empty
+ * Sets the player that will make the last turn before the round ends when the
+ * heap is empty
*
* @return the last player
*/
public abstract IPlayer getLastPlayer();
/**
- * Gets the player that will make the last turn before the round ends when
- * the heap is empty
+ * Gets the player that will make the last turn before the round ends when the
+ * heap is empty
*
* @param lastPlayer
- * the last player
+ * the last player
*/
public abstract void setLastPlayer(IPlayer lastPlayer);
@@ -90,13 +92,13 @@ public interface IRoundState {
* Makes the player with number i the active player
*
* @param i
- * number of the player to make active
+ * number of the player to make active
*/
public void setActivePlayerNumber(int i);
/**
- * Gets the number of the current turn. Numbers smaller than one indicate
- * hand inspection turns
+ * Gets the number of the current turn. Numbers smaller than one indicate hand
+ * inspection turns
*
* @return current turn number
*/
diff --git a/src/jrummikub/model/IStoneTray.java b/src/jrummikub/model/IStoneTray.java
index f9c9d88..d286484 100644
--- a/src/jrummikub/model/IStoneTray.java
+++ b/src/jrummikub/model/IStoneTray.java
@@ -1,5 +1,7 @@
package jrummikub.model;
+import java.io.Serializable;
+
import jrummikub.util.Pair;
/**
@@ -9,7 +11,7 @@ import jrummikub.util.Pair;
* Objects held by the IStoneTray
*/
public interface IStoneTray<E extends Sizeable> extends
- Iterable<Pair<E, Position>>, Cloneable {
+ Iterable<Pair<E, Position>>, Cloneable, Serializable {
/**
* Adds object to the tray
diff --git a/src/jrummikub/model/Player.java b/src/jrummikub/model/Player.java
index 6f7885b..00469c5 100644
--- a/src/jrummikub/model/Player.java
+++ b/src/jrummikub/model/Player.java
@@ -2,6 +2,8 @@ package jrummikub.model;
/** Class managing player data. No methods in release 1 */
public class Player implements IPlayer {
+ private static final long serialVersionUID = 2588861964190952815L;
+
private PlayerSettings settings;
private IHand hand;
private boolean laidOut;
diff --git a/src/jrummikub/model/PlayerSettings.java b/src/jrummikub/model/PlayerSettings.java
index b38d746..17e521c 100644
--- a/src/jrummikub/model/PlayerSettings.java
+++ b/src/jrummikub/model/PlayerSettings.java
@@ -1,25 +1,27 @@
package jrummikub.model;
import java.awt.Color;
+import java.io.Serializable;
import jrummikub.control.turn.TurnControlFactory;
/**
* The settings of a player
*/
-public class PlayerSettings {
+public class PlayerSettings implements Serializable {
+ private static final long serialVersionUID = 1963640115089275992L;
+
private String name;
private Color color;
private TurnControlFactory.Type turnControlType;
-
/**
* Create a new human player
*
* @param name
- * the player's name
+ * the player's name
* @param color
- * the player's color
+ * the player's color
*/
public PlayerSettings(String name, Color color) {
this.name = name;
@@ -49,7 +51,7 @@ public class PlayerSettings {
* Sets the player's color
*
* @param color
- * the new color
+ * the new color
*/
public void setColor(Color color) {
this.color = color;
@@ -59,7 +61,7 @@ public class PlayerSettings {
* Sets the player's name
*
* @param name
- * the new name
+ * the new name
*/
public void setName(String name) {
this.name = name;
@@ -69,7 +71,7 @@ public class PlayerSettings {
* Set the player's TurnControlFactory type
*
* @param turnControlType
- * player's TurnControlFactory type
+ * player's TurnControlFactory type
*/
public void setTurnControlType(TurnControlFactory.Type turnControlType) {
this.turnControlType = turnControlType;
diff --git a/src/jrummikub/model/Position.java b/src/jrummikub/model/Position.java
index 47c6c89..b41d8fa 100644
--- a/src/jrummikub/model/Position.java
+++ b/src/jrummikub/model/Position.java
@@ -1,11 +1,14 @@
package jrummikub.model;
+import java.io.Serializable;
+
/**
* {@link Stone} Position class to determine positions on {@link Table} or
* {@link Hand}
*/
-public class Position {
+public class Position implements Serializable {
+ private static final long serialVersionUID = -582497930480638380L;
private double x;
private double y;
diff --git a/src/jrummikub/model/RoundState.java b/src/jrummikub/model/RoundState.java
index fd7dc15..e2125a7 100644
--- a/src/jrummikub/model/RoundState.java
+++ b/src/jrummikub/model/RoundState.java
@@ -1,14 +1,15 @@
package jrummikub.model;
import java.util.ArrayList;
-import java.util.List;
/** Class managing the overall and momentary RoundState */
public class RoundState implements IRoundState {
+ private static final long serialVersionUID = 8678490099871939059L;
+
private GameSettings gameSettings;
private ITable table;
- private List<Player> players;
+ private ArrayList<Player> players;
private int activePlayer;
private StoneHeap gameHeap;
private IPlayer lastPlayer;
diff --git a/src/jrummikub/model/Score.java b/src/jrummikub/model/Score.java
index 7020edc..ad530f6 100644
--- a/src/jrummikub/model/Score.java
+++ b/src/jrummikub/model/Score.java
@@ -1,25 +1,29 @@
package jrummikub.model;
+import java.io.Serializable;
+import java.util.ArrayList;
import java.util.List;
/**
* Score of a single round
*/
-public class Score {
- private List<Boolean> winners;
- private List<Integer> points;
+public class Score implements Serializable {
+ private static final long serialVersionUID = 2200041688506962025L;
+
+ private ArrayList<Boolean> winners;
+ private ArrayList<Integer> points;
/**
* Create a new round score
*
* @param winners
- * set for each player among the winners
+ * set for each player among the winners
* @param points
- * points of each player
+ * points of each player
*/
public Score(List<Boolean> winners, List<Integer> points) {
- this.winners = winners;
- this.points = points;
+ this.winners = new ArrayList<Boolean>(winners);
+ this.points = new ArrayList<Integer>(points);
}
/**
diff --git a/src/jrummikub/model/Stone.java b/src/jrummikub/model/Stone.java
index 800425e..a6d62c4 100644
--- a/src/jrummikub/model/Stone.java
+++ b/src/jrummikub/model/Stone.java
@@ -1,18 +1,21 @@
package jrummikub.model;
+import java.io.Serializable;
+
/** Basic Rummikub Stone */
-public class Stone implements Sizeable {
+public class Stone implements Sizeable, Serializable {
+ private static final long serialVersionUID = 7032593080727812277L;
+
private int value;
private StoneColor color;
private final boolean joker;
/**
- * Creates a joker of the given color. The color is only used for
- * displaying.
+ * Creates a joker of the given color. The color is only used for displaying.
*
* @param color
- * joker color
+ * joker color
*/
public Stone(StoneColor color) {
this.value = 0;
@@ -24,9 +27,9 @@ public class Stone implements Sizeable {
* Creates a normal stone of a given color and value
*
* @param value
- * stone value
+ * stone value
* @param color
- * stone color
+ * stone color
*/
public Stone(int value, StoneColor color) {
this.value = value;
@@ -73,10 +76,10 @@ public class Stone implements Sizeable {
@Override
public String toString() {
- if (joker) {
- return "Stone[joker,color=" + color + "]";
- } else {
- return "Stone[value=" + value + ",color=" + color + "]";
- }
+ if (joker) {
+ return "Stone[joker,color=" + color + "]";
+ } else {
+ return "Stone[value=" + value + ",color=" + color + "]";
+ }
}
}
diff --git a/src/jrummikub/model/StoneHeap.java b/src/jrummikub/model/StoneHeap.java
index b3c5fbe..d49bede 100644
--- a/src/jrummikub/model/StoneHeap.java
+++ b/src/jrummikub/model/StoneHeap.java
@@ -1,5 +1,6 @@
package jrummikub.model;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -11,15 +12,17 @@ import java.util.Random;
* players to draw one or more random Stones.
*/
-public class StoneHeap {
- List<Stone> heap;
+public class StoneHeap implements Serializable {
+ private static final long serialVersionUID = -5247740086907775125L;
+
+ ArrayList<Stone> heap;
private Random generator = new Random();
/**
* Creates 106 Stones according to standard rules
*
* @param gameSettings
- * (for number of sets/jokers, colors etc.)
+ * (for number of sets/jokers, colors etc.)
* */
public StoneHeap(GameSettings gameSettings) {
heap = new ArrayList<Stone>();
@@ -69,7 +72,7 @@ public class StoneHeap {
* Removes several {@link Stone}s from the heap and returns them
*
* @param number
- * number of requested Stones
+ * number of requested Stones
* @return list of drawn stones
*/
public List<Stone> drawStones(int number) {
@@ -94,7 +97,7 @@ public class StoneHeap {
* Put stones back on the heap
*
* @param stones
- * collection of stones to put back
+ * collection of stones to put back
*/
public void putBack(Collection<Stone> stones) {
heap.addAll(stones);
diff --git a/src/jrummikub/model/StoneTray.java b/src/jrummikub/model/StoneTray.java
index 1f59afa..b0a824d 100644
--- a/src/jrummikub/model/StoneTray.java
+++ b/src/jrummikub/model/StoneTray.java
@@ -13,6 +13,7 @@ import jrummikub.util.Pair;
* @param <E>
* Type of positioned objects (must implement Sizeable)
*/
+@SuppressWarnings("serial")
public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
protected HashMap<E, Pair<E, Position>> objects = new HashMap<E, Pair<E, Position>>();
diff --git a/src/jrummikub/model/Table.java b/src/jrummikub/model/Table.java
index 1ac31a9..1f07f97 100644
--- a/src/jrummikub/model/Table.java
+++ b/src/jrummikub/model/Table.java
@@ -5,6 +5,8 @@ import jrummikub.util.Pair;
/** Class administering the {@link Stone}s on the game-Table */
public class Table extends StoneTray<StoneSet> implements ITable {
+ private static final long serialVersionUID = 2433091681355019937L;
+
private GameSettings gameSettings;
private static class StoneInfo {
@@ -23,7 +25,7 @@ public class Table extends StoneTray<StoneSet> implements ITable {
* Constructor for a table
*
* @param settings
- * GameSettings
+ * GameSettings
*/
public Table(GameSettings settings) {
gameSettings = settings;
@@ -33,7 +35,7 @@ public class Table extends StoneTray<StoneSet> implements ITable {
* Removes {@link Stone} from the Table
*
* @param stone
- * stone to pick up
+ * stone to pick up
*/
@Override
public void pickUpStone(Stone stone) {
@@ -84,8 +86,7 @@ public class Table extends StoneTray<StoneSet> implements ITable {
pickUp(set);
Pair<StoneSet, StoneSet> firstSplit = set.splitAt(stonePosition);
- Pair<StoneSet, StoneSet> secondSplit = firstSplit.getSecond()
- .splitAt(1);
+ Pair<StoneSet, StoneSet> secondSplit = firstSplit.getSecond().splitAt(1);
StoneSet leftSet = firstSplit.getFirst();
StoneSet rightSet = secondSplit.getSecond();
@@ -93,8 +94,8 @@ public class Table extends StoneTray<StoneSet> implements ITable {
if (set.classify(gameSettings).getFirst() == StoneSet.Type.RUN) {
Position leftPosition, rightPosition;
leftPosition = setPosition;
- rightPosition = new Position(
- setPosition.getX() + stonePosition + 1, setPosition.getY());
+ rightPosition = new Position(setPosition.getX() + stonePosition + 1,
+ setPosition.getY());
drop(leftSet, leftPosition);
drop(rightSet, rightPosition);
diff --git a/src/jrummikub/util/Pair.java b/src/jrummikub/util/Pair.java
index 91fcbed..80b9ea0 100644
--- a/src/jrummikub/util/Pair.java
+++ b/src/jrummikub/util/Pair.java
@@ -1,14 +1,18 @@
package jrummikub.util;
+import java.io.Serializable;
+
/**
* A pair of objects
*
* @param <T1>
- * Type of first component
+ * Type of first component
* @param <T2>
- * Type of second component
+ * Type of second component
*/
-public class Pair<T1, T2> {
+public class Pair<T1, T2> implements Serializable {
+ private static final long serialVersionUID = 9197464436906172698L;
+
private final T1 first;
private final T2 second;
@@ -16,9 +20,9 @@ public class Pair<T1, T2> {
* Create a new pair from two values
*
* @param first
- * the first pair component
+ * the first pair component
* @param second
- * the second pair component
+ * the second pair component
*/
public Pair(T1 first, T2 second) {
this.first = first;