Class CoordPackerZone

java.lang.Object
squidpony.squidgrid.zone.Zone.Skeleton
squidpony.squidgrid.zone.CoordPackerZone
All Implemented Interfaces:
Serializable, Iterable<Coord>, Collection<Coord>, ImmutableZone, Zone

public class CoordPackerZone
extends Zone.Skeleton
implements Collection<Coord>, ImmutableZone
A zone constructed by CoordPacker.
Author:
smelC
See Also:
Serialized Form
  • Field Details

  • Constructor Details

  • Method Details

    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<Coord>
      Specified by:
      isEmpty in interface Zone
      Returns:
      Whether this zone is empty.
    • contains

      public boolean contains​(Object o)
      Returns true if this collection contains the specified element. More formally, returns true if and only if this collection contains at least one element e such that (o==null ? e==null : o.equals(e)).
      Specified by:
      contains in interface Collection<Coord>
      Parameters:
      o - element whose presence in this collection is to be tested
      Returns:
      true if this collection contains the specified element
      Throws:
      ClassCastException - if the type of the specified element is incompatible with this collection (optional)
      NullPointerException - if the specified element is null and this collection does not permit null elements (optional)
    • toArray

      public Object[] toArray()
      Returns an array containing all of the elements in this collection. If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

      The returned array will be "safe" in that no references to it are maintained by this collection. (In other words, this method must allocate a new array even if this collection is backed by an array). The caller is thus free to modify the returned array.

      This method acts as bridge between array-based and collection-based APIs.

      Specified by:
      toArray in interface Collection<Coord>
      Returns:
      an array containing all of the elements in this collection
    • toArray

      public <T> T[] toArray​(T[] a)
      Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. If the collection fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this collection.

      If this collection fits in the specified array with room to spare (i.e., the array has more elements than this collection), the element in the array immediately following the end of the collection is set to null. (This is useful in determining the length of this collection only if the caller knows that this collection does not contain any null elements.)

      If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

      Like the toArray() method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs.

      Suppose x is a collection known to contain only strings. The following code can be used to dump the collection into a newly allocated array of String:

           String[] y = x.toArray(new String[0]);

      Note that toArray(new Object[0]) is identical in function to toArray().

      Specified by:
      toArray in interface Collection<Coord>
      Parameters:
      a - the array into which the elements of this collection are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
      Returns:
      an array containing all of the elements in this collection
      Throws:
      ArrayStoreException - if the runtime type of the specified array is not a supertype of the runtime type of every element in this collection
      NullPointerException - if the specified array is null
    • add

      public boolean add​(Coord coord)
      Does nothing (this Zone is immutable).
      Specified by:
      add in interface Collection<Coord>
    • remove

      public boolean remove​(Object o)
      Does nothing (this Zone is immutable).
      Specified by:
      remove in interface Collection<Coord>
    • containsAll

      public boolean containsAll​(Collection<?> c)
      Returns true if this collection contains all of the elements in the specified collection.
      Specified by:
      containsAll in interface Collection<Coord>
      Parameters:
      c - collection to be checked for containment in this collection
      Returns:
      true if this collection contains all of the elements in the specified collection
      Throws:
      ClassCastException - if the types of one or more elements in the specified collection are not Coord
      See Also:
      contains(Object)
    • addAll

      public boolean addAll​(Collection<? extends Coord> c)
      Does nothing (this Zone is immutable).
      Specified by:
      addAll in interface Collection<Coord>
    • removeAll

      public boolean removeAll​(Collection<?> c)
      Does nothing (this Zone is immutable).
      Specified by:
      removeAll in interface Collection<Coord>
    • retainAll

      public boolean retainAll​(Collection<?> c)
      Does nothing (this Zone is immutable).
      Specified by:
      retainAll in interface Collection<Coord>
    • clear

      public void clear()
      Does nothing (this Zone is immutable).
      Specified by:
      clear in interface Collection<Coord>
    • size

      public int size()
      Specified by:
      size in interface Collection<Coord>
      Specified by:
      size in interface Zone
      Overrides:
      size in class Zone.Skeleton
      Returns:
      The number of cells that this zone contains (the size Zone.getAll()).
    • contains

      public boolean contains​(int x, int y)
      Specified by:
      contains in interface Zone
      Overrides:
      contains in class Zone.Skeleton
      Returns:
      Whether this zone contains the coordinate (x,y).
    • contains

      public boolean contains​(Coord c)
      Specified by:
      contains in interface Zone
      Overrides:
      contains in class Zone.Skeleton
      Returns:
      Whether this zone contains c.
    • getAll

      public List<Coord> getAll()
      Specified by:
      getAll in interface Zone
      Returns:
      All cells in this zone.
    • expand

      public CoordPackerZone expand​(int distance)
      Description copied from interface: ImmutableZone
      Expands the area of this Zone in the four cardinal directions, performing the expansion consecutively distance times. Does not modify this Zone; returns a new Zone with the requested changes.
      Specified by:
      expand in interface ImmutableZone
      Parameters:
      distance - the amount to expand outward using Manhattan distance (diamond shape)
      Returns:
      a freshly-constructed Zone with the requested changes
    • expand8way

      public CoordPackerZone expand8way​(int distance)
      Description copied from interface: ImmutableZone
      Expands the area of this Zone in the four cardinal and four diagonal directions, performing the expansion consecutively distance times. Does not modify this Zone; returns a new Zone with the requested changes.
      Specified by:
      expand8way in interface ImmutableZone
      Parameters:
      distance - the amount to expand outward using Chebyshev distance (square shape)
      Returns:
      a freshly-constructed Zone with the requested changes
    • contains

      public boolean contains​(Zone other)
      Specified by:
      contains in interface Zone
      Overrides:
      contains in class Zone.Skeleton
      Returns:
      true if all cells of other are in this.
    • intersectsWith

      public boolean intersectsWith​(Zone other)
      Specified by:
      intersectsWith in interface Zone
      Overrides:
      intersectsWith in class Zone.Skeleton
      Returns:
      true if this and other have a common cell.
    • extend

      public Zone extend()
      Description copied from interface: Zone
      Gets a new Zone that contains all the Coords in this plus all neighboring Coords, which can be orthogonally or diagonally adjacent to any Coord this has in it. Related to the expand() methods in CoordPacker and GreasedRegion, but guaranteed to use 8-way adjacency and to return a new Zone.
      Specified by:
      extend in interface Zone
      Overrides:
      extend in class Zone.Skeleton
      Returns:
      A variant of this where cells adjacent to this (orthogonally or diagonally) have been added (i.e. it's this plus Zone.getExternalBorder()).
    • getInternalBorder

      Specified by:
      getInternalBorder in interface Zone
      Overrides:
      getInternalBorder in class Zone.Skeleton
      Returns:
      Cells in this that are adjacent to a cell not in this
    • getExternalBorder

      Description copied from interface: Zone
      Gets a Collection of Coord values that are not in this Zone, but are adjacent to it, either orthogonally or diagonally. Related to the fringe() methods in CoordPacker and GreasedRegion, but guaranteed to use 8-way adjacency and to return a new Collection of Coord.
      Specified by:
      getExternalBorder in interface Zone
      Overrides:
      getExternalBorder in class Zone.Skeleton
      Returns:
      Cells adjacent to this (orthogonally or diagonally) that aren't in this
    • translate

      public Zone translate​(int x, int y)
      Specified by:
      translate in interface Zone
      Overrides:
      translate in class Zone.Skeleton
      Returns:
      this shifted by (x,y)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals​(Object o)
      Specified by:
      equals in interface Collection<Coord>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Collection<Coord>
      Overrides:
      hashCode in class Object