elge.world
Class MatrixRepresentation

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--elge.agent.VectorRepresentation
                    |
                    +--elge.world.MatrixRepresentation
All Implemented Interfaces:
AgentRepresentation, Collection, EventListener, List, MoveableMatrix, Serializable, VetoableChangeListener

public class MatrixRepresentation
extends VectorRepresentation
implements MoveableMatrix, VetoableChangeListener

This representation holds agent in a matrix with x,y coordinates. It extends the VetorRepresentation which is xml storable.

Author:
Pavol Žibrita
See Also:
Serialized Form

Field Summary
 
Fields inherited from class elge.agent.VectorRepresentation
agents, propertySupport
 
Fields inherited from class java.util.AbstractList
modCount
 
Fields inherited from interface elge.agent.AgentRepresentation
PROP_DIMENSION
 
Constructor Summary
MatrixRepresentation()
          Creates default isntance of dimension 100,100.
MatrixRepresentation(Dimension dim)
          Creates a new instance of MatrixRepresentation with a size.
MatrixRepresentation(int width, int height)
          Creates a new instance of MatrixRepresentation with a size.
 
Method Summary
 void add(int index, Object a)
          Inserts the specified element at the specified position in this list (optional operation).
 boolean add(Object a)
          Ensures that this collection contains the specified element (optional operation).
 Point correctPosition(Point p)
           
 Point createDefaultPosition()
           
 Dimension getDimension()
          Returns the matrix size.
 Point checkPosition(Point p)
          Checks if the position is acceptable.
 boolean move(MoveableAgent a, Point p)
          Tries to move the agent to a new position. if the position is not acceptable, false is returned and position is not changed.
 void remove(Agent a)
           
 Point rndPosition()
          Generates position somewhere within the representation dimension.
 Point rndRelPosition(Point from, double radius)
          Like rndPosition, but it generates relativee from point from with max distance to point radius.
 void setDimension(Dimension d)
          Sets new dimension of the matrix
 Point setPosition(MoveableAgent a, Point p)
          Sets the position for the agent.
 void vetoableChange(PropertyChangeEvent evt)
          This method gets called when a constrained property is changed.
 
Methods inherited from class elge.agent.VectorRepresentation
addAll, addAll, addPropertyChangeListener, clear, contains, containsAll, get, getDimenstion, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removePropertyChangeListener, retainAll, set, size, subList, toArray, toArray
 
Methods inherited from class java.util.AbstractList
equals, hashCode, removeRange
 
Methods inherited from class java.util.AbstractCollection
toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
equals, hashCode
 

Constructor Detail

MatrixRepresentation

public MatrixRepresentation()
Creates default isntance of dimension 100,100.


MatrixRepresentation

public MatrixRepresentation(int width,
                            int height)
Creates a new instance of MatrixRepresentation with a size.

Parameters:
width - width of the matrix
height - height of the matrix

MatrixRepresentation

public MatrixRepresentation(Dimension dim)
Creates a new instance of MatrixRepresentation with a size.

Parameters:
dim - The size of the matrix
Method Detail

add

public void add(int index,
                Object a)
Description copied from class: VectorRepresentation
Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Specified by:
add in interface List
Overrides:
add in class VectorRepresentation
Parameters:
index - index at which the specified element is to be inserted.
a - element to be inserted.

add

public boolean add(Object a)
Description copied from class: VectorRepresentation
Ensures that this collection contains the specified element (optional operation). Returns true if this collection changed as a result of the call. (Returns false if this collection does not permit duplicates and already contains the specified element.)

Collections that support this operation may place limitations on what elements may be added to this collection. In particular, some collections will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. Collection classes should clearly specify in their documentation any restrictions on what elements may be added.

If a collection refuses to add a particular element for any reason other than that it already contains the element, it must throw an exception (rather than returning false). This preserves the invariant that a collection always contains the specified element after this call returns.

Specified by:
add in interface List
Overrides:
add in class VectorRepresentation
Parameters:
a - element whose presence in this collection is to be ensured.
Returns:
true if this collection changed as a result of the call

createDefaultPosition

public Point createDefaultPosition()

remove

public void remove(Agent a)

rndPosition

public Point rndPosition()
Generates position somewhere within the representation dimension.

Specified by:
rndPosition in interface AgentRepresentation
Overrides:
rndPosition in class VectorRepresentation
Returns:
returns a random point in the matrix.

rndRelPosition

public Point rndRelPosition(Point from,
                            double radius)
Like rndPosition, but it generates relativee from point from with max distance to point radius.

Specified by:
rndRelPosition in interface AgentRepresentation
Overrides:
rndRelPosition in class VectorRepresentation
Parameters:
from - Point to generate from.
radius - max distance to generate the point from the from point
Returns:
returns random point relative to porint from in dinstance of radius.

setDimension

public void setDimension(Dimension d)
Sets new dimension of the matrix

Specified by:
setDimension in interface AgentRepresentation
Overrides:
setDimension in class VectorRepresentation
Parameters:
d - Size of the matrix

getDimension

public Dimension getDimension()
Returns the matrix size.

Specified by:
getDimension in interface AgentRepresentation
Overrides:
getDimension in class VectorRepresentation
Returns:
the size of the matrix

checkPosition

public Point checkPosition(Point p)
Checks if the position is acceptable. If not, new position is returnd else the p is returned.

Specified by:
checkPosition in interface MoveableMatrix

correctPosition

public Point correctPosition(Point p)

move

public boolean move(MoveableAgent a,
                    Point p)
Tries to move the agent to a new position. if the position is not acceptable, false is returned and position is not changed.

Specified by:
move in interface MoveableMatrix

setPosition

public Point setPosition(MoveableAgent a,
                         Point p)
Sets the position for the agent. If the position is not acceptable, a acceptable position is set and returned, if the position is ok, the p is returned.

Specified by:
setPosition in interface MoveableMatrix

vetoableChange

public void vetoableChange(PropertyChangeEvent evt)
                    throws PropertyVetoException
This method gets called when a constrained property is changed.

Specified by:
vetoableChange in interface VetoableChangeListener
Parameters:
evt - a PropertyChangeEvent object describing the event source and the property that has changed.
Throws:
PropertyVetoException - if the recipient wishes the property change to be rolled back.