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 boolean
add(Coord coord)
Does nothing (this Zone is immutable).boolean
addAll(Collection<? extends Coord> c)
Does nothing (this Zone is immutable).void
clear()
Does nothing (this Zone is immutable).boolean
contains(int x, int y)
boolean
contains(Object o)
Returns true if this collection contains the specified element.boolean
contains(Zone other)
boolean
contains(Coord c)
boolean
containsAll(Collection<?> c)
Returns true if this collection contains all of the elements in the specified collection.boolean
equals(Object o)
CoordPackerZone
expand(int distance)
Expands the area of this Zone in the four cardinal directions, performing the expansion consecutivelydistance
times.CoordPackerZone
expand8way(int distance)
Expands the area of this Zone in the four cardinal and four diagonal directions, performing the expansion consecutivelydistance
times.Zone
extend()
Gets a new Zone that contains all the Coords inthis
plus 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()
int
hashCode()
boolean
intersectsWith(Zone other)
boolean
isEmpty()
boolean
remove(Object o)
Does nothing (this Zone is immutable).boolean
removeAll(Collection<?> c)
Does nothing (this Zone is immutable).boolean
retainAll(Collection<?> c)
Does nothing (this Zone is immutable).int
size()
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.String
toString()
Zone
translate(int x, int y)
Methods inherited from class squidpony.squidgrid.zone.Zone.Skeleton
getCenter, getDiagonal, getHeight, getWidth, iterator, translate, xBound, yBound
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
iterator, parallelStream, removeIf, spliterator, stream, toArray
-
Field Details
-
Constructor Details
-
Method Details
-
isEmpty
- Specified by:
isEmpty
in interfaceCollection<Coord>
- Specified by:
isEmpty
in 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:
contains
in 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:
toArray
in 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:
toArray
in 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:
add
in interfaceCollection<Coord>
-
remove
Does nothing (this Zone is immutable).- Specified by:
remove
in interfaceCollection<Coord>
-
containsAll
Returns true if this collection contains all of the elements in the specified collection.- Specified by:
containsAll
in 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:
addAll
in interfaceCollection<Coord>
-
removeAll
Does nothing (this Zone is immutable).- Specified by:
removeAll
in interfaceCollection<Coord>
-
retainAll
Does nothing (this Zone is immutable).- Specified by:
retainAll
in interfaceCollection<Coord>
-
clear
Does nothing (this Zone is immutable).- Specified by:
clear
in interfaceCollection<Coord>
-
size
- Specified by:
size
in interfaceCollection<Coord>
- Specified by:
size
in interfaceZone
- Overrides:
size
in classZone.Skeleton
- Returns:
- The number of cells that this zone contains (the size
Zone.getAll()
).
-
contains
- Specified by:
contains
in interfaceZone
- Overrides:
contains
in classZone.Skeleton
- Returns:
- Whether this zone contains the coordinate (x,y).
-
contains
- Specified by:
contains
in interfaceZone
- Overrides:
contains
in classZone.Skeleton
- Returns:
- Whether this zone contains
c
.
-
getAll
-
expand
Description copied from interface:ImmutableZone
Expands the area of this Zone in the four cardinal directions, performing the expansion consecutivelydistance
times. Does not modify this Zone; returns a new Zone with the requested changes.- Specified by:
expand
in 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:ImmutableZone
Expands the area of this Zone in the four cardinal and four diagonal directions, performing the expansion consecutivelydistance
times. Does not modify this Zone; returns a new Zone with the requested changes.- Specified by:
expand8way
in 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:
contains
in interfaceZone
- Overrides:
contains
in classZone.Skeleton
- Returns:
- true if all cells of
other
are inthis
.
-
intersectsWith
- Specified by:
intersectsWith
in interfaceZone
- Overrides:
intersectsWith
in classZone.Skeleton
- Returns:
- true if
this
andother
have a common cell.
-
extend
Description copied from interface:Zone
Gets a new Zone that contains all the Coords inthis
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 interfaceZone
- Overrides:
extend
in classZone.Skeleton
- Returns:
- A variant of
this
where cells adjacent tothis
(orthogonally or diagonally) have been added (i.e. it'sthis
plusZone.getExternalBorder()
).
-
getInternalBorder
- Specified by:
getInternalBorder
in interfaceZone
- Overrides:
getInternalBorder
in classZone.Skeleton
- Returns:
- Cells in
this
that are adjacent to a cell not inthis
-
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 interfaceZone
- Overrides:
getExternalBorder
in classZone.Skeleton
- Returns:
- Cells adjacent to
this
(orthogonally or diagonally) that aren't inthis
-
translate
- Specified by:
translate
in interfaceZone
- Overrides:
translate
in classZone.Skeleton
- Returns:
this
shifted by(x,y)
-
toString
-
equals
- Specified by:
equals
in interfaceCollection<Coord>
- Overrides:
equals
in classObject
-
hashCode
- Specified by:
hashCode
in interfaceCollection<Coord>
- Overrides:
hashCode
in classObject
-