Class CoordPackerZone
- All Implemented Interfaces:
Serializable,Iterable<Coord>,Collection<Coord>,ImmutableZone,Zone
public class CoordPackerZone extends Zone.Skeleton implements Collection<Coord>, ImmutableZone
CoordPacker.- Author:
- smelC
- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from interface squidpony.squidgrid.zone.Zone
Zone.Helper, Zone.Skeleton -
Field Summary
-
Constructor Summary
Constructors Constructor Description CoordPackerZone(short[] shorts) -
Method Summary
Modifier and Type Method Description booleanadd(Coord coord)Does nothing (this Zone is immutable).booleanaddAll(Collection<? extends Coord> c)Does nothing (this Zone is immutable).voidclear()Does nothing (this Zone is immutable).booleancontains(int x, int y)booleancontains(Object o)Returns true if this collection contains the specified element.booleancontains(Zone other)booleancontains(Coord c)booleancontainsAll(Collection<?> c)Returns true if this collection contains all of the elements in the specified collection.booleanequals(Object o)CoordPackerZoneexpand(int distance)Expands the area of this Zone in the four cardinal directions, performing the expansion consecutivelydistancetimes.CoordPackerZoneexpand8way(int distance)Expands the area of this Zone in the four cardinal and four diagonal directions, performing the expansion consecutivelydistancetimes.Zoneextend()Gets a new Zone that contains all the Coords inthisplus all neighboring Coords, which can be orthogonally or diagonally adjacent to any Coord this has in it.List<Coord>getAll()Collection<Coord>getExternalBorder()Gets a Collection of Coord values that are not in this Zone, but are adjacent to it, either orthogonally or diagonally.Collection<Coord>getInternalBorder()inthashCode()booleanintersectsWith(Zone other)booleanisEmpty()booleanremove(Object o)Does nothing (this Zone is immutable).booleanremoveAll(Collection<?> c)Does nothing (this Zone is immutable).booleanretainAll(Collection<?> c)Does nothing (this Zone is immutable).intsize()Object[]toArray()Returns an array containing all of the elements in this collection.<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.StringtoString()Zonetranslate(int x, int y)Methods inherited from class squidpony.squidgrid.zone.Zone.Skeleton
getCenter, getDiagonal, getHeight, getWidth, iterator, translate, xBound, yBoundMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
iterator, parallelStream, removeIf, spliterator, stream, toArray
-
Field Details
-
Constructor Details
-
Method Details
-
isEmpty
- Specified by:
isEmptyin interfaceCollection<Coord>- Specified by:
isEmptyin interfaceZone- Returns:
- Whether this zone is empty.
-
contains
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:
containsin interfaceCollection<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
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:
toArrayin interfaceCollection<Coord>- Returns:
- an array containing all of the elements in this collection
-
toArray
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:
toArrayin interfaceCollection<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 collectionNullPointerException- if the specified array is null
-
add
Does nothing (this Zone is immutable).- Specified by:
addin interfaceCollection<Coord>
-
remove
Does nothing (this Zone is immutable).- Specified by:
removein interfaceCollection<Coord>
-
containsAll
Returns true if this collection contains all of the elements in the specified collection.- Specified by:
containsAllin interfaceCollection<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
Does nothing (this Zone is immutable).- Specified by:
addAllin interfaceCollection<Coord>
-
removeAll
Does nothing (this Zone is immutable).- Specified by:
removeAllin interfaceCollection<Coord>
-
retainAll
Does nothing (this Zone is immutable).- Specified by:
retainAllin interfaceCollection<Coord>
-
clear
Does nothing (this Zone is immutable).- Specified by:
clearin interfaceCollection<Coord>
-
size
- Specified by:
sizein interfaceCollection<Coord>- Specified by:
sizein interfaceZone- Overrides:
sizein classZone.Skeleton- Returns:
- The number of cells that this zone contains (the size
Zone.getAll()).
-
contains
- Specified by:
containsin interfaceZone- Overrides:
containsin classZone.Skeleton- Returns:
- Whether this zone contains the coordinate (x,y).
-
contains
- Specified by:
containsin interfaceZone- Overrides:
containsin classZone.Skeleton- Returns:
- Whether this zone contains
c.
-
getAll
-
expand
Description copied from interface:ImmutableZoneExpands the area of this Zone in the four cardinal directions, performing the expansion consecutivelydistancetimes. Does not modify this Zone; returns a new Zone with the requested changes.- Specified by:
expandin interfaceImmutableZone- Parameters:
distance- the amount to expand outward using Manhattan distance (diamond shape)- Returns:
- a freshly-constructed Zone with the requested changes
-
expand8way
Description copied from interface:ImmutableZoneExpands the area of this Zone in the four cardinal and four diagonal directions, performing the expansion consecutivelydistancetimes. Does not modify this Zone; returns a new Zone with the requested changes.- Specified by:
expand8wayin interfaceImmutableZone- Parameters:
distance- the amount to expand outward using Chebyshev distance (square shape)- Returns:
- a freshly-constructed Zone with the requested changes
-
contains
- Specified by:
containsin interfaceZone- Overrides:
containsin classZone.Skeleton- Returns:
- true if all cells of
otherare inthis.
-
intersectsWith
- Specified by:
intersectsWithin interfaceZone- Overrides:
intersectsWithin classZone.Skeleton- Returns:
- true if
thisandotherhave a common cell.
-
extend
Description copied from interface:ZoneGets a new Zone that contains all the Coords inthisplus 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:
extendin interfaceZone- Overrides:
extendin classZone.Skeleton- Returns:
- A variant of
thiswhere cells adjacent tothis(orthogonally or diagonally) have been added (i.e. it'sthisplusZone.getExternalBorder()).
-
getInternalBorder
- Specified by:
getInternalBorderin interfaceZone- Overrides:
getInternalBorderin classZone.Skeleton- Returns:
- Cells in
thisthat are adjacent to a cell not inthis
-
getExternalBorder
Description copied from interface:ZoneGets 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:
getExternalBorderin interfaceZone- Overrides:
getExternalBorderin classZone.Skeleton- Returns:
- Cells adjacent to
this(orthogonally or diagonally) that aren't inthis
-
translate
- Specified by:
translatein interfaceZone- Overrides:
translatein classZone.Skeleton- Returns:
thisshifted by(x,y)
-
toString
-
equals
- Specified by:
equalsin interfaceCollection<Coord>- Overrides:
equalsin classObject
-
hashCode
- Specified by:
hashCodein interfaceCollection<Coord>- Overrides:
hashCodein classObject
-