Class RegionMap<V>

java.lang.Object
squidpony.squidmath.OrderedMap<short[],​V>
squidpony.squidmath.RegionMap<V>
All Implemented Interfaces:
Serializable, Cloneable, Map<short[],​V>, SortedMap<short[],​V>

public class RegionMap<V>
extends OrderedMap<short[],​V>
implements Serializable
A small extension of OrderedMap that specifically handles short[] regions as produced by CoordPacker. The methods allAt(int, int), containsRegion(short[]), and regionsContaining(int, int) are added here, and the minor extra work needed to handle array keys in OrderedMap is taken care of automatically. toString() also produces nicer output by default for this usage, with the keys printed in a usable way. Created by Tommy Ettinger on 11/24/2016.
See Also:
Serialized Form
  • Constructor Details

    • RegionMap

      public RegionMap​(int expected, float f)
    • RegionMap

      public RegionMap​(int expected)
      Creates a new RegionMap with 0.75f as load factor.
      Parameters:
      expected - the expected number of elements in the RegionMap.
    • RegionMap

      public RegionMap()
      Creates a new RegionMap with initial expected 16 entries and 0.75f as load factor.
    • RegionMap

      public RegionMap​(Map<short[],​? extends V> m, float f)
      Creates a new RegionMap copying a given one.
      Parameters:
      m - a Map to be copied into the new RegionMap.
      f - the load factor.
    • RegionMap

      public RegionMap​(Map<short[],​? extends V> m)
      Creates a new RegionMap with 0.75f as load factor copying a given one.
      Parameters:
      m - a Map to be copied into the new RegionMap.
    • RegionMap

      public RegionMap​(short[][] keyArray, V[] valueArray, float f)
      Creates a new RegionMap using the elements of two parallel arrays.
      Parameters:
      keyArray - the array of keys of the new RegionMap.
      valueArray - the array of corresponding values in the new RegionMap.
      f - the load factor.
      Throws:
      IllegalArgumentException - if k and v have different lengths.
    • RegionMap

      public RegionMap​(Collection<short[]> keyColl, Collection<V> valueColl, float f)
      Creates a new RegionMap using the elements of two parallel arrays.
      Parameters:
      keyColl - the collection of keys of the new RegionMap.
      valueColl - the collection of corresponding values in the new RegionMap.
      f - the load factor.
      Throws:
      IllegalArgumentException - if k and v have different lengths.
    • RegionMap

      public RegionMap​(short[][] keyArray, V[] valueArray)
      Creates a new RegionMap with 0.75f as load factor using the elements of two parallel arrays.
      Parameters:
      keyArray - the array of keys of the new RegionMap.
      valueArray - the array of corresponding values in the new RegionMap.
      Throws:
      IllegalArgumentException - if k and v have different lengths.
  • Method Details

    • allAt

      public ArrayList<V> allAt​(int x, int y)
      Gets a List of all values associated with regions containing a given x,y point.
      Parameters:
      x - the x coordinate of the point in question
      y - the y coordinate of the point in question
      Returns:
      an ArrayList of all V values corresponding to regions containing the given x,y point.
    • containsRegion

      public boolean containsRegion​(short[] region)
      Checks if a region, stored as packed data (possibly from CoordPacker or this class) overlaps with regions stored in this object as keys. Returns true if there is any overlap, false otherwise
      Parameters:
      region - the packed region to check for overlap with regions this stores values for
      Returns:
      true if the region overlaps at all, false otherwise
    • regionsContaining

      public OrderedSet<short[]> regionsContaining​(int x, int y)
      Gets a List of all regions containing a given x,y point.
      Parameters:
      x - the x coordinate of the point in question
      y - the y coordinate of the point in question
      Returns:
      an ArrayList of all regions in this data structure containing the given x,y point.
    • toString

      public String toString​(String separator)
    • toString

      public String toString()
      Overrides:
      toString in class OrderedMap<short[],​V>