games.strategy.engine.data
Class UnitCollection

java.lang.Object
  extended by games.strategy.engine.data.GameDataComponent
      extended by games.strategy.engine.data.UnitCollection
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<Unit>

public class UnitCollection
extends GameDataComponent
implements java.lang.Iterable<Unit>

Version:
1.0 A collection of units.
Author:
Sean Bridges
See Also:
Serialized Form

Constructor Summary
UnitCollection(NamedUnitHolder holder, GameData data)
          Creates new UnitCollection
 
Method Summary
 boolean allMatch(Match<Unit> matcher)
           
 boolean containsAll(java.util.Collection<Unit> units)
           
 int countMatches(Match<Unit> predicate)
           
 NamedUnitHolder getHolder()
           
 java.util.List<Unit> getMatches(Match<Unit> predicate)
           
 java.util.Set<PlayerID> getPlayersWithUnits()
           
 IntegerMap<PlayerID> getPlayerUnitCounts()
           
 int getUnitCount()
           
 int getUnitCount(PlayerID owner)
           
 int getUnitCount(UnitType type)
           
 int getUnitCount(UnitType type, PlayerID owner)
           
 java.util.Collection<Unit> getUnits()
           
 java.util.Collection<Unit> getUnits(IntegerMap<UnitType> types)
          Passed a map of UnitType -> int return a collection of units of each type up to max
 java.util.Collection<Unit> getUnits(UnitType type, int count)
          returns up to int units of a given type currently in the collection.
 IntegerMap<UnitType> getUnitsByType()
          Returns a map of UnitType -> int.
 IntegerMap<UnitType> getUnitsByType(PlayerID id)
          Returns a map of UnitType -> int.
 boolean hasUnitsFromMultiplePlayers()
           
 boolean isEmpty()
           
 java.util.Iterator<Unit> iterator()
           
 int size()
           
 boolean someMatch(Match<Unit> matcher)
           
 java.lang.String toString()
           
 
Methods inherited from class games.strategy.engine.data.GameDataComponent
getData, readInternal, writeInternal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UnitCollection

public UnitCollection(NamedUnitHolder holder,
                      GameData data)
Creates new UnitCollection

Method Detail

getUnitCount

public int getUnitCount()

getUnitCount

public int getUnitCount(UnitType type)

getUnitCount

public int getUnitCount(UnitType type,
                        PlayerID owner)

getUnitCount

public int getUnitCount(PlayerID owner)

containsAll

public boolean containsAll(java.util.Collection<Unit> units)

getUnits

public java.util.Collection<Unit> getUnits(UnitType type,
                                           int count)
returns up to int units of a given type currently in the collection.


getUnitsByType

public IntegerMap<UnitType> getUnitsByType()
Returns a map of UnitType -> int.


getUnitsByType

public IntegerMap<UnitType> getUnitsByType(PlayerID id)
Returns a map of UnitType -> int. Only returns units for the specified player


getUnits

public java.util.Collection<Unit> getUnits(IntegerMap<UnitType> types)
Passed a map of UnitType -> int return a collection of units of each type up to max


size

public int size()

isEmpty

public boolean isEmpty()

getUnits

public java.util.Collection<Unit> getUnits()

getPlayersWithUnits

public java.util.Set<PlayerID> getPlayersWithUnits()
Returns:
a Set of all players who have units in this collection.

getPlayerUnitCounts

public IntegerMap<PlayerID> getPlayerUnitCounts()
Returns:
the count of units each player has in this collection.

hasUnitsFromMultiplePlayers

public boolean hasUnitsFromMultiplePlayers()

getHolder

public NamedUnitHolder getHolder()

allMatch

public boolean allMatch(Match<Unit> matcher)

someMatch

public boolean someMatch(Match<Unit> matcher)

countMatches

public int countMatches(Match<Unit> predicate)

getMatches

public java.util.List<Unit> getMatches(Match<Unit> predicate)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

iterator

public java.util.Iterator<Unit> iterator()
Specified by:
iterator in interface java.lang.Iterable<Unit>