Class ChunkHashTable

java.lang.Object
com.sk89q.worldguard.protection.managers.index.ChunkHashTable
All Implemented Interfaces:
ConcurrentRegionIndex, RegionIndex, ChangeTracked

public class ChunkHashTable extends Object implements ConcurrentRegionIndex
Maintains a hash table for each chunk containing a list of regions that are contained within that chunk, allowing for fast spatial lookup.
  • Constructor Details

    • ChunkHashTable

      public ChunkHashTable(RegionIndex index, String name)
      Create a new instance.
      Parameters:
      index - the index
      name -
  • Method Details

    • awaitCompletion

      public boolean awaitCompletion(long timeout, TimeUnit unit) throws InterruptedException
      Waits until all currently executing background tasks complete.
      Parameters:
      timeout - the maximum time to wait
      unit - the time unit of the timeout argument
      Returns:
      true if this executor terminated and false if the timeout elapsed before termination
      Throws:
      InterruptedException - on interruption
    • 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 interface RegionIndex
      Parameters:
      chunkPosition - the chunk position
    • biasAll

      public void biasAll(Collection<com.sk89q.worldedit.math.BlockVector2> chunkPositions)
      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 interface RegionIndex
      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 interface RegionIndex
      Parameters:
      chunkPosition - the chunk position
    • forgetAll

      public void forgetAll()
      Description copied from interface: RegionIndex
      Clearly all extra cache data created by any calls to RegionIndex.bias(BlockVector2).
      Specified by:
      forgetAll in interface RegionIndex
    • add

      public void add(ProtectedRegion region)
      Description copied from interface: RegionIndex
      Add a region to this index, replacing any existing one with the same name (equality determined using Normal).

      The parents of the region will also be added to the index.

      Specified by:
      add in interface RegionIndex
      Parameters:
      region - the region
    • addAll

      public void addAll(Collection<ProtectedRegion> regions)
      Description copied from interface: RegionIndex
      Add a list of regions to this index, replacing any existing one with the same name (equality determined using Normal).

      The parents of the region will also be added to the index.

      Specified by:
      addAll in interface RegionIndex
      Parameters:
      regions - a collections of regions
    • remove

      public Set<ProtectedRegion> remove(String id, RemovalStrategy strategy)
      Description copied from interface: RegionIndex
      Remove a region from the index with the given name.
      Specified by:
      remove in interface RegionIndex
      Parameters:
      id - the name of the region
      strategy - what to do with children
      Returns:
      a list of removed regions where the first entry is the region specified by id
    • contains

      public boolean contains(String id)
      Description copied from interface: RegionIndex
      Test whether the index contains a region named by the given name (equality determined using Normal).
      Specified by:
      contains in interface RegionIndex
      Parameters:
      id - the name of the region
      Returns:
      true if the index contains the region
    • get

      @Nullable public ProtectedRegion get(String id)
      Description copied from interface: RegionIndex
      Get the region named by the given name (equality determined using Normal).
      Specified by:
      get in interface RegionIndex
      Parameters:
      id - the name of the region
      Returns:
      a region or null
    • apply

      public void apply(Predicate<ProtectedRegion> consumer)
      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 interface RegionIndex
      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 interface RegionIndex
      Parameters:
      position - the position
      consumer - a predicate that returns true to continue iterating
    • applyIntersecting

      public void applyIntersecting(ProtectedRegion region, Predicate<ProtectedRegion> consumer)
      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 interface RegionIndex
      Parameters:
      region - the intersecting region
      consumer - 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 interface RegionIndex
      Returns:
      the number of regions
    • getAndClearDifference

      public RegionDifference 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 interface RegionIndex
      Returns:
      the difference
    • setDirty

      public void setDirty(RegionDifference difference)
      Description copied from interface: RegionIndex
      Set the index to be dirty using the given difference.
      Specified by:
      setDirty in interface RegionIndex
      Parameters:
      difference - the difference
    • values

      public Collection<ProtectedRegion> values()
      Description copied from interface: RegionIndex
      Get an unmodifiable collection of regions stored in this index.
      Specified by:
      values in interface RegionIndex
      Returns:
      a collection of regions
    • isDirty

      public boolean isDirty()
      Description copied from interface: ChangeTracked
      Tests whether changes have been made.
      Specified by:
      isDirty in interface ChangeTracked
      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 interface ChangeTracked
      Parameters:
      dirty - a new dirty state