|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.AbstractCollection | +--java.util.AbstractList | +--elge.agent.VectorRepresentation
VectorRepresentation is very simple class, that holds the agents like Vector class but it supports proprtyChangeListener and fires a event every time an agent has been added or removed.
Field Summary | |
protected Vector |
agents
delegate to hold the agents |
protected PropertyChangeSupport |
propertySupport
the propertyChangeSupport for listener |
Fields inherited from class java.util.AbstractList |
modCount |
Fields inherited from interface elge.agent.AgentRepresentation |
PROP_DIMENSION |
Constructor Summary | |
VectorRepresentation()
Creates a new instance of VectorRepresentation |
Method Summary | |
void |
add(int index,
Object element)
Inserts the specified element at the specified position in this list (optional operation). |
boolean |
add(Object o)
Ensures that this collection contains the specified element (optional operation). |
boolean |
addAll(Collection c)
Adds all of the elements in the specified collection to this collection (optional operation). |
boolean |
addAll(int index,
Collection c)
Inserts all of the elements in the specified collection into this list at the specified position (optional operation). |
void |
addPropertyChangeListener(PropertyChangeListener listener)
Adds a listener. |
void |
clear()
Removes all of the elements from this collection (optional operation). |
boolean |
contains(Object o)
Returns true if this collection contains the specified element. |
boolean |
containsAll(Collection c)
Returns true if this collection contains all of the elements in the specified collection. |
Object |
get(int index)
Returns the element at the specified position in this list. |
Dimension |
getDimension()
does nothing |
Dimension |
getDimenstion()
does nothing. |
int |
indexOf(Object o)
Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element. |
boolean |
isEmpty()
Returns true if this collection contains no elements. |
Iterator |
iterator()
Returns an iterator over the elements in this collection. |
int |
lastIndexOf(Object o)
Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element. |
ListIterator |
listIterator()
Returns a list iterator of the elements in this list (in proper sequence). |
ListIterator |
listIterator(int index)
Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list. |
Object |
remove(int index)
Removes the element at the specified position in this list (optional operation). |
boolean |
remove(Object o)
Removes a single instance of the specified element from this collection, if it is present (optional operation). |
boolean |
removeAll(Collection c)
Removes all this collection's elements that are also contained in the specified collection (optional operation). |
void |
removePropertyChangeListener(PropertyChangeListener listener)
removes property listener |
boolean |
retainAll(Collection c)
Retains only the elements in this collection that are contained in the specified collection (optional operation). |
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. |
Object |
set(int index,
Object element)
Replaces the element at the specified position in this list with the specified element (optional operation). |
void |
setDimension(Dimension d)
does nothing |
int |
size()
Returns the number of agents |
List |
subList(int fromIndex,
int toIndex)
Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. |
Object[] |
toArray()
Returns an array containing all of the elements in this collection. |
Object[] |
toArray(Object[] a)
Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. |
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 |
Field Detail |
protected Vector agents
protected PropertyChangeSupport propertySupport
Constructor Detail |
public VectorRepresentation()
Method Detail |
public Dimension getDimenstion()
public Point rndPosition()
rndPosition
in interface AgentRepresentation
public Point rndRelPosition(Point from, double radius)
rndRelPosition
in interface AgentRepresentation
from
- relative pointradius
- distance
public void setDimension(Dimension d)
setDimension
in interface AgentRepresentation
d
- sizepublic int size()
size
in interface List
size
in class AbstractCollection
public Dimension getDimension()
getDimension
in interface AgentRepresentation
public void addPropertyChangeListener(PropertyChangeListener listener)
addPropertyChangeListener
in interface AgentRepresentation
listener
- a lsitener to this AgentRepresentationPropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener listener)
removePropertyChangeListener
in interface AgentRepresentation
listener
- the lsitenerPropertyChangeListener
public boolean add(Object o)
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.
add
in interface List
add
in class AbstractList
o
- element whose presence in this collection is to be ensured.
ClassCastException
- class of the specified element prevents it
from being added to this collection.public void add(int index, Object element)
add
in interface List
add
in class AbstractList
index
- index at which the specified element is to be inserted.element
- element to be inserted.
ClassCastException
- if the class of the specified element
prevents it from being added to this list.
NullPointerException
- if the specified element is null and
this list does not support null elements.
IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > size()).public boolean addAll(Collection c)
addAll
in interface List
addAll
in class AbstractCollection
c
- elements to be inserted into this collection.
ClassCastException
- if the class of an element of the specified
collection prevents it from being added to this collection.add(Object)
public boolean addAll(int index, Collection c)
addAll
in interface List
addAll
in class AbstractList
index
- index at which to insert first element from the specified
collection.c
- elements to be inserted into this list.
ClassCastException
- if the class of one of elements of the
specified collection prevents it from being added to this
list.
IndexOutOfBoundsException
- if the index is out of range (index
< 0 || index > size()).public void clear()
clear
in interface List
clear
in class AbstractList
public boolean contains(Object o)
contains
in interface List
contains
in class AbstractCollection
o
- element whose presence in this collection is to be tested.
NullPointerException
- if the specified element is null and this
collection does not support null elements (optional).public boolean containsAll(Collection c)
containsAll
in interface List
containsAll
in class AbstractCollection
c
- collection to be checked for containment in this collection.
ClassCastException
- if the types of one or more elements
in the specified collection are incompatible with this
collection (optional).
NullPointerException
- if the specified collection is
null.contains(Object)
public Object get(int index)
get
in interface List
get
in class AbstractList
index
- index of element to return.
IndexOutOfBoundsException
- if the index is out of range (index
< 0 || index >= size()).public int indexOf(Object o)
indexOf
in interface List
indexOf
in class AbstractList
o
- element to search for.
ClassCastException
- if the type of the specified element
is incompatible with this list (optional).public boolean isEmpty()
isEmpty
in interface List
isEmpty
in class AbstractCollection
public Iterator iterator()
iterator
in interface List
iterator
in class AbstractList
public int lastIndexOf(Object o)
lastIndexOf
in interface List
lastIndexOf
in class AbstractList
o
- element to search for.
ClassCastException
- if the type of the specified element
is incompatible with this list (optional).
NullPointerException
- if the specified element is null and this
list does not support null elements (optional).public ListIterator listIterator()
listIterator
in interface List
listIterator
in class AbstractList
public ListIterator listIterator(int index)
listIterator
in interface List
listIterator
in class AbstractList
index
- index of first element to be returned from the
list iterator (by a call to the next method).
IndexOutOfBoundsException
- if the index is out of range (index
< 0 || index > size()).public boolean remove(Object o)
remove
in interface List
remove
in class AbstractCollection
o
- element to be removed from this collection, if present.
ClassCastException
- if the type of the specified element
is incompatible with this collection (optional).
NullPointerException
- if the specified element is null and this
collection does not support null elements (optional).public Object remove(int index)
remove
in interface List
remove
in class AbstractList
index
- the index of the element to removed.
IndexOutOfBoundsException
- if the index is out of range (index
< 0 || index >= size()).public boolean removeAll(Collection c)
removeAll
in interface List
removeAll
in class AbstractCollection
c
- elements to be removed from this collection.
ClassCastException
- if the types of one or more elements
in this collection are incompatible with the specified
collection (optional).
NullPointerException
- if this collection contains one or more
null elements and the specified collection does not support
null elements (optional).
NullPointerException
- if the specified collection is
null.remove(Object)
,
contains(Object)
public boolean retainAll(Collection c)
retainAll
in interface List
retainAll
in class AbstractCollection
c
- elements to be retained in this collection.
UnsupportedOperationException
- if the retainAll method
is not supported by this Collection.remove(Object)
,
contains(Object)
public Object set(int index, Object element)
set
in interface List
set
in class AbstractList
index
- index of element to replace.element
- element to be stored at the specified position.
ClassCastException
- if the class of the specified element
prevents it from being added to this list.
NullPointerException
- if the specified element is null and
this list does not support null elements.
IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size()).public List subList(int fromIndex, int toIndex)
This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a list can be used as a range operation by passing a subList view instead of a whole list. For example, the following idiom removes a range of elements from a list:
list.subList(from, to).clear();Similar idioms may be constructed for indexOf and lastIndexOf, and all of the algorithms in the Collections class can be applied to a subList.
The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list. (Structural modifications are those that change the size of this list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)
subList
in interface List
subList
in class AbstractList
fromIndex
- low endpoint (inclusive) of the subList.toIndex
- high endpoint (exclusive) of the subList.
IndexOutOfBoundsException
- for an illegal endpoint index value
(fromIndex < 0 || toIndex > size || fromIndex > toIndex).public Object[] toArray()
The returned array will be "safe" in that no references to it are maintained by this collection. (In other words, this method must allocate a new array even if this collection is backed by an array). The caller is thus free to modify the returned array.
This method acts as bridge between array-based and collection-based APIs.
toArray
in interface List
toArray
in class AbstractCollection
public Object[] toArray(Object[] a)
If this collection fits in the specified array with room to spare (i.e., the array has more elements than this collection), the element in the array immediately following the end of the collection is set to null. This is useful in determining the length of this collection only if the caller knows that this collection does not contain any null elements.)
If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.
Like the toArray method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs
Suppose l is a List known to contain only strings. The following code can be used to dump the list into a newly allocated array of String:
String[] x = (String[]) v.toArray(new String[0]);
Note that toArray(new Object[0]) is identical in function to toArray().
toArray
in interface List
toArray
in class AbstractCollection
a
- the array into which the elements of this collection are to be
stored, if it is big enough; otherwise, a new array of the same
runtime type is allocated for this purpose.
ArrayStoreException
- the runtime type of the specified array is
not a supertype of the runtime type of every element in this
collection.
NullPointerException
- if the specified array is null.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |