Package de.extio.spacecraft.shared.world
Class LinearSearchIndex2D<T extends SpatialIndex2Capable>
- java.lang.Object
-
- de.extio.spacecraft.shared.world.LinearSearchIndex2D<T>
-
- All Implemented Interfaces:
SpatialIndex2D<T>
,AutoCloseable
,Iterable<T>
public final class LinearSearchIndex2D<T extends SpatialIndex2Capable> extends Object implements SpatialIndex2D<T>
LinearSearchIndex2D doing linear search only. Use it only for very special use cases. Implementation is mainly intended for performance comparison.
-
-
Field Summary
-
Fields inherited from interface de.extio.spacecraft.shared.world.SpatialIndex2D
SESSION
-
-
Constructor Summary
Constructors Constructor Description LinearSearchIndex2D()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(T obj)
Adds an object to the indexvoid
clear()
Clears but keeps internal state allocated.void
close()
Clears and frees internal statevoid
executeAt(CoordI2 position, Consumer<T> consumer, Predicate<T> filter)
Executes a consumer for all objects at a given position.List<T>
find(CoordI2 position, CoordI2 dimension, Predicate<T> filter)
Queries all object intersecting with a given area.T
findFirstAt(CoordI2 position, Predicate<T> filter)
Returns the first object at a given position.Iterator<T>
iterator()
void
move(T obj, CoordI2 oldPosition, CoordI2 oldDimension)
Moves an indexed object to a new location.void
remove(T obj)
Removes an object from the index-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface de.extio.spacecraft.shared.world.SpatialIndex2D
executeAt, find, find, find, findFirstAt
-
-
-
-
Method Detail
-
iterator
public Iterator<T> iterator()
- Specified by:
iterator
in interfaceIterable<T extends SpatialIndex2Capable>
-
add
public void add(T obj)
Description copied from interface:SpatialIndex2D
Adds an object to the index- Specified by:
add
in interfaceSpatialIndex2D<T extends SpatialIndex2Capable>
-
remove
public void remove(T obj)
Description copied from interface:SpatialIndex2D
Removes an object from the index- Specified by:
remove
in interfaceSpatialIndex2D<T extends SpatialIndex2Capable>
-
move
public void move(T obj, CoordI2 oldPosition, CoordI2 oldDimension)
Description copied from interface:SpatialIndex2D
Moves an indexed object to a new location. Implementations are usually faster than doing separate remove() and add() operations- Specified by:
move
in interfaceSpatialIndex2D<T extends SpatialIndex2Capable>
-
find
public List<T> find(CoordI2 position, CoordI2 dimension, Predicate<T> filter)
Description copied from interface:SpatialIndex2D
Queries all object intersecting with a given area. Objects can be pre-filtered which is usually faster than returning them first and then filter in your own code.- Specified by:
find
in interfaceSpatialIndex2D<T extends SpatialIndex2Capable>
-
findFirstAt
public T findFirstAt(CoordI2 position, Predicate<T> filter)
Description copied from interface:SpatialIndex2D
Returns the first object at a given position. Objects can be pre-filtered which is usually faster than returning them first and then filter in your own code.- Specified by:
findFirstAt
in interfaceSpatialIndex2D<T extends SpatialIndex2Capable>
-
executeAt
public void executeAt(CoordI2 position, Consumer<T> consumer, Predicate<T> filter)
Description copied from interface:SpatialIndex2D
Executes a consumer for all objects at a given position. Objects can be pre-filtered which is usually faster than returning them first and then filter in your own code.- Specified by:
executeAt
in interfaceSpatialIndex2D<T extends SpatialIndex2Capable>
-
close
public void close()
Description copied from interface:SpatialIndex2D
Clears and frees internal state- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceSpatialIndex2D<T extends SpatialIndex2Capable>
-
clear
public void clear()
Description copied from interface:SpatialIndex2D
Clears but keeps internal state allocated. Optimization for re-use.- Specified by:
clear
in interfaceSpatialIndex2D<T extends SpatialIndex2Capable>
-
-