|
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.algart.model3d.common.movement.model.SimpleItemSet
public class SimpleItemSet extends java.lang.Object implements ItemSet
Simplest item set.
This implementation of ItemSet
interface stores the items in a built-in
java.util.List, which is initially created in the constructor by some ItemListBuilder
object. So, all basic methods of this object — size()
, get(int)
, set(int, Item)
,
add(Item)
, getAll()
, getAll(Class)
, addAll(java.util.Collection)
,
removeItems(int, int)
— are implemented very simply via the corresponding methods
of java.util.List interface. The only non-trivial methods are
getPossibleInteractingIndexes(int[], int)
and preprocess()
: see comments to those methods
for more details.
Please see comments fo ItemSet
interface about multithreading usage.
AlgART Laboratory 2010
Constructor and Description |
---|
SimpleItemSet()
Creates new instance of this class, storing items in java.util.ArrayList. |
SimpleItemSet(ItemListBuilder itemListBuilder)
Creates new instance of this class. |
Modifier and Type | Method and Description | |
---|---|---|
void |
add(Item newItem)
Appends the specified item to the end of this item list. |
|
void |
addAll(java.util.Collection<? extends Item> newItems)
Appends all items from the specified collection to the end of this item list, in the order that they are returned by the specified collection's iterator. |
|
Item |
get(int itemIndex)
Returns the item with the given index (from 0 to ItemSet.size() −1). |
|
java.util.List<Item> |
getAll()
Returns the list of all items of this item list. |
|
|
getAll(java.lang.Class<? extends T> requiredClass)
Returns newly created modifiable list of all items of this item list, implementing the specified interface (or extending the specified class). |
|
int |
getPossibleInteractingIndexes(int[] result,
int itemIndex)
This implementation is based on a simple loop, which checks coordinates and interaction radii of all items
and stores in the result only indexes of such items that the distance between centers
(of the item #itemIndex and the other one) is not greater than the sum
of interaction radii of that item pair. |
|
void |
preprocess()
This implementation allocates several Java arrays and stores there coordinates of centers and interaction radii of all items, which have centers
and interaction radii (i.e. implement HavingInteractionRadius ). |
|
void |
removeItems(int fromIndex,
int toIndex)
Removes all items with indexes fromIndex<=k<toIndex and shifts any subsequent items to the left (subtracts toIndex-fromIndex from their indexes). |
|
void |
set(int itemIndex,
Item newItem)
Replaces the item with the given index (from 0 to ItemSet.size() −1) with the specified new one. |
|
int |
size()
Returns the number of items in this item list. |
|
java.lang.String |
toString()
Returns a brief string description of this object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public SimpleItemSet(ItemListBuilder itemListBuilder)
The itemListBuilder argument specifies the builder, that will be used for creating the built-in java.util.List instance, which will really store all items.
itemListBuilder
- the builder, that will be used for creating the java.util.List instance.java.lang.NullPointerException
- if itemListBuilder is null.public SimpleItemSet()
SimpleItemSet
(ItemListBuilder.DEFAULT
)
Method Detail |
---|
public int size()
ItemSet
size
in interface ItemSet
public Item get(int itemIndex)
ItemSet
ItemSet.size()
−1).
get
in interface ItemSet
itemIndex
- index of the item to get.public void set(int itemIndex, Item newItem)
ItemSet
ItemSet.size()
−1) with the specified new one.
set
in interface ItemSet
itemIndex
- index of the item to replace.newItem
- new item to be stored at the specified index.public void add(Item newItem)
ItemSet
add
in interface ItemSet
newItem
- new item to be added to this item list.public java.util.List<Item> getAll()
ItemSet
get
(k).
The returned list can be either newly created list, or an immutable view (Collections.unmodifiableList) of the internal collection, stored by this object. In any case, you cannot modify the set of items via the result of this method. But the returned list contains references to items, not their clones; so changes in the returned items (via setXxx methods) will be reflected in this collection.
getAll
in interface ItemSet
public <T extends Item> java.util.List<T> getAll(java.lang.Class<? extends T> requiredClass)
ItemSet
The returned list is newly created, so changes in it do not affect to this object. But the returned list contains references to items, not their clones; so changes in the returned items (via setXxx methods) will be reflected in this collection.
getAll
in interface ItemSet
requiredClass
- the class of all returned items.public void addAll(java.util.Collection<? extends Item> newItems)
ItemSet
Note: if some of added items are null, then part of them can be still added before throwing NullPointerException. In other words, this method can be non-atomic regarding this failure.
addAll
in interface ItemSet
newItems
- new items to be added to this item list.public void removeItems(int fromIndex, int toIndex)
ItemSet
removeItems
in interface ItemSet
fromIndex
- starting index of removed items (inclusive).toIndex
- ending index of removed items (exclusive).public int getPossibleInteractingIndexes(int[] result, int itemIndex)
interaction radii
of all items
and stores in the result only indexes of such items that the distance between centers
(of the item #itemIndex and the other one) is not greater than the sum
of interaction radii
of that item pair.
getPossibleInteractingIndexes
in interface ItemSet
result
- the indexes of "neighbours": items that can interact with the given item.itemIndex
- the index of the given item.java.lang.NullPointerException
- if result argument is null.java.lang.IllegalStateException
- if the length of result array is insufficient.java.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size()
).public void preprocess()
interaction radii
of all items, which have centers
and interaction radii (i.e. implement HavingInteractionRadius
).
It optimizes the execution of getPossibleInteractingIndexes(int[], int)
method:
Java usually works faster with usual Java array, than with properties of objects available
via getXxx method.
This method reallocates memory if and only if it is the first call of this method or
the number of items size()
was changed since the last call of it.
preprocess
in interface ItemSet
public java.lang.String toString()
The result of this method may depend on implementation.
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |