net.sf.freecol.server.control
Class ChangeSet

java.lang.Object
  extended by net.sf.freecol.server.control.ChangeSet

public class ChangeSet
extends java.lang.Object

Changes to be sent to the client.


Nested Class Summary
private static class ChangeSet.AttackChange
          Encapsulate an attack.
private static class ChangeSet.AttributeChange
          Encapsulate an attribute change.
private static class ChangeSet.Change
           
static class ChangeSet.ChangePriority
           
private static class ChangeSet.MessageChange
          Encapsulate a Message.
private static class ChangeSet.MoveChange
          Encapsulate a move.
private static class ChangeSet.ObjectChange
          Encapsulate a FreeColGameObject update.
private static class ChangeSet.OwnedChange
          Encapsulate an owned object change.
private static class ChangeSet.PartialObjectChange
          Encapsulate a partial update of a FreeColGameObject.
private static class ChangeSet.RemoveChange
           
static class ChangeSet.See
           
private static class ChangeSet.SpyChange
           
private static class ChangeSet.StanceChange
          Encapsulate a stance change.
private static class ChangeSet.TrivialChange
          Encapsulate trivial element, which will only have attributes apart from its name.
 
Field Summary
private static java.util.Comparator<ChangeSet.Change> changeComparator
           
private  java.util.ArrayList<ChangeSet.Change> changes
           
 
Constructor Summary
ChangeSet()
          Simple constructor.
ChangeSet(ChangeSet other)
          Copying constructor.
 
Method Summary
 ChangeSet add(ChangeSet.See see, ChangeSet.ChangePriority cp, DOMMessage message)
          Helper function to add a Message to a ChangeSet.
 ChangeSet add(ChangeSet.See see, FreeColGameObject... objects)
          Helper function to add updates for multiple objects to a ChangeSet.
 ChangeSet add(ChangeSet.See see, java.util.List<FreeColGameObject> objects)
          Helper function to add updates for multiple objects to a ChangeSet.
 ChangeSet addAttack(ChangeSet.See see, Unit unit, Unit defender, boolean success)
          Helper function to add an attack to a ChangeSet.
 ChangeSet addAttribute(ChangeSet.See see, java.lang.String key, java.lang.String value)
          Helper function to add an attribute setting to a ChangeSet.
 ChangeSet addDead(ServerPlayer serverPlayer)
          Helper function to add a dead player event to a ChangeSet.
 ChangeSet addDisappear(ServerPlayer owner, Tile tile, FreeColGameObject fcgo)
          Helper function to add a removal for an object that disappears (that is, moves where it can not be seen) to a ChangeSet.
 ChangeSet addDispose(ChangeSet.See see, Location loc, FreeColGameObject obj)
          Helper function to add a removal for a disposal list to a ChangeSet.
 ChangeSet addFather(ServerPlayer serverPlayer, FoundingFather father)
          Helper function to add a founding father addition event to a ChangeSet.
 ChangeSet addGlobalHistory(Game game, HistoryEvent history)
          Helper function to add a global history event to a ChangeSet.
 ChangeSet addHistory(ServerPlayer serverPlayer, HistoryEvent history)
          Helper function to add a history event to a ChangeSet.
 ChangeSet addMessage(ChangeSet.See see, ModelMessage message)
          Helper function to add a message to a ChangeSet.
 ChangeSet addMove(ChangeSet.See see, Unit unit, Location loc, Tile tile)
          Helper function to add a move to a ChangeSet.
 ChangeSet addPartial(ChangeSet.See see, FreeColGameObject fcgo, java.lang.String... fields)
          Helper function to add a partial update change for an object to a ChangeSet.
 ChangeSet addRegion(ServerPlayer serverPlayer, Region region, java.lang.String name)
          Helper function to add a region discovery to a ChangeSet.
 ChangeSet addSale(ServerPlayer serverPlayer, Settlement settlement, GoodsType type, int price)
          Helper function to add a sale change to a ChangeSet.
 ChangeSet addSpy(ChangeSet.See see, Settlement settlement)
          Helper function to add a spying change to a ChangeSet.
 ChangeSet addStance(ChangeSet.See see, Player first, Player.Stance stance, Player second)
          Helper function to add a stance change to a ChangeSet.
 ChangeSet addTradeRoute(ServerPlayer serverPlayer, TradeRoute tradeRoute)
          Helper function to add a new trade route change to a ChangeSet.
 ChangeSet addTrivial(ChangeSet.See see, java.lang.String name, ChangeSet.ChangePriority cp, java.lang.String... attributes)
          Helper function to add a trivial element to a ChangeSet.
 org.w3c.dom.Element build(ServerPlayer serverPlayer)
          Build a generalized update.
private static java.util.List<org.w3c.dom.Element> collapseElementList(java.util.List<org.w3c.dom.Element> elements)
          Collapse adjacent elements in a list with the same tag.
private static void collapseElements(org.w3c.dom.Element head, org.w3c.dom.Element tail)
          Collapse one element into another.
private static boolean collapseOK(org.w3c.dom.Element e1, org.w3c.dom.Element e2)
          Can two elements be collapsed? They need to have the same name and attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

changes

private java.util.ArrayList<ChangeSet.Change> changes

changeComparator

private static java.util.Comparator<ChangeSet.Change> changeComparator
Constructor Detail

ChangeSet

public ChangeSet()
Simple constructor.


ChangeSet

public ChangeSet(ChangeSet other)
Copying constructor.

Parameters:
other - The other ChangeSet to copy.
Method Detail

add

public ChangeSet add(ChangeSet.See see,
                     FreeColGameObject... objects)
Helper function to add updates for multiple objects to a ChangeSet.

Parameters:
see - The visibility of this change.
objects - The FreeColGameObjects that changed.
Returns:
The updated ChangeSet.

add

public ChangeSet add(ChangeSet.See see,
                     java.util.List<FreeColGameObject> objects)
Helper function to add updates for multiple objects to a ChangeSet.

Parameters:
see - The visibility of this change.
objects - The FreeColGameObjects that changed.
Returns:
The updated ChangeSet.

add

public ChangeSet add(ChangeSet.See see,
                     ChangeSet.ChangePriority cp,
                     DOMMessage message)
Helper function to add a Message to a ChangeSet.

Parameters:
see - The visibility of this change.
cp - The priority of this change.
message - The Message to add.
Returns:
The updated ChangeSet.

addAttack

public ChangeSet addAttack(ChangeSet.See see,
                           Unit unit,
                           Unit defender,
                           boolean success)
Helper function to add an attack to a ChangeSet.

Parameters:
see - The visibility of this change.
unit - The Unit that is attacking.
defender - The Unit that is defending.
success - Did the attack succeed?
Returns:
The updated ChangeSet.

addAttribute

public ChangeSet addAttribute(ChangeSet.See see,
                              java.lang.String key,
                              java.lang.String value)
Helper function to add an attribute setting to a ChangeSet.

Parameters:
see - The visibility of this change.
key - A key String.
value - The corresponding value as a String.
Returns:
The updated ChangeSet.

addDead

public ChangeSet addDead(ServerPlayer serverPlayer)
Helper function to add a dead player event to a ChangeSet. Deaths are public knowledge.

Parameters:
serverPlayer - The ServerPlayer that died.
Returns:
The updated ChangeSet.

addDispose

public ChangeSet addDispose(ChangeSet.See see,
                            Location loc,
                            FreeColGameObject obj)
Helper function to add a removal for a disposal list to a ChangeSet.

Parameters:
see - The visibility of this change.
loc - The Location where the object was.
obj - The FreeColGameObject to remove.
Returns:
The updated ChangeSet.

addDisappear

public ChangeSet addDisappear(ServerPlayer owner,
                              Tile tile,
                              FreeColGameObject fcgo)
Helper function to add a removal for an object that disappears (that is, moves where it can not be seen) to a ChangeSet.

Parameters:
owner - The ServerPlayer that owns this object.
tile - The Tile where the object was.
fcgo - The FreeColGameObject that disappears.
Returns:
The updated ChangeSet.

addFather

public ChangeSet addFather(ServerPlayer serverPlayer,
                           FoundingFather father)
Helper function to add a founding father addition event to a ChangeSet. Also adds the father to the owner.

Parameters:
serverPlayer - The ServerPlayer adding the father.
father - The FoundingFather to add.
Returns:
The updated ChangeSet.

addGlobalHistory

public ChangeSet addGlobalHistory(Game game,
                                  HistoryEvent history)
Helper function to add a global history event to a ChangeSet. Also adds the history to all the European players.

Parameters:
game - The Game to find players in.
history - The HistoryEvent to add.
Returns:
The updated ChangeSet.

addHistory

public ChangeSet addHistory(ServerPlayer serverPlayer,
                            HistoryEvent history)
Helper function to add a history event to a ChangeSet. Also adds the history to the owner.

Parameters:
serverPlayer - The ServerPlayer making history.
history - The HistoryEvent to add.
Returns:
The updated ChangeSet.

addMessage

public ChangeSet addMessage(ChangeSet.See see,
                            ModelMessage message)
Helper function to add a message to a ChangeSet.

Parameters:
see - The visibility of this change.
message - The ModelMessage to add.
Returns:
The updated ChangeSet.

addMove

public ChangeSet addMove(ChangeSet.See see,
                         Unit unit,
                         Location loc,
                         Tile tile)
Helper function to add a move to a ChangeSet.

Parameters:
see - The visibility of this change.
unit - The Unit that is moving.
loc - The location from which the unit is moving.
tile - The Tile to which the unit is moving.
Returns:
The updated ChangeSet.

addPartial

public ChangeSet addPartial(ChangeSet.See see,
                            FreeColGameObject fcgo,
                            java.lang.String... fields)
Helper function to add a partial update change for an object to a ChangeSet.

Parameters:
see - The visibility of this change.
fcgo - The FreeColGameObject to update.
fields - The fields to update.
Returns:
The updated ChangeSet.

addRegion

public ChangeSet addRegion(ServerPlayer serverPlayer,
                           Region region,
                           java.lang.String name)
Helper function to add a region discovery to a ChangeSet. Also adds the history to all Europeans.

Parameters:
serverPlayer - The ServerPlayer discovering the region.
region - The Region to discover.
name - The name of the region.
Returns:
The updated ChangeSet.

addSale

public ChangeSet addSale(ServerPlayer serverPlayer,
                         Settlement settlement,
                         GoodsType type,
                         int price)
Helper function to add a sale change to a ChangeSet.

Parameters:
serverPlayer - The ServerPlayer making the sale.
settlement - The Settlement that is buying.
type - The GoodsType bought.
price - The per unit price.
Returns:
The updated ChangeSet.

addSpy

public ChangeSet addSpy(ChangeSet.See see,
                        Settlement settlement)
Helper function to add a spying change to a ChangeSet.

Parameters:
see - The visibility of this change.
settlement - The Settlement to spy on.
Returns:
The updated ChangeSet.

addStance

public ChangeSet addStance(ChangeSet.See see,
                           Player first,
                           Player.Stance stance,
                           Player second)
Helper function to add a stance change to a ChangeSet.

Parameters:
see - The visibility of this change.
first - The Player changing stance.
stance - The Stance to change to.
second - The Player wrt with to change.
Returns:
The updated ChangeSet.

addTradeRoute

public ChangeSet addTradeRoute(ServerPlayer serverPlayer,
                               TradeRoute tradeRoute)
Helper function to add a new trade route change to a ChangeSet. Also adds the trade route to the player.

Parameters:
serverPlayer - The ServerPlayer adding the route.
tradeRoute - The new TradeRoute.
Returns:
The updated ChangeSet.

addTrivial

public ChangeSet addTrivial(ChangeSet.See see,
                            java.lang.String name,
                            ChangeSet.ChangePriority cp,
                            java.lang.String... attributes)
Helper function to add a trivial element to a ChangeSet.

Parameters:
see - The visibility of this change.
name - The name of the element.
cp - The ChangePriority for this change.
attributes - Attributes to add to this trivial change.
Returns:
The updated ChangeSet.

collapseElements

private static void collapseElements(org.w3c.dom.Element head,
                                     org.w3c.dom.Element tail)
Collapse one element into another.

Parameters:
head - The Element to collapse into.
tail - The Element to extract nodes from.

collapseOK

private static boolean collapseOK(org.w3c.dom.Element e1,
                                  org.w3c.dom.Element e2)
Can two elements be collapsed? They need to have the same name and attributes.

Parameters:
e1 - The first Element.
e2 - The second Element.
Returns:
True if they can be collapsed.

collapseElementList

private static java.util.List<org.w3c.dom.Element> collapseElementList(java.util.List<org.w3c.dom.Element> elements)
Collapse adjacent elements in a list with the same tag.

Parameters:
elements - The list of Elements to consider.
Returns:
A collapsed list of elements.

build

public org.w3c.dom.Element build(ServerPlayer serverPlayer)
Build a generalized update. Beware that removing an object does not necessarily update its tile correctly on the client side--- if a tile update is needed the tile should be supplied in the objects list.

Parameters:
serverPlayer - The ServerPlayer to send the update to.
Returns:
An element encapsulating an update of the objects to consider, or null if there is nothing to report.