dd.sim
Class MapCell

java.lang.Object
  extended bydd.sim.SimObject
      extended bydd.sim.MapCell
All Implemented Interfaces:
java.io.Serializable

public class MapCell
extends SimObject

A single geographic location in a map. The simulation map is broken down into multiple hexagonal areas called cells. A MapCell has a location within a map and stores attributes related to its location. Attributes may be location specific or may be organized into layers.

Because of the tight connection between Maps and MapCells, a MapCell must have an associated map in order to work properly.

Author:
Eric Scharff
See Also:
Serialized Form

Field Summary
 
Fields inherited from class dd.sim.SimObject
attributes
 
Constructor Summary
MapCell(Map map, int row, int column)
          Create a new map cell at the current location.
 
Method Summary
 void addLayer(Layer layer)
          Add a layer to the current cell.
 java.util.List attributesInRange(Layer layer, float minValue, float maxValue)
          Finds all attributes on a layer between a minimum and maximum value.
 double cDistanceTo(MapCell anotherCell)
          Computes the cellwise distance between this and another cell.
 java.util.Collection cellsWithin(int distance)
          Returns all cells within a specified distance from this one.
 double eDistanceTo(MapCell anotherCell)
          Computes the Euclidean distance between this and another cell.
 float getAttribute(java.lang.String attributeName, Layer layer)
          Queries this cell for an attribute associated with a specified layer.
 float getAttribute(java.lang.String attributeName, Layer layer, float defaultValue)
          Queries this cell for an attribute associated with a specified layer.
 int getColumn()
          Get the cell's column in Map coordinates.
 java.util.Map getLayerAttributes(Layer layer)
          Returns all of the attributes that are associated with a layer.
 java.util.Collection getLayers()
          Returns all the layers associated with this cell.
 Map getMap()
          Returns the map associated with this cell.
 java.lang.String getName()
          Get the cell's name: its Map coordinates as a string of the form "<row, col>".
 java.util.Collection getNeighbors()
          Returns all of the cells directly adjacent to this cell.
 java.lang.Object getObjectAttribute(java.lang.String attributeName, Layer layer)
          Queries this cell for an attribute associated with a specified layer.
 int getRow()
          Get the cell's row in Map coordinates.
 double getX()
          Get the cell's geographic X coordinate.
 double getY()
          Get the cell's geographic Y coordinate.
 boolean hasAttribute(java.lang.String attributeName, Layer layer)
          Queries whether a cell has an attribute on this layer.
 boolean isSet(java.lang.String attributeName, Layer layer)
          Indicates whether this cell has an attribute set (with non-zero value) with the specified name on the specified layer.
 MapCell north()
          Returns the cell north of this cell.
 MapCell northEast()
          Returns the cell northeast of this cell.
 MapCell northWest()
          Returns the cell northwest of this cell.
 java.lang.String printName()
           
 void setAttribute(java.lang.String attributeName, Layer layer, float value)
          Sets the attribute associated with a specified layer.
 void setAttribute(java.lang.String attributeName, Layer layer, java.lang.Object value)
          Sets the attribute associated with a specified layer.
 void setColumn(int column)
          Set the cell's column in Map coordinates.
 void setMap(Map map)
          Sets the map associated with this cell.
 void setRow(int row)
          Set the cell's row in Map coordinates.
 void setX(double x)
          Set the cell's geographic X coordinate.
 void setY(double y)
          Set the cell's geographic Y coordinate.
 MapCell south()
          Returns the cell south of this cell.
 MapCell southEast()
          Returns the cell southeast of this cell.
 MapCell southWest()
          Returns the cell southwest of this cell.
 java.lang.String toString()
          Provide a textual description of the map cell.
 
Methods inherited from class dd.sim.SimObject
addPropertyChangeListener, addPropertyChangeListener, debug, duplicate, error, fatal, filter, filter, firePropertyChange, getAttribute, getAttribute, getAttributes, getGlobalAttribute, getObjectAttribute, getObjectAttribute, incrementAttribute, incrementAttribute, isSet, log, out, readFromXML, readFromXML, removeAttribute, removePropertyChangeListener, setAttribute, setAttribute, setAttribute, setAttributes, setGlobalAttribute, warning, writeText, writeXML, writeXML
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MapCell

public MapCell(Map map,
               int row,
               int column)
