public class CoordPackerZone extends Zone.Skeleton implements java.util.Collection<Coord>, ImmutableZone
CoordPacker
.Zone.Helper, Zone.Skeleton
Modifier and Type | Field and Description |
---|---|
protected short[] |
shorts |
protected java.util.List<Coord> |
unpacked |
height, width
Constructor and Description |
---|
CoordPackerZone(short[] shorts) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(Coord coord)
Does nothing (this Zone is immutable).
|
boolean |
addAll(java.util.Collection<? extends Coord> c)
Does nothing (this Zone is immutable).
|
void |
clear()
Does nothing (this Zone is immutable).
|
boolean |
contains(Coord c) |
boolean |
contains(int x,
int y) |
boolean |
contains(java.lang.Object o)
Returns true if this collection contains the specified element.
|
boolean |
contains(Zone other) |
boolean |
containsAll(java.util.Collection<?> c)
Returns true if this collection contains all of the elements
in the specified collection.
|
boolean |
equals(java.lang.Object o) |
CoordPackerZone |
expand(int distance)
Expands the area of this Zone in the four cardinal directions, performing the expansion consecutively
distance times. |
CoordPackerZone |
expand8way(int distance)
Expands the area of this Zone in the four cardinal and four diagonal directions, performing the expansion
consecutively
distance times. |
Zone |
extend()
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. |
java.util.List<Coord> |
getAll() |
java.util.Collection<Coord> |
getExternalBorder()
Gets a Collection of Coord values that are not in this Zone, but are
adjacent to it, either orthogonally or diagonally.
|
java.util.Collection<Coord> |
getInternalBorder() |
int |
hashCode() |
boolean |
intersectsWith(Zone other) |
boolean |
isEmpty() |
boolean |
remove(java.lang.Object o)
Does nothing (this Zone is immutable).
|
boolean |
removeAll(java.util.Collection<?> c)
Does nothing (this Zone is immutable).
|
boolean |
retainAll(java.util.Collection<?> c)
Does nothing (this Zone is immutable).
|
int |
size() |
java.lang.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.
|
java.lang.String |
toString() |
Zone |
translate(int x,
int y) |
getCenter, getDiagonal, getHeight, getWidth, iterator, translate, xBound, yBound
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
iterator, parallelStream, removeIf, spliterator, stream
protected final short[] shorts
protected transient java.util.List<Coord> unpacked
public boolean isEmpty()
public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection<Coord>
o
- element whose presence in this collection is to be testedjava.lang.ClassCastException
- if the type of the specified element
is incompatible with this collection
(optional)java.lang.NullPointerException
- if the specified element is null and this
collection does not permit null elements
(optional)public java.lang.Object[] toArray()
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.
toArray
in interface java.util.Collection<Coord>
public <T> T[] toArray(T[] a)
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().
toArray
in interface java.util.Collection<Coord>
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.java.lang.ArrayStoreException
- if the runtime type of the specified array
is not a supertype of the runtime type of every element in
this collectionjava.lang.NullPointerException
- if the specified array is nullpublic boolean add(Coord coord)
add
in interface java.util.Collection<Coord>
public boolean remove(java.lang.Object o)
remove
in interface java.util.Collection<Coord>
public boolean containsAll(java.util.Collection<?> c)
containsAll
in interface java.util.Collection<Coord>
c
- collection to be checked for containment in this collectionjava.lang.ClassCastException
- if the types of one or more elements
in the specified collection are not Coordcontains(Object)
public boolean addAll(java.util.Collection<? extends Coord> c)
addAll
in interface java.util.Collection<Coord>
public boolean removeAll(java.util.Collection<?> c)
removeAll
in interface java.util.Collection<Coord>
public boolean retainAll(java.util.Collection<?> c)
retainAll
in interface java.util.Collection<Coord>
public void clear()
clear
in interface java.util.Collection<Coord>
public int size()
size
in interface java.util.Collection<Coord>
size
in interface Zone
size
in class Zone.Skeleton
Zone.getAll()
).public boolean contains(int x, int y)
contains
in interface Zone
contains
in class Zone.Skeleton
public boolean contains(Coord c)
contains
in interface Zone
contains
in class Zone.Skeleton
c
.public java.util.List<Coord> getAll()
public CoordPackerZone expand(int distance)
ImmutableZone
distance
times. Does not modify this Zone; returns a new Zone with the requested changes.expand
in interface ImmutableZone
distance
- the amount to expand outward using Manhattan distance (diamond shape)public CoordPackerZone expand8way(int distance)
ImmutableZone
distance
times. Does not modify this Zone; returns a new Zone with the requested changes.expand8way
in interface ImmutableZone
distance
- the amount to expand outward using Chebyshev distance (square shape)public boolean contains(Zone other)
contains
in interface Zone
contains
in class Zone.Skeleton
other
are in this
.public boolean intersectsWith(Zone other)
intersectsWith
in interface Zone
intersectsWith
in class Zone.Skeleton
this
and other
have a common cell.public Zone extend()
Zone
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.extend
in interface Zone
extend
in class Zone.Skeleton
this
where cells adjacent to this
(orthogonally or diagonally) have been added (i.e. it's this
plus Zone.getExternalBorder()
).public java.util.Collection<Coord> getInternalBorder()
getInternalBorder
in interface Zone
getInternalBorder
in class Zone.Skeleton
this
that are adjacent to a cell not in
this
public java.util.Collection<Coord> getExternalBorder()
Zone
getExternalBorder
in interface Zone
getExternalBorder
in class Zone.Skeleton
this
(orthogonally or diagonally) that
aren't in this
public Zone translate(int x, int y)
translate
in interface Zone
translate
in class Zone.Skeleton
this
shifted by (x,y)
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in interface java.util.Collection<Coord>
equals
in class java.lang.Object
public int hashCode()
hashCode
in interface java.util.Collection<Coord>
hashCode
in class java.lang.Object
Copyright © Eben Howard 2012–2022. All rights reserved.