|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjfreerails.world.top.WorldImpl
jfreerails.world.top.WorldDiffs
public class WorldDiffs
An implemenation of World that only stores differences relative to an
underlying world object. Below is some stylised code showing what this class
does. The key object could be a location on the map, a
position in a list etc.
The advantages of using an instance of this class instead of a copy of the
world object are:
HashMap underlyingWorldObject;
HashMap differences;
public void put(Object key, Object value) {
if (underlyingWorldObject.get(key).equals(value)) {
if (differences.containsKey(key)) {
differences.remove(key);
}
} else {
differences.put(key, value);
}
}
public Object get(Object key) {
if (differences.containsKey(key)) {
return differences.get(key);
} else {
return underlyingWorldObject.get(key);
}
}
| Nested Class Summary | |
|---|---|
static class |
WorldDiffs.LISTID
|
| Nested classes/interfaces inherited from class jfreerails.world.top.WorldImpl |
|---|
WorldImpl.ActivityAndTime |
| Field Summary | |
|---|---|
private java.util.SortedMap<ListKey,java.lang.Object> |
listDiff
|
private java.util.HashMap<ImPoint,java.lang.Object> |
mapDiff
Stores the differences on the map, ImPoint are used as keys. |
private static long |
serialVersionUID
|
private WorldImpl |
underlying
|
| Fields inherited from class jfreerails.world.top.WorldImpl |
|---|
activityLists, bankAccounts, currentBalance, items, lists, map, players, sharedLists, time |
| Constructor Summary | |
|---|---|
WorldDiffs(ReadOnlyWorld row)
|
|
| Method Summary | |
|---|---|
java.lang.Object |
getDiff(ListKey key)
|
java.util.Iterator<ListKey> |
getListDiffs()
|
java.util.Iterator<ImPoint> |
getMapDiffs()
The iterator returns instances of java.awt.Point that store the coordinates of tiles that are different to the underlying world object. |
int |
getMapHeight()
Returns the height of the map in tiles. |
int |
getMapWidth()
Returns the width of the map in tiles. |
FreerailsSerializable |
getTile(int x,
int y)
Returns the tile at the specified position on the map. |
ReadOnlyWorld |
getUnderlying()
|
boolean |
isDifferent()
|
int |
listDiffs()
Used by unit tests. |
int |
numberOfMapDifferences()
Used by unit tests. |
void |
reset()
After this method returns, all differences are cleared and calls to methods on this object should produce the same results as calls the the corresponding methods on the underlying world object. |
void |
setTile(int x,
int y,
FreerailsSerializable tile)
Replaces the tile at the specified position on the map with the specified tile. |
| Methods inherited from class jfreerails.world.top.WorldImpl |
|---|
add, add, add, addActiveEntity, addPlayer, addTransaction, boundsContain, boundsContain, boundsContain, currentTime, defensiveCopy, equals, get, get, get, getActivities, getCurrentBalance, getID, getNumberOfActiveEntities, getNumberOfPlayers, getNumberOfTransactions, getPlayer, getTransaction, getTransactionTimeStamp, hashCode, isPlayer, removeLast, removeLast, removeLastActiveEntity, removeLastActivity, removeLastPlayer, removeLastTransaction, set, set, set, setTime, setupItems, setupMap, size, size, size |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final long serialVersionUID
private final java.util.SortedMap<ListKey,java.lang.Object> listDiff
private final java.util.HashMap<ImPoint,java.lang.Object> mapDiff
private final WorldImpl underlying
| Constructor Detail |
|---|
public WorldDiffs(ReadOnlyWorld row)
| Method Detail |
|---|
public java.util.Iterator<ImPoint> getMapDiffs()
public java.util.Iterator<ListKey> getListDiffs()
public java.lang.Object getDiff(ListKey key)
public int getMapHeight()
ReadOnlyWorld
getMapHeight in interface ReadOnlyWorldgetMapHeight in class WorldImplpublic int getMapWidth()
ReadOnlyWorld
getMapWidth in interface ReadOnlyWorldgetMapWidth in class WorldImpl
public FreerailsSerializable getTile(int x,
int y)
ReadOnlyWorld
getTile in interface ReadOnlyWorldgetTile in class WorldImplpublic int numberOfMapDifferences()
public int listDiffs()
public void reset()
public void setTile(int x,
int y,
FreerailsSerializable tile)
World
setTile in interface WorldsetTile in class WorldImplpublic boolean isDifferent()
public ReadOnlyWorld getUnderlying()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||