Create a new map cell at the current location. This associates a cell with the Map provided at the row and column (in the map's internal coordinate system)

Parameters:
map - Map in which this cell exists
row - row of the cell, in Map coordinates
column - column of the cell, in Map coordinates
Method Detail

getName

public java.lang.String getName()
Get the cell's name: its Map coordinates as a string of the form "<row, col>".


getRow

public int getRow()
Get the cell's row in Map coordinates. Note that this is an internal representation and is typically not used directly.

Returns:
the row of the cell, in Map coordinates
See Also:
getY()

setRow

public void setRow(int row)
Set the cell's row in Map coordinates. Note that this is an internal representation and is typically not used directly.

Parameters:
row - new row of the cell, in Map coordinates
See Also:
setY(double)

getColumn

public int getColumn()
Get the cell's column in Map coordinates. Note that this is an internal representation and is typically not used directly.

Returns:
the column of the cell, in Map coordinates
See Also:
getX()

setColumn

public void setColumn(int column)
Set the cell's column in Map coordinates. Note that this is an internal representation and is typically not used directly.

Parameters:
column - new column of the cell, in Map coordinates
See Also:
setX(double)

getX

public double getX()
Get the cell's geographic X coordinate. This method is typically used to get a cell's location. It returns the cells X ("longitude" of sorts) in the virtual Cartesian coordinate system used in the Map.

Returns:
the horizontal coordinate of the center of the cell

setX

public void setX(double x)
Set the cell's geographic X coordinate. The coordinate system used is arbitrary, but currently uses a Cartesian coordinate so that X and Y values can be used to compute distances.

Parameters:
x - the horizontal coordinate of the center of the cell

getY

public double getY()
Get the cell's geographic Y coordinate. This method is typically used to get a cell's location. It returns the cells Y ("latitude" of sorts) in the virtual Cartesian coordinate system used in the Map.

Returns:
the vertical coordinate of the center of the cell

setY

public void setY(double y)
Set the cell's geographic Y coordinate. The coordinate system used is arbitrary, but currently uses a Cartesian coordinate so that X and Y values can be used to compute distances.

Parameters:
y - the vertical coordinate of the center of the cell

getMap

public Map getMap()
Returns the map associated with this cell. A map cell must be associated with one (and only one) map.

Returns:
the map in which this cell exists

setMap

public void setMap(Map map)
Sets the map associated with this cell. Note that a cell must be associated with a map or most of the cell's functionality is not useful because of the tight dependence on the Map's functionality.

Parameters:
map - the map in which this cell exists

north

public MapCell north()
Returns the cell north of this cell. This is a convenience method to access a cell's neighbor.

Returns:
the cell north of this cell, null if it does not exist.
See Also:
Map.northOf(MapCell)

south

public MapCell south()
Returns the cell south of this cell. This is a convenience method to access a cell's neighbor.

Returns:
the cell south of this cell, null if it does not exist.
See Also:
Map.southOf(MapCell)

northEast

public MapCell northEast()
Returns the cell northeast of this cell. This is a convenience method to access a cell's neighbor.

Returns:
the cell northeast of this cell, null if it does not exist.
See Also:
Map.northEastOf(MapCell)

southEast

public MapCell southEast()
Returns the cell southeast of this cell. This is a convenience method to access a cell's neighbor.

Returns:
the cell southeast of this cell, null if it does not exist.
See Also:
Map.southEastOf(MapCell)

northWest

public MapCell northWest()
Returns the cell northwest of this cell. This is a convenience method to access a cell's neighbor.

Returns:
the cell northwest of this cell, null if it does not exist.
See Also:
Map.northWestOf(MapCell)

southWest

public MapCell southWest()
Returns the cell southwest of this cell. This is a convenience method to access a cell's neighbor.

Returns:
the cell southwest of this cell, null if it does not exist.
See Also:
Map.northWestOf(MapCell)

getNeighbors

public java.util.Collection getNeighbors()
Returns all of the cells directly adjacent to this cell. Note that the cell itself is not included. Typically returns a list of 6 neighbors, but will return less on the edges of the map.

Returns:
a collection of the neighbors of this cell

eDistanceTo

public double eDistanceTo(MapCell anotherCell)
Computes the Euclidean distance between this and another cell. Note that both cells must exist in the same map in order for the result to be meaningful.

Parameters:
anotherCell - cell to which distance should be computed
Returns:
the distance between this cell and the cell specified
See Also:
Map.eDistanceBetweenCells(MapCell,MapCell)

cDistanceTo

public double cDistanceTo(MapCell anotherCell)
Computes the cellwise distance between this and another cell. Note that both cells must exist in the same map in order for the result to be meaningful.

Parameters:
anotherCell - cell to which distance should be computed
Returns:
the distance between this cell and the cell specified
See Also:
Map.cDistanceBetweenCells(MapCell,MapCell)

cellsWithin

public java.util.Collection cellsWithin(int distance)
Returns all cells within a specified distance from this one. The distance is given in Cartesian coordinates, and returns an arbitrary sized list of cells that are within the specified boundary,

Parameters:
distance - Cartesian distance threshold
Returns:
all cells that are distance or less units away from this cell.

addLayer

public void addLayer(Layer layer)
Add a layer to the current cell. Layers group related pieces of information. A layer must be added to a cell before setting information pertaining to that layer.

Parameters:
layer - layer to associate with this cell

getLayers

public java.util.Collection getLayers()
Returns all the layers associated with this cell. This method returns all layers that have been added to the cell, regardless of whether there are any attributes associated with that layer.

Returns:
a collection of Layer objects associated with this cell

getLayerAttributes

public java.util.Map getLayerAttributes(Layer layer)
Returns all of the attributes that are associated with a layer. This method returns a Map (name value pairs) for attributes on a layer associated with this cell.

Parameters:
layer - the layer of attributes to be retrieved
Returns:
a Map of attributes (name/value pairs) on this layer associated with this location.

hasAttribute

public boolean hasAttribute(java.lang.String attributeName,
                            Layer layer)
Queries whether a cell has an attribute on this layer. This is conceptually identical to getting an attribute and testing if it is null, but easier to read.

Parameters:
attributeName - name of the attribute to be queried
layer - layer with which the attribute is associated
Returns:
true if the cell has an attribute with this name on this layer, false otherwise.

getAttribute

public float getAttribute(java.lang.String attributeName,
                          Layer layer)
Queries this cell for an attribute associated with a specified layer. If this location has an attribute stored in this layer, that attribute is returned. Note that this is different than a non-layer-specific attribute. This is a convenience method for the more general-purpose getObjectAttribute method, which shares the same variables.

Parameters:
attributeName - name of the attribute to be queried
layer - layer with which the attribute is associated
Returns:
the value of that attribute in this cell on the layer specified
Throws:
java.util.NoSuchElementException - if there is no attribute with that name associated with that layer.

attributesInRange

public java.util.List attributesInRange(Layer layer,
                                        float minValue,
                                        float maxValue)
Finds all attributes on a layer between a minimum and maximum value. This method queries every attribute on a specified layer and returns all of the attributes that have a value between minValue and maxValue, inclusive.

Parameters:
layer - layer whose attributes should be queried
minValue - lower end of range
maxValue - upper end of range
Returns:
the names of all attributes with value >= minValue and <= maxValue

getAttribute

public float getAttribute(java.lang.String attributeName,
                          Layer layer,
                          float defaultValue)
Queries this cell for an attribute associated with a specified layer. If this location has an attribute stored in this layer, that attribute is returned. Note that this is different than a non-layer-specific attribute. This is a convenience method for the more general-purpose getObjectAttribute method, which shares the same variables.

Parameters:
attributeName - name of the attribute to be queried
layer - layer with which the attribute is associated
defaultValue - default if the attribute does not exist
Returns:
the value of that attribute in this cell on the layer specified, or the default value of there is no such attribute

isSet

public boolean isSet(java.lang.String attributeName,
                     Layer layer)
Indicates whether this cell has an attribute set (with non-zero value) with the specified name on the specified layer. Note that this is different than a non-layer-specific attribute.

Parameters:
attributeName - name of the attribute to be tested
layer - layer with which the attribute is associated
Returns:
true if the attribute is defined in this cell on the specified layer with a non-zero value; false otherwise

getObjectAttribute

public java.lang.Object getObjectAttribute(java.lang.String attributeName,
                                           Layer layer)
Queries this cell for an attribute associated with a specified layer. If this location has an attribute stored in this layer, that attribute is returned. Note that this is different than a non-layer-specific attribute.

Parameters:
attributeName - name of the attribute to be queried
layer - layer with which the attribute is associated
Returns:
the value of that attribute in this cell on the layer specified, null if the attribute does not exist

setAttribute

public void setAttribute(java.lang.String attributeName,
                         Layer layer,
                         float value)
Sets the attribute associated with a specified layer. This creates a new attribute (or overwrites an existing attribute) associated with the name and layer specified. This has the effect of associating a value with the current cell with the current name on the current layer. An appropriate property change event is fired when the attribute is set.

Parameters:
attributeName - name of the attribute to set
layer - layer on which the attribute should exist
value - value to which the attribute should be set
See Also:
PropertyChangeEvent

setAttribute

public void setAttribute(java.lang.String attributeName,
                         Layer layer,
                         java.lang.Object value)
Sets the attribute associated with a specified layer. This creates a new attribute (or overwrites an existing attribute) associated with the name and layer specified. This has the effect of associating a value with the current cell with the current name on the current layer. An appropriate property change event is fired when the attribute is set.

Parameters:
attributeName - name of the attribute to set
layer - layer on which the attribute should exist
value - value to which the attribute should be set
See Also:
PropertyChangeEvent

printName

public java.lang.String printName()

toString

public java.lang.String toString()
Provide a textual description of the map cell. This method is useful for debugging.

Returns:
a simple printable description of the cell