|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.ascape.model.space.CollectionSpace
public class CollectionSpace
The Class CollectionSpace.
Nested Class Summary | |
---|---|
class |
CollectionSpace.ClosestDataPoint
The Class ClosestDataPoint. |
static class |
CollectionSpace.ConditionalIterator
The Class ConditionalIterator. |
protected class |
CollectionSpace.CSIterator
The Class CSIterator. |
protected class |
CollectionSpace.CSMutableIterator
The Class CSMutableIterator. |
protected class |
CollectionSpace.ListMutableRandomIterator
The Class ListMutableRandomIterator. |
protected class |
CollectionSpace.ListRandomIterator
The Class ListRandomIterator. |
protected class |
CollectionSpace.MutableSubIterator
The Class MutableSubIterator. |
protected class |
CollectionSpace.SubIterator
The Class SubIterator. |
Field Summary | |
---|---|
protected java.util.Collection |
collection
The backing collection. |
static int |
ESTIMATED_MAXIMUM_SIZE
The estimated maximum size a typical collection will be. |
protected Coordinate |
extent
The extent (furthest valid point) of the context. |
protected Geometry |
geometry
The basic geometric structure of this collection. |
Constructor Summary | |
---|---|
CollectionSpace()
Instantiates a new collection space. |
Method Summary | |
---|---|
boolean |
add(java.lang.Object a)
Adds the supplied object (agent) to this collection. |
boolean |
add(java.lang.Object o,
boolean isParent)
Adds the supplied object to this collection. |
boolean |
addAll(java.util.Collection c)
Adds all of the agent in the specified collection to the end of the context. |
double |
calculateDistance(Coordinate origin,
Coordinate target)
Returns the shortest distance between one Location and another. |
double |
calculateDistance(Location origin,
Location target)
Returns the shortest distance between one agent and another. |
void |
clear()
Removes all agents from the context. |
java.lang.Object |
clone()
Overides the clone method to do a deep clone of member state so that such state will not be shared between scapes. |
java.util.Iterator |
conditionalIterator(Conditional condition)
Conditional iterator. |
static java.util.Iterator |
conditionalIterator(java.util.Iterator iter,
Conditional condition)
Conditional iterator. |
void |
construct()
Construct. |
boolean |
contains(java.lang.Object o)
Returns true if the context collection contains the object (agent.) |
boolean |
containsAll(java.util.Collection c)
Returns true if this collection contains all of agents in the specified collection. |
int |
countWithin(Coordinate origin,
Conditional condition,
boolean includeSelf,
double distance)
Returns the number of agents within the specified distance of the agent that meet some condition. |
static int[] |
createOrder(int length)
Creates a new array of ints for use as indexes for an ordered iteration. |
protected Conditional |
createSpatialConditional(Coordinate origin,
Conditional condition,
boolean includeSelf,
double distance)
Creates the spatial conditional. |
void |
deleteSweep()
Walks through each agent, deleting it if it has been marked for deletion. |
static java.util.List |
filter(java.util.Collection list,
Conditional condition)
Filter. |
java.util.List |
find(Conditional condition)
Finds all locations with specified condition. |
Location |
findMaximum(DataPoint point)
Returns the agent with the maximum value. |
Location |
findMaximum(java.util.Iterator iter,
DataPoint dataPoint)
Find the maximum cell of some data point. |
Location |
findMaximumWithin(Coordinate coordinate,
DataPoint dataPoint,
Conditional condition,
boolean includeSelf,
double distance)
Find maximum within. |
Location |
findMinimum(DataPoint point)
Returns the agent with the minimum value. |
Location |
findMinimum(java.util.Iterator iter,
DataPoint dataPoint)
Find minimum. |
Location |
findMinimumWithin(Coordinate coordinate,
DataPoint dataPoint,
Conditional condition,
boolean includeSelf,
double distance)
Find minimum within. |
Location |
findNearest(Coordinate origin,
Conditional condition,
boolean includeOrigin,
double distance)
Finds the nearest agent that meets some condition. |
Location |
findNearest(Location origin,
Conditional condition,
boolean includeOrigin,
double distance)
Finds the nearest agent that meets some condition. |
Location |
findRandom()
Returns an agent randomly selected from the collection. |
Location |
findRandom(Conditional condition)
Returns an agent randomly that matches a condition. |
Location |
findRandom(Location excludeLocation)
Returns a random unoccupied discrete location in the space given with the lattice. |
Location |
findRandom(Location exclude,
Conditional condition)
Returns an agent randomly that matches a condition, excluding the coordinate. |
Coordinate |
findRandomCoordinate()
Returns a coordinate randomly selected from the collection's space. |
Location |
findRandomWithin(Location origin,
Conditional condition,
boolean includeSelf,
double distance)
|
java.util.List |
findWithin(Coordinate origin,
Conditional condition,
boolean includeSelf,
double distance)
Returns all agents within the specified distance of the agent. |
Location |
get(Coordinate coordinate)
Returns the cell existing at the specified coordinate. |
SpaceContext |
getContext()
Gets the context. |
Coordinate |
getExtent()
Returns the extent of the context. |
Geometry |
getGeometry()
Return the geometry of this context. |
java.util.Random |
getRandom()
|
int |
getSize()
Returns the size, or number of agents, of this space. |
boolean |
hasWithin(Coordinate origin,
Conditional condition,
boolean includeSelf,
double distance)
Returns if there are agents within the specified distance of the origin that meet some Condition. |
void |
initialize()
Initialize. |
boolean |
isDeleteSweepNeeded()
Is a delete sweep needed for this context? Intended for internal purposes. |
boolean |
isEmpty()
Are there no agents in this context?. |
boolean |
isMutable()
Is the context mutable, that is, can it change its structure at runtime? Returns true for this collection. |
boolean |
isPeriodic()
Is the geometry periodic or aperiodic? (Do edges wrap to opposite side or not?). |
java.util.Iterator |
iterator()
Returns an iterator across all agents in this context. |
static int |
iteratorCount(java.util.Iterator iter)
Iterator count. |
static java.util.List |
iteratorToList(java.util.Iterator iter)
Iterator to list. |
void |
moveAway(Location origin,
Coordinate target,
double distance)
Moves an agent toward the specified agent. |
void |
moveToward(Location origin,
Coordinate target,
double distance)
Moves an agent toward the specified agent. |
Location |
newLocation()
Creates a new agent in this collection by cloning the prototype agent, adding it to the end of the vector, and initializing it. |
Location |
newLocation(boolean randomLocation)
Creates a new agent in this collection by cloning the prototype agent, adding it to a random or arbitrary (last in this case) place in the collection, and initializing it. |
void |
populate()
Populate. |
double |
randomInRange(double low,
double high)
Generate a double uniformly distributed across some range. |
int |
randomInRange(int low,
int high)
Generate an integer uniformly distributed across some range. |
boolean |
randomIs()
Returns a random boolean value. |
static int[] |
randomizeOrder(int[] order,
java.util.Random random)
Randomizes order of the supplied int. |
int |
randomToLimit(int limit)
Generate an integer uniformly distributed across 0...limit - 1. |
boolean |
remove(java.lang.Object o)
Removes the supplied object (agent) from this collection. |
boolean |
removeAll(java.util.Collection c)
Removes all of the agents contained in the collection. |
boolean |
retainAll(java.util.Collection c)
Retains only the elements in the context that are in the specified collection. |
ResetableIterator |
safeIterator()
Returns a context iterator across all objects in this context. |
ResetableIterator |
safeIterator(int start,
int limit)
Safe iterator. |
ResetableIterator[] |
safeIterators(int count)
Returns multiple independently thread safe context iterators across all agents in this context. |
RandomIterator |
safeRandomIterator()
Returns a context iterator across all agents in random order. |
void |
set(Coordinate coordinate,
Location agent)
Sets the agent at the specified coordinate to the supplied agent. |
void |
setContext(SpaceContext context)
Sets the context. |
void |
setExtent(Coordinate extent)
Sets the size of the context. |
void |
setExtent(int size)
Sets the size of the collection. |
protected void |
setGeometry(Geometry geometry)
Sets the geometry or basic structure of this context. |
void |
setPeriodic(boolean periodic)
Sets the geometry to periodic or aperiodic. |
void |
setRandom(java.util.Random random)
|
void |
setSize(int internalSize)
Sets the size of the collection. |
int |
size()
Returns the number of agents in the context. |
java.lang.Object[] |
toArray()
Returns an array containing all of the elements in this collection in proper sequence. |
java.lang.Object[] |
toArray(java.lang.Object[] a)
Returns an array containing the current agents in this context; the runtime type is specified by the passed array. |
java.util.List |
toList()
|
java.util.Iterator |
withinIterator(Coordinate origin,
Conditional condition,
boolean includeSelf,
double distance)
Returns an iteration across all agents the specified distance from the origin. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.util.Collection |
---|
equals, hashCode |
Field Detail |
---|
public static int ESTIMATED_MAXIMUM_SIZE
protected java.util.Collection collection
protected Geometry geometry
protected Coordinate extent
Constructor Detail |
---|
public CollectionSpace()
Method Detail |
---|
public void deleteSweep()
public Location newLocation()
public Location newLocation(boolean randomLocation)
newLocation
in interface Space
randomLocation
- should the agent be placed in a random location, or in an
arbitrary location?
public boolean isEmpty()
isEmpty
in interface java.util.Collection
public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection
o
- the agent to search for
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection
Arrays.asList(java.lang.Object[])
public java.lang.Object[] toArray(java.lang.Object[] a)
toArray
in interface java.util.Collection
a
- the array to copy the agents to
java.lang.ArrayStoreException
- if the runtime type of the specified array doesn't match all
agentspublic boolean containsAll(java.util.Collection c)
containsAll
in interface java.util.Collection
c
- collection of agents to be found in the context
public boolean addAll(java.util.Collection c)
addAll
in interface java.util.Collection
c
- collection whose agents are to be added to the context
public boolean removeAll(java.util.Collection c)
removeAll
in interface java.util.Collection
c
- collection whose agents are to be added to the context
public boolean retainAll(java.util.Collection c)
retainAll
in interface java.util.Collection
c
- collection whose agents are to be retained in the context
public void clear()
clear
in interface java.util.Collection
public boolean add(java.lang.Object a)
add
in interface java.util.Collection
a
- the a
public boolean add(java.lang.Object o, boolean isParent)
add
in interface Space
o
- the agent to addisParent
- should this context be made the parent context of the agent?
java.lang.ClassCastException
- if the object is not an instance of agentpublic boolean remove(java.lang.Object o)
remove
in interface java.util.Collection
o
- the agent to be removed
public java.util.Iterator iterator()
iterator
in interface java.lang.Iterable
iterator
in interface java.util.Collection
public ResetableIterator safeIterator(int start, int limit)
Space
safeIterator
in interface Space
start
- the startlimit
- the limit
public boolean isMutable()
isMutable
in interface Space
public ResetableIterator[] safeIterators(int count)
safeIterators
in interface Space
count
- the count
public void moveAway(Location origin, Coordinate target, double distance)
moveAway
in interface Space
origin
- the agent movingtarget
- the agent's targetdistance
- the distance to movepublic void moveToward(Location origin, Coordinate target, double distance)
moveToward
in interface Space
origin
- the agent movingtarget
- the agent's targetdistance
- the distance to movepublic double calculateDistance(Location origin, Location target)
calculateDistance
in interface Space
origin
- the starting agenttarget
- the ending agent
public double calculateDistance(Coordinate origin, Coordinate target)
calculateDistance
in interface Space
origin
- one Locationtarget
- another Location
public java.util.List find(Conditional condition)
find
in interface Space
condition
- the condition to search locations for
public Location findMaximum(java.util.Iterator iter, DataPoint dataPoint)
iter
- the iterdataPoint
- the data point
public Location findNearest(Coordinate origin, Conditional condition, boolean includeOrigin, double distance)
findNearest
in interface Space
origin
- the coordinate to find agents nearcondition
- the condition that found agent must meetincludeOrigin
- if the origin should be includeddistance
- the maximum distance around the origin to look
public Location findNearest(Location origin, Conditional condition, boolean includeOrigin, double distance)
findNearest
in interface Space
origin
- the lcoation to find agents nearcondition
- the condition that found agent must meetincludeOrigin
- if the origin should be includeddistance
- the maximum distance around the origin to look
public Coordinate findRandomCoordinate()
findRandomCoordinate
in interface Space
public static java.util.List iteratorToList(java.util.Iterator iter)
iter
- the iter
public static int iteratorCount(java.util.Iterator iter)
iter
- the iter
public java.util.List findWithin(Coordinate origin, Conditional condition, boolean includeSelf, double distance)
findWithin
in interface Space
origin
- the coordinate at the center of the searchincludeSelf
- whether or not the starting agent should be included in the
searchdistance
- the distance agents must be within to be includedcondition
- the condition
public int countWithin(Coordinate origin, Conditional condition, boolean includeSelf, double distance)
countWithin
in interface Space
origin
- the coordinate at the center of the searchcondition
- the condition the agent must meet to be includeddistance
- the distance agents must be within to be includedincludeSelf
- the include self
public boolean hasWithin(Coordinate origin, Conditional condition, boolean includeSelf, double distance)
hasWithin
in interface Space
origin
- the coordinate at the center of the searchcondition
- the condition the agent must meet to be includeddistance
- the distance agents must be within to be includedincludeSelf
- the include self
public Location findMinimumWithin(Coordinate coordinate, DataPoint dataPoint, Conditional condition, boolean includeSelf, double distance)
Space
findMinimumWithin
in interface Space
coordinate
- the coordinatedataPoint
- the data pointcondition
- the conditionincludeSelf
- the include selfdistance
- the distance
public Location findMaximumWithin(Coordinate coordinate, DataPoint dataPoint, Conditional condition, boolean includeSelf, double distance)
Space
findMaximumWithin
in interface Space
coordinate
- the coordinatedataPoint
- the data pointcondition
- the conditionincludeSelf
- the include selfdistance
- the distance
public Location findMinimum(java.util.Iterator iter, DataPoint dataPoint)
iter
- the iterdataPoint
- the data point
public ResetableIterator safeIterator()
safeIterator
in interface Space
public RandomIterator safeRandomIterator()
safeRandomIterator
in interface Space
public static java.util.Iterator conditionalIterator(java.util.Iterator iter, Conditional condition)
iter
- the itercondition
- the condition
public java.util.Iterator conditionalIterator(Conditional condition)
Space
conditionalIterator
in interface Space
condition
- the condition
public static java.util.List filter(java.util.Collection list, Conditional condition)
list
- the listcondition
- the condition
public java.util.Iterator withinIterator(Coordinate origin, Conditional condition, boolean includeSelf, double distance)
withinIterator
in interface Space
origin
- the starting cellincludeSelf
- should the origin be includeddistance
- the distance agents must be within to be includedcondition
- the condition
protected Conditional createSpatialConditional(Coordinate origin, Conditional condition, boolean includeSelf, double distance)
origin
- the origincondition
- the conditionincludeSelf
- the include selfdistance
- the distance
public Location findRandom()
findRandom
in interface Space
public Location findRandom(Location excludeLocation)
findRandom
in interface Space
excludeLocation
- a cell to exclude from get (typically origin)
public Location findRandom(Conditional condition)
findRandom
in interface Space
condition
- the condition that must be matched
public Location findRandom(Location exclude, Conditional condition)
findRandom
in interface Space
condition
- the condition that must be matched
public Location findRandomWithin(Location origin, Conditional condition, boolean includeSelf, double distance)
findRandomWithin
in interface Space
public Location findMinimum(DataPoint point)
findMinimum
in interface Space
point
- the data point to use to make the comparison for minimum
public Location findMaximum(DataPoint point)
findMaximum
in interface Space
point
- the data point to use to make the comparison for maximum
public Location get(Coordinate coordinate)
get
in interface Space
coordinate
- the coordinate
public void set(Coordinate coordinate, Location agent)
set
in interface Space
coordinate
- the coordinate to add the agent atagent
- the agent to addpublic void setExtent(int size)
size
- the size of this contextpublic int size()
size
in interface java.util.Collection
public int getSize()
getSize
in interface Space
public Coordinate getExtent()
getExtent
in interface Space
public void setExtent(Coordinate extent)
setExtent
in interface Space
extent
- a coordinate at the maximum extentpublic boolean isDeleteSweepNeeded()
public void setSize(int internalSize)
setSize
in interface Space
internalSize
- the new size of the collectionpublic void construct()
Space
construct
in interface Space
public void populate()
Space
populate
in interface Space
public void initialize()
Space
initialize
in interface Space
public int randomInRange(int low, int high)
randomInRange
in interface RandomFunctions
low
- the lowest number (inclusive) that the resulting int might behigh
- the hignest number (inclusive) that the resulting int might be
public double randomInRange(double low, double high)
randomInRange
in interface RandomFunctions
low
- the lowest number (inclusive) that the resulting double might
behigh
- the hignest number (exclusive) that the resulting double might
be
public int randomToLimit(int limit)
randomToLimit
in interface RandomFunctions
limit
- the maximum limit (exclusive) of the resulting int
public boolean randomIs()
randomIs
in interface RandomFunctions
public SpaceContext getContext()
Space
getContext
in interface Space
public void setContext(SpaceContext context)
Space
setContext
in interface Space
context
- the new contextpublic java.util.Random getRandom()
getRandom
in interface RandomFunctions
public void setRandom(java.util.Random random)
setRandom
in interface RandomFunctions
public Geometry getGeometry()
getGeometry
in interface Space
protected void setGeometry(Geometry geometry)
geometry
- the structure of this contextpublic boolean isPeriodic()
isPeriodic
in interface Space
public void setPeriodic(boolean periodic)
setPeriodic
in interface Space
periodic
- true if periodic (wraps around at each edge), false is
aperiodicpublic java.lang.Object clone()
clone
in interface Space
clone
in class java.lang.Object
public static int[] createOrder(int length)
length
- the length
public static int[] randomizeOrder(int[] order, java.util.Random random)
order
- the orderrandom
- the random
public java.util.List toList()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |