|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.walend.grid.AbstractArrayGrid2D
Grid2D is a simple two-dimensional Grid.
Nested Class Summary | |
private class |
AbstractArrayGrid2D.AddressIterator
|
private class |
AbstractArrayGrid2D.IStripeIterator
|
private class |
AbstractArrayGrid2D.JStripeIterator
|
private class |
AbstractArrayGrid2D.WholeGridIterator
|
Nested classes inherited from class net.walend.grid.Grid2D |
Grid2D.Dimensions2D |
Field Summary | |
private java.lang.Object[][] |
array
|
private java.lang.Object |
fill
|
private Address2D |
maxAddress
|
Fields inherited from interface net.walend.grid.Grid2D |
DIMENSIONS2D, I, J |
Constructor Summary | |
protected |
AbstractArrayGrid2D(Address2D maxAddress)
|
protected |
AbstractArrayGrid2D(Address2D maxAddress,
Grid2D grid)
|
protected |
AbstractArrayGrid2D(Address2D maxAddress,
java.lang.Object fill)
|
protected |
AbstractArrayGrid2D(Grid2D grid)
|
protected |
AbstractArrayGrid2D(int sizeI,
int sizeJ)
|
protected |
AbstractArrayGrid2D(int sizeI,
int sizeJ,
Grid2D grid)
|
protected |
AbstractArrayGrid2D(int sizeI,
int sizeJ,
java.lang.Object fill)
|
Method Summary | |
boolean |
add(java.lang.Object o)
Throws an UnsupportedOperationException. |
boolean |
addAll(java.util.Collection c)
Throws an UnsupportedOperationException. |
java.util.Iterator |
addressIterator()
Returns an Iterator of all the addresses in the grid. |
Address |
addressOf(java.lang.Object object)
Returns an Address in the Grid occupied by object. |
private static Address2D |
castAddress(Address address)
|
protected void |
checkAddress(int i,
int j)
|
void |
clear()
Replaces all of the elements with fill. |
boolean |
contains(java.lang.Object o)
Returns true if this collection contains the specified element. |
boolean |
containsAddress(Address address)
Returns true if the address is on this Grid. |
boolean |
containsAddress(int i,
int j)
Return true if the i,j address is on the Grid. |
boolean |
containsAll(java.util.Collection c)
Returns true if this collection contains all of the elements in the specified collection. |
boolean |
containsDimension(Dimension dimension)
Returns true if dimension is used in this Grid. |
private void |
createArray(int sizeI,
int sizeJ)
|
private void |
fill(java.lang.Object fill)
|
java.lang.Object |
get(Address address)
Return the Object at address. |
java.lang.Object |
get(int i,
int j)
Returns the object in the grid at i,j. |
net.walend.enum.Enum |
getDimensions()
Returns the Dimensions enumerated type |
java.lang.Object |
getFillObject()
Return the fill object for this grid. |
java.lang.Class |
getPrincipleInterface()
Returns the class's principle interface for state comparisons, net.walend.grid.Grid2D. |
boolean |
isEmpty()
Returns true if this collection contains no elements. |
IndexedIterator |
iStripeIterator(int i)
Returns an iterator accross zs at i. |
java.util.Iterator |
iterator()
Returns an iterator over the elements in this collection. |
IndexedIterator |
jStripeIterator(int j)
Returns an iterator accross is at j. |
Address |
maxAddress()
Return the address furthest from the origin for this grid. |
protected java.lang.Object |
put(Address address,
java.lang.Object object)
Replace the Object at address with object. |
protected java.lang.Object |
put(int i,
int j,
java.lang.Object object)
Replaces the object at i,j with object. |
boolean |
remove(java.lang.Object o)
Removes a single instance of the specified element from this collection, if it is present (optional operation). |
boolean |
removeAll(java.util.Collection c)
Removes all this collection's elements that are also contained in the specified collection (optional operation). |
boolean |
retainAll(java.util.Collection c)
Retains only the elements in this collection that are contained in the specified collection (optional operation). |
boolean |
sameGrid2DAs(Grid2D grid)
If this has the same contents as grid in the same spots, returns true. |
boolean |
sameStateAs(HasState victim)
If two HasStates have the same internal state, return true. |
int |
size()
Returns the number of elements in this collection. |
int |
sizeI()
Return the size of the grid in I. |
int |
sizeJ()
Return the size of the grid in J. |
IndexedIterator |
stripeIterator(Address address,
Dimension dimensionToScan)
Returns an Iterator accross the stripe at Address, through dimensionToScan. |
protected java.lang.Object |
take(Address address)
Replace the Object at Address with fill. |
protected java.lang.Object |
take(int i,
int j)
Replaces the object at i,j with fill. |
java.lang.Object[] |
toArray()
Returns an array containing all of the elements in this collection. |
java.lang.Object[] |
toArray(java.lang.Object[] 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()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Collection |
equals, hashCode |
Field Detail |
private java.lang.Object[][] array
private java.lang.Object fill
private Address2D maxAddress
Constructor Detail |
protected AbstractArrayGrid2D(int sizeI, int sizeJ, java.lang.Object fill) throws OffGridException
protected AbstractArrayGrid2D(int sizeI, int sizeJ) throws OffGridException
protected AbstractArrayGrid2D(Address2D maxAddress) throws OffGridException
protected AbstractArrayGrid2D(Address2D maxAddress, java.lang.Object fill) throws OffGridException
protected AbstractArrayGrid2D(Grid2D grid) throws OffGridException
protected AbstractArrayGrid2D(Address2D maxAddress, Grid2D grid) throws OffGridException
protected AbstractArrayGrid2D(int sizeI, int sizeJ, Grid2D grid) throws OffGridException
Method Detail |
private void createArray(int sizeI, int sizeJ)
private void fill(java.lang.Object fill)
private static Address2D castAddress(Address address)
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.Class getPrincipleInterface()
getPrincipleInterface
in interface HasState
public boolean sameStateAs(HasState victim)
For objects with subobjects, Generally this method should only return true if the internal objects are equal. Implement a contentsHaveSameState() method to determine if the contents have the same state.
sameStateAs
in interface HasState
public int size()
I've decided to count nulls as elements in Grids, so this returns sizeI()*sizeJ().
size
in interface java.util.Collection
public boolean isEmpty()
Since nulls count as values, this method would only return true for a Grid with no elements.
isEmpty
in interface java.util.Collection
public boolean contains(java.lang.Object o)
This method scans the entire array before returning false.
contains
in interface java.util.Collection
o
- element whose presence in this collection is to be tested.
public java.util.Iterator iterator()
iterator
in interface java.util.Collection
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
public java.lang.Object[] toArray(java.lang.Object[] 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 l is a List known to contain only strings. The following code can be used to dump the list into a newly allocated array of String:
String[] x = (String[]) v.toArray(new String[0]);
Note that toArray(new Object[0]) is identical in function to toArray().
toArray
in interface java.util.Collection
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
- the runtime type of the specified array is
not a supertype of the runtime type of every element in this
collection.public boolean add(java.lang.Object o)
add
in interface java.util.Collection
public boolean remove(java.lang.Object o)
This method has to scan the array to find the element to remove.
Removing the fill object always returns false. Either the Grid doesn't contain the object, or removing one (replacing it with the fill object) won't change the Grid.
remove
in interface java.util.Collection
o
- element to be removed from this collection, if present.
public boolean containsAll(java.util.Collection c)
Dangerously inefficient code. O(ixjxc.size()). Use something else.
containsAll
in interface java.util.Collection
c
- collection to be checked for containment in this collection.
contains(Object)
public boolean addAll(java.util.Collection c)
addAll
in interface java.util.Collection
public boolean removeAll(java.util.Collection c)
Because this method replaces every object it removes with the fill object, putting the fill object in the collection won't get rid of it.
removeAll
in interface java.util.Collection
c
- elements to be removed from this collection.
java.lang.UnsupportedOperationException
- if the removeAll method
is not supported by this collection.remove(Object)
,
contains(Object)
public boolean retainAll(java.util.Collection c)
Because this method replaces every object it removes with the fill object, leaving the fill object out of the collection won't get rid of it.
retainAll
in interface java.util.Collection
c
- elements to be retained in this collection.
java.lang.UnsupportedOperationException
- if the retainAll method
is not supported by this Collection.remove(Object)
,
contains(Object)
public void clear()
clear
in interface java.util.Collection
java.lang.UnsupportedOperationException
- if the clear method is
not supported by this collection.public java.lang.Object getFillObject()
getFillObject
in interface Grid
public boolean containsDimension(Dimension dimension)
containsDimension
in interface Grid
public net.walend.enum.Enum getDimensions()
getDimensions
in interface Grid
public Address maxAddress()
maxAddress
in interface Grid
public boolean containsAddress(Address address)
containsAddress
in interface Grid
public java.lang.Object get(Address address) throws OffGridException
get
in interface Grid
OffGridException
public Address addressOf(java.lang.Object object) throws ObjectNotOnGridException
addressOf
in interface Grid
ObjectNotOnGridException
protected java.lang.Object put(Address address, java.lang.Object object) throws OffGridException
OffGridException
protected java.lang.Object take(Address address) throws OffGridException
OffGridException
public IndexedIterator stripeIterator(Address address, Dimension dimensionToScan)
stripeIterator
in interface Grid
public int sizeI()
sizeI
in interface Grid2D
public int sizeJ()
sizeJ
in interface Grid2D
public boolean containsAddress(int i, int j)
containsAddress
in interface Grid2D
protected void checkAddress(int i, int j)
public java.lang.Object get(int i, int j) throws OffGridException
get
in interface Grid2D
OffGridException
protected java.lang.Object take(int i, int j) throws OffGridException
OffGridException
protected java.lang.Object put(int i, int j, java.lang.Object object)
public boolean sameGrid2DAs(Grid2D grid)
sameGrid2DAs
in interface Grid2D
public IndexedIterator iStripeIterator(int i) throws OffGridException
iStripeIterator
in interface Grid2D
OffGridException
public IndexedIterator jStripeIterator(int j) throws OffGridException
jStripeIterator
in interface Grid2D
OffGridException
public java.util.Iterator addressIterator()
addressIterator
in interface Grid
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |