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 classA factory for new instances using this index. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(ProtectedRegion region)Add a region to this index, replacing any existing one with the same name (equality determined usingNormal).voidaddAll(Collection<ProtectedRegion> regions)Add a list of regions to this index, replacing any existing one with the same name (equality determined usingNormal).voidapply(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.voidapplyContaining(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.voidapplyIntersecting(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.voidbias(com.sk89q.worldedit.math.BlockVector2 chunkPosition)Bias the given chunk for faster lookups (put it in a hash table, etc.).voidbiasAll(Collection<com.sk89q.worldedit.math.BlockVector2> chunkPositions)Bias the given chunk for faster lookups (put it in a hash table, etc.).booleanTest whether the index contains a region named by the given name (equality determined usingNormal).voidforget(com.sk89q.worldedit.math.BlockVector2 chunkPosition)No longer bias the given chunk for faster lookup.voidClearly 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.booleanisDirty()Tests whether changes have been made.protected voidCalled to rebuild the index after changes.remove(String id, RemovalStrategy strategy)Remove a region from the index with the given name.voidsetDirty(boolean dirty)Set whether changes have been made.voidsetDirty(RegionDifference difference)Set the index to be dirty using the given difference.intsize()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:RegionIndexAdd 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:
addAllin interfaceRegionIndex- Parameters:
regions- a collections of regions
-
bias
public void bias(com.sk89q.worldedit.math.BlockVector2 chunkPosition)Description copied from interface:RegionIndexBias the given chunk for faster lookups (put it in a hash table, etc.).Implementations may choose to do nothing.
- Specified by:
biasin interfaceRegionIndex- Parameters:
chunkPosition- the chunk position
-
biasAll
Description copied from interface:RegionIndexBias the given chunk for faster lookups (put it in a hash table, etc.).Implementations may choose to do nothing.
- Specified by:
biasAllin interfaceRegionIndex- Parameters:
chunkPositions- the chunk position
-
forget
public void forget(com.sk89q.worldedit.math.BlockVector2 chunkPosition)Description copied from interface:RegionIndexNo longer bias the given chunk for faster lookup.- Specified by:
forgetin interfaceRegionIndex- Parameters:
chunkPosition- the chunk position
-
forgetAll
public void forgetAll()Description copied from interface:RegionIndexClearly all extra cache data created by any calls toRegionIndex.bias(BlockVector2).- Specified by:
forgetAllin interfaceRegionIndex
-
add
Description copied from interface:RegionIndexAdd 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:
addin interfaceRegionIndex- Parameters:
region- the region
-
remove
Description copied from interface:RegionIndexRemove a region from the index with the given name.- Specified by:
removein 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:RegionIndexTest whether the index contains a region named by the given name (equality determined usingNormal).- Specified by:
containsin interfaceRegionIndex- Parameters:
id- the name of the region- Returns:
- true if the index contains the region
-
get
Description copied from interface:RegionIndexGet the region named by the given name (equality determined usingNormal).- Specified by:
getin interfaceRegionIndex- Parameters:
id- the name of the region- Returns:
- a region or
null
-
apply
Description copied from interface:RegionIndexApply the given predicate to all the regions in the index until there are no more regions or the predicate returns false.- Specified by:
applyin 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:RegionIndexApply the given predicate to all regions that contain the given position until there are no more regions or the predicate returns false.- Specified by:
applyContainingin interfaceRegionIndex- Parameters:
position- the positionconsumer- a predicate that returns true to continue iterating
-
applyIntersecting
Description copied from interface:RegionIndexApply the given predicate to all regions that intersect the given region until there are no more regions or the predicate returns false.- Specified by:
applyIntersectingin interfaceRegionIndex- Parameters:
region- the intersecting regionconsumer- a predicate that returns true to continue iterating
-
size
public int size()Description copied from interface:RegionIndexReturn the number of regions in the index.- Specified by:
sizein interfaceRegionIndex- Returns:
- the number of regions
-
getAndClearDifference
Description copied from interface:RegionIndexGet the list of changed or removed regions since last call and clear those lists.- Specified by:
getAndClearDifferencein interfaceRegionIndex- Returns:
- the difference
-
setDirty
Description copied from interface:RegionIndexSet the index to be dirty using the given difference.- Specified by:
setDirtyin interfaceRegionIndex- Parameters:
difference- the difference
-
values
Description copied from interface:RegionIndexGet an unmodifiable collection of regions stored in this index.- Specified by:
valuesin interfaceRegionIndex- Returns:
- a collection of regions
-
isDirty
public boolean isDirty()Description copied from interface:ChangeTrackedTests whether changes have been made.- Specified by:
isDirtyin interfaceChangeTracked- Returns:
- true if changes have been made
-
setDirty
public void setDirty(boolean dirty)Description copied from interface:ChangeTrackedSet whether changes have been made.- Specified by:
setDirtyin interfaceChangeTracked- Parameters:
dirty- a new dirty state
-