Class HashMapIndex
java.lang.Object
com.sk89q.worldguard.protection.managers.index.HashMapIndex
- All Implemented Interfaces:
ConcurrentRegionIndex
,RegionIndex
,ChangeTracked
- Direct Known Subclasses:
PriorityRTreeIndex
An index that stores regions in a hash map, which allows for fast lookup
by ID but O(n) performance for spatial queries.
This implementation supports concurrency to the extent that
a ConcurrentMap
does.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
A factory for new instances using this index. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(ProtectedRegion region) Add a region to this index, replacing any existing one with the same name (equality determined usingNormal
).void
addAll
(Collection<ProtectedRegion> regions) Add a list of regions to this index, replacing any existing one with the same name (equality determined usingNormal
).void
apply
(Predicate<ProtectedRegion> consumer) Apply the given predicate to all the regions in the index until there are no more regions or the predicate returns false.void
applyContaining
(com.sk89q.worldedit.math.BlockVector3 position, Predicate<ProtectedRegion> consumer) Apply the given predicate to all regions that contain the given position until there are no more regions or the predicate returns false.void
applyIntersecting
(ProtectedRegion region, Predicate<ProtectedRegion> consumer) Apply the given predicate to all regions that intersect the given region until there are no more regions or the predicate returns false.void
bias
(com.sk89q.worldedit.math.BlockVector2 chunkPosition) Bias the given chunk for faster lookups (put it in a hash table, etc.).void
biasAll
(Collection<com.sk89q.worldedit.math.BlockVector2> chunkPositions) Bias the given chunk for faster lookups (put it in a hash table, etc.).boolean
Test whether the index contains a region named by the given name (equality determined usingNormal
).void
forget
(com.sk89q.worldedit.math.BlockVector2 chunkPosition) No longer bias the given chunk for faster lookup.void
Clearly all extra cache data created by any calls toRegionIndex.bias(BlockVector2)
.Get the region named by the given name (equality determined usingNormal
).Get the list of changed or removed regions since last call and clear those lists.boolean
isDirty()
Tests whether changes have been made.protected void
Called to rebuild the index after changes.remove
(String id, RemovalStrategy strategy) Remove a region from the index with the given name.void
setDirty
(boolean dirty) Set whether changes have been made.void
setDirty
(RegionDifference difference) Set the index to be dirty using the given difference.int
size()
Return the number of regions in the index.values()
Get an unmodifiable collection of regions stored in this index.
-
Constructor Details
-
HashMapIndex
public HashMapIndex()
-
-
Method Details
-
rebuildIndex
protected void rebuildIndex()Called to rebuild the index after changes. -
addAll
Description copied from interface:RegionIndex
Add a list of regions to this index, replacing any existing one with the same name (equality determined usingNormal
).The parents of the region will also be added to the index.
- Specified by:
addAll
in interfaceRegionIndex
- Parameters:
regions
- a collections of regions
-
bias
public void bias(com.sk89q.worldedit.math.BlockVector2 chunkPosition) Description copied from interface:RegionIndex
Bias the given chunk for faster lookups (put it in a hash table, etc.).Implementations may choose to do nothing.
- Specified by:
bias
in interfaceRegionIndex
- Parameters:
chunkPosition
- the chunk position
-
biasAll
Description copied from interface:RegionIndex
Bias the given chunk for faster lookups (put it in a hash table, etc.).Implementations may choose to do nothing.
- Specified by:
biasAll
in interfaceRegionIndex
- Parameters:
chunkPositions
- the chunk position
-
forget
public void forget(com.sk89q.worldedit.math.BlockVector2 chunkPosition) Description copied from interface:RegionIndex
No longer bias the given chunk for faster lookup.- Specified by:
forget
in interfaceRegionIndex
- Parameters:
chunkPosition
- the chunk position
-
forgetAll
public void forgetAll()Description copied from interface:RegionIndex
Clearly all extra cache data created by any calls toRegionIndex.bias(BlockVector2)
.- Specified by:
forgetAll
in interfaceRegionIndex
-
add
Description copied from interface:RegionIndex
Add a region to this index, replacing any existing one with the same name (equality determined usingNormal
).The parents of the region will also be added to the index.
- Specified by:
add
in interfaceRegionIndex
- Parameters:
region
- the region
-
remove
Description copied from interface:RegionIndex
Remove a region from the index with the given name.- Specified by:
remove
in interfaceRegionIndex
- Parameters:
id
- the name of the regionstrategy
- what to do with children- Returns:
- a list of removed regions where the first entry is the region specified by
id
-
contains
Description copied from interface:RegionIndex
Test whether the index contains a region named by the given name (equality determined usingNormal
).- Specified by:
contains
in interfaceRegionIndex
- Parameters:
id
- the name of the region- Returns:
- true if the index contains the region
-
get
Description copied from interface:RegionIndex
Get the region named by the given name (equality determined usingNormal
).- Specified by:
get
in interfaceRegionIndex
- Parameters:
id
- the name of the region- Returns:
- a region or
null
-
apply
Description copied from interface:RegionIndex
Apply the given predicate to all the regions in the index until there are no more regions or the predicate returns false.- Specified by:
apply
in interfaceRegionIndex
- Parameters:
consumer
- a predicate that returns true to continue iterating
-
applyContaining
public void applyContaining(com.sk89q.worldedit.math.BlockVector3 position, Predicate<ProtectedRegion> consumer) Description copied from interface:RegionIndex
Apply the given predicate to all regions that contain the given position until there are no more regions or the predicate returns false.- Specified by:
applyContaining
in interfaceRegionIndex
- Parameters:
position
- the positionconsumer
- a predicate that returns true to continue iterating
-
applyIntersecting
Description copied from interface:RegionIndex
Apply the given predicate to all regions that intersect the given region until there are no more regions or the predicate returns false.- Specified by:
applyIntersecting
in interfaceRegionIndex
- Parameters:
region
- the intersecting regionconsumer
- a predicate that returns true to continue iterating
-
size
public int size()Description copied from interface:RegionIndex
Return the number of regions in the index.- Specified by:
size
in interfaceRegionIndex
- Returns:
- the number of regions
-
getAndClearDifference
Description copied from interface:RegionIndex
Get the list of changed or removed regions since last call and clear those lists.- Specified by:
getAndClearDifference
in interfaceRegionIndex
- Returns:
- the difference
-
setDirty
Description copied from interface:RegionIndex
Set the index to be dirty using the given difference.- Specified by:
setDirty
in interfaceRegionIndex
- Parameters:
difference
- the difference
-
values
Description copied from interface:RegionIndex
Get an unmodifiable collection of regions stored in this index.- Specified by:
values
in interfaceRegionIndex
- Returns:
- a collection of regions
-
isDirty
public boolean isDirty()Description copied from interface:ChangeTracked
Tests whether changes have been made.- Specified by:
isDirty
in interfaceChangeTracked
- Returns:
- true if changes have been made
-
setDirty
public void setDirty(boolean dirty) Description copied from interface:ChangeTracked
Set whether changes have been made.- Specified by:
setDirty
in interfaceChangeTracked
- Parameters:
dirty
- a new dirty state
-