net.sf.freecol.common.model
Class Player.UnitIterator

java.lang.Object
  extended by net.sf.freecol.common.model.Player.UnitIterator
All Implemented Interfaces:
java.util.Iterator<Unit>
Enclosing class:
Player

public class Player.UnitIterator
extends java.lang.Object
implements java.util.Iterator<Unit>

An Iterator of Units that can be made active.


Field Summary
private  Player owner
           
private  Player.UnitPredicate predicate
           
private  java.util.List<Unit> units
           
private  java.util.Comparator<Unit> xyComparator
          A comparator to compare units by position, top to bottom, left to right.
 
Constructor Summary
Player.UnitIterator(Player owner, Player.UnitPredicate predicate)
          Creates a new UnitIterator.
 
Method Summary
 boolean hasNext()
          Check if there is any more valid units.
 Unit next()
          Get the next valid unit.
 void remove()
          Removes from the underlying collection the last element returned by the iterator (optional operation).
 void reset()
          Reset the internal units list, initially only with units that satisfy the predicate.
 boolean setNext(Unit unit)
          Set the next valid unit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

owner

private Player owner

predicate

private Player.UnitPredicate predicate

units

private java.util.List<Unit> units

xyComparator

private final java.util.Comparator<Unit> xyComparator
A comparator to compare units by position, top to bottom, left to right.

Constructor Detail

Player.UnitIterator

public Player.UnitIterator(Player owner,
                           Player.UnitPredicate predicate)
Creates a new UnitIterator.

Parameters:
owner - The Player that needs an iterator of it's units.
predicate - An object for deciding whether a Unit should be included in the Iterator or not.
Method Detail

reset

public void reset()
Reset the internal units list, initially only with units that satisfy the predicate.


hasNext

public boolean hasNext()
Check if there is any more valid units. If there are, it will be at the head of the internal units list.

Specified by:
hasNext in interface java.util.Iterator<Unit>
Returns:
True if there are any valid units left.

next

public Unit next()
Get the next valid unit. Always call hasNext to enforce validity.

Specified by:
next in interface java.util.Iterator<Unit>
Returns:
The next valid unit, or null if none.

setNext

public boolean setNext(Unit unit)
Set the next valid unit.

Parameters:
unit - The Unit to put at the front of the list.
Returns:
True if the operation succeeds.

remove

public void remove()
Removes from the underlying collection the last element returned by the iterator (optional operation).

Specified by:
remove in interface java.util.Iterator<Unit>
Throws:
java.lang.UnsupportedOperationException - no matter what.