util.grid
Class Placeable

java.lang.Object
  extended by util.grid.Placeable
All Implemented Interfaces:
Serializable, Iterable<Point>

public class Placeable
extends Object
implements Iterable<Point>, Serializable

Lightweight representation of a figure placeable in Cartesian coordinates. Implementations can occupy multiple locations by providing an immutable pattern of occupancy around the pivot.

Version:
January 9, 2008
See Also:
Serialized Form

Field Summary
static long serialVersionUID
           
 
Constructor Summary
Placeable(Placeable placeable)
          Constructs a deep duplicate of a placeable.
Placeable(Point anchor, Orientation facedOrientation)
          Constructor for a placeable that occupies a single location.
 
Method Summary
 boolean contains(Point loc)
          Returns if this contains a given location.
 HashSet<Point> getOccupied()
          Provides positions currently occupied.
 Orientation getOrientation()
          Provides the direction being faced.
 HashSet<Point> getPattern(Orientation ori)
          Provides the pattern used to construct occupied positions.
 Point getPivot()
          Provides placeable's central position.
 Iterator<Point> iterator()
          Provides an iterator over occupied locations with an unsupported removal method.
 void setOrientation(Orientation ori)
          Sets the direction being faced.
 void setPivot(Point loc)
          Sets the placeable's central position.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

Placeable

public Placeable(Point anchor,
                 Orientation facedOrientation)
Constructor for a placeable that occupies a single location. This is valid for all orientations.

Parameters:
anchor - initial occupied location
facedOrientation - initial direction being faced

Placeable

public Placeable(Placeable placeable)
Constructs a deep duplicate of a placeable.

Parameters:
placeable - placeable from which to duplicate attributes
Method Detail

getPivot

public Point getPivot()
Provides placeable's central position.

Returns:
central position of the figure

setPivot

public void setPivot(Point loc)
Sets the placeable's central position.

Parameters:
loc - new central position of the figure

getOrientation

public Orientation getOrientation()
Provides the direction being faced.

Returns:
orientation being faced

setOrientation

public void setOrientation(Orientation ori)
Sets the direction being faced.

Parameters:
ori - direction being faced
Throws:
IllegalArgumentException - if no pattern is available for the orientation

getPattern

public HashSet<Point> getPattern(Orientation ori)
Provides the pattern used to construct occupied positions.

Parameters:
ori - orientation of pattern
Returns:
pattern used with the given orientation, null if none's defined

getOccupied

public HashSet<Point> getOccupied()
Provides positions currently occupied. This is a O(n) operation based on the number of occupied positions.

Returns:
occupied locations

contains

public boolean contains(Point loc)
Returns if this contains a given location. This is a constant time operation.

Parameters:
loc - location to be checked
Returns:
true if this contains the given location, false otherwise

iterator

public Iterator<Point> iterator()
Provides an iterator over occupied locations with an unsupported removal method. This is a constant time operation.

Specified by:
iterator in interface Iterable<Point>
Returns:
iterator of locations