net.walend.grid
Class MapGrid2D

java.lang.Object
  |
  +--net.walend.grid.AbstractMapGrid2D
        |
        +--net.walend.grid.MapGrid2D
All Implemented Interfaces:
java.util.Collection, Grid, Grid2D, HasState, net.walend.enum.Immutable, java.io.Serializable

public final class MapGrid2D
extends AbstractMapGrid2D
implements java.io.Serializable, net.walend.enum.Immutable

Grid2D is a simple two-dimensional Grid.

Author:
David Walend dfw1@cornell.edu
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class net.walend.grid.AbstractMapGrid2D
 
Nested classes inherited from class net.walend.grid.Grid2D
Grid2D.Dimensions2D
 
Field Summary
 
Fields inherited from class net.walend.grid.AbstractMapGrid2D
 
Fields inherited from interface net.walend.grid.Grid2D
DIMENSIONS2D, I, J
 
Constructor Summary
MapGrid2D(Address2D maxAddress, Grid2D grid)
           
MapGrid2D(Grid2D grid)
           
MapGrid2D(int sizeI, int sizeJ, Grid2D grid)
           
 
Method Summary
 boolean add(java.lang.Object o)
          Throws an UnsupportedOperationException.
 boolean addAll(java.util.Collection c)
          Throws an UnsupportedOperationException.
 void clear()
          Replaces all of the elements with fill.
 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.
 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).
 IndexedIterator stripeIterator(Address address, Dimension dimensionToScan)
          Returns an Iterator accross the stripe at Address, through dimensionToScan.
 
Methods inherited from class net.walend.grid.AbstractMapGrid2D
addressIterator, addressOf, checkAddress, contains, containsAddress, containsAddress, containsAll, containsDimension, get, get, getDimensions, getFillObject, getPrincipleInterface, isEmpty, maxAddress, put, put, sameGrid2DAs, sameStateAs, size, sizeI, sizeJ, take, take, toArray, toArray, 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
 

Constructor Detail

MapGrid2D

public MapGrid2D(Grid2D grid)
          throws OffGridException

MapGrid2D

public MapGrid2D(Address2D maxAddress,
                 Grid2D grid)
          throws OffGridException

MapGrid2D

public MapGrid2D(int sizeI,
                 int sizeJ,
                 Grid2D grid)
          throws OffGridException
Method Detail

iterator

public java.util.Iterator iterator()
Returns an iterator over the elements in this collection. There are no guarantees concerning the order in which the elements are returned.

Specified by:
iterator in interface java.util.Collection
Overrides:
iterator in class AbstractMapGrid2D
Returns:
an Iterator over the elements in this collection

add

public boolean add(java.lang.Object o)
Throws an UnsupportedOperationException.

Specified by:
add in interface java.util.Collection
Overrides:
add in class AbstractMapGrid2D

remove

public boolean remove(java.lang.Object o)
Removes a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if this collection contains one or more such elements. Returns true if this collection contained the specified element (or equivalently, if this collection changed as a result of the call).

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.

Specified by:
remove in interface java.util.Collection
Overrides:
remove in class AbstractMapGrid2D
Parameters:
o - element to be removed from this collection, if present.
Returns:
true if this collection changed as a result of the call

addAll

public boolean addAll(java.util.Collection c)
Throws an UnsupportedOperationException.

Specified by:
addAll in interface java.util.Collection
Overrides:
addAll in class AbstractMapGrid2D

removeAll

public boolean removeAll(java.util.Collection c)
Removes all this collection's elements that are also contained in the specified collection (optional operation). After this call returns, this collection will contain no elements in common with the specified collection, unless that collection contained the fill object.

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.

Specified by:
removeAll in interface java.util.Collection
Overrides:
removeAll in class AbstractMapGrid2D
Parameters:
c - elements to be removed from this collection.
Returns:
true if this collection changed as a result of the call
Throws:
java.lang.UnsupportedOperationException - if the removeAll method is not supported by this collection.
See Also:
remove(Object), AbstractMapGrid2D.contains(Object)

retainAll

public boolean retainAll(java.util.Collection c)
Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection, except for the fill object.

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.

Specified by:
retainAll in interface java.util.Collection
Overrides:
retainAll in class AbstractMapGrid2D
Parameters:
c - elements to be retained in this collection.
Returns:
true if this collection changed as a result of the call
Throws:
java.lang.UnsupportedOperationException - if the retainAll method is not supported by this Collection.
See Also:
remove(Object), AbstractMapGrid2D.contains(Object)

clear

public void clear()
Replaces all of the elements with fill. Removes all of the elements from this collection (optional operation). This collection will be empty after this method returns unless it throws an exception.

Specified by:
clear in interface java.util.Collection
Overrides:
clear in class AbstractMapGrid2D
Throws:
java.lang.UnsupportedOperationException - if the clear method is not supported by this collection.

stripeIterator

public IndexedIterator stripeIterator(Address address,
                                      Dimension dimensionToScan)
Returns an Iterator accross the stripe at Address, through dimensionToScan. This iterator is remarkably robust and will not throw ConcurrentModificationExceptions.

Specified by:
stripeIterator in interface Grid
Overrides:
stripeIterator in class AbstractMapGrid2D

iStripeIterator

public IndexedIterator iStripeIterator(int i)
                                throws OffGridException
Returns an iterator accross zs at i.

Specified by:
iStripeIterator in interface Grid2D
Overrides:
iStripeIterator in class AbstractMapGrid2D
OffGridException

jStripeIterator

public IndexedIterator jStripeIterator(int j)
                                throws OffGridException
Returns an iterator accross is at j.

Specified by:
jStripeIterator in interface Grid2D
Overrides:
jStripeIterator in class AbstractMapGrid2D
OffGridException


Copyright (c) 2001, 2002, David Walend