com.eliad.util
Interface CellsSet


public interface CellsSet
extends java.lang.Cloneable, java.io.Serializable

An interface to describe a subset of N2. The word "cell" will be used to denote a point in N2.

Note that, like the Point, Dimension, and Rectangle basic geometry APIs, all symmetric methods take arguments x first, y second.

Invariants:
forall int x >= -1 | forall int y >= -1 | getCellsCount(x, y) >= 0
forall int x >= -1 | forall int y >= 0 | getCellsCount(x, y) <= getCellsCount(x,-1)
forall int y >= -1 | forall int x >= 0 | getCellsCount(x, y) <= getCellsCount(-1,y)
exists int y >= 0 | exists int x >= 0 | getCellsCount(x, y) == getCellsCount(-1,y)
forall int x >= -1 | getCellsCount(x, 0) == 0
forall int y >= -1 | getCellsCount(0, y) == 0
forall int x >= 0 | forall int y= > 0 | getCellsCount(x+1,y+1) + getCellsCount(x,y) == getCellsCount(x,y+1) + getCellsCount(x+1,y) +(containsCell(x,y) ? 1 : 0)
isEmpty() == (getCellsCount(-1,-1) == 0)
isEmpty() == getBounds().isEmpty()
forall int x >= 0 | forall int y >= 0 | !getBounds().contains(x,y) implies !containsCell(x,y)
!isEmpty() implies exists int x in [getBounds().x, getBounds().x + getBounds().width[ | containsCell(x,getBounds().y)
!isEmpty() implies exists int y in [getBounds().y, getBounds().y + getBounds().height[ | containsCell(getBounds().x,y)
!isEmpty() implies exists int x in [getBounds().x, getBounds().x + getBounds().width[ | containsCell(x,getBounds().y + getBounds().height - 1)
!isEmpty() implies exists int y in [getBounds().y, getBounds().y + getBounds().height[ | containsCell(getBounds().x + getBounds().width - 1,y) The contract for iterator is alittle more difficult to express:
iterator() != null The objects returned by the iterator are Point, and for every such point pt, containsCell(pt.x,pt.y) is true. Moreover, for 2 consecutive objects p0 and p1, p0.y < p1.y || p0.y == p1.y && p0.x < p1.x. And last but not least,
forall Point pt | containsCell(pt.x, pt.y) implies pt belongs to iterator()
Version:
1.0 00/04/10
Author:
Patrick Mérissert-Coffinières

Inner Class Summary
static class CellsSet.Factory
          A factory to clone CellsSet objects, and create default ones
static interface CellsSet.Listener
          A call-back for tracking changes
 
Method Summary
 void addListener(CellsSet.Listener l)
          Adds Listener l to the list of Listeners that will be notified of any changes to the model by the invocation of their method markAsChanged with a r argument containing all changes.
 void clear()
          Empties the set
 void clearCells(java.awt.Rectangle r)
          Ensures that all cells in the specified rectangle are withdrawn from the set
 java.lang.Object clone()
          Necessary to allow public access to the clone method.
 boolean containsCell(int x, int y)
          Tests whether the cell defined by coordinates x,y is in the set
 java.awt.Rectangle getBounds()
          Returns the smallest rectangle including all the cells in the subset
 int getCellsCount(int maxwidth, int maxheight)
          Returns the number of cells inside some (optional) limits
 void insertColumns(int start, int count)
          Inserts count columns before position start.
 void insertRows(int start, int count)
          Inserts count rows before position start.
 boolean isEmpty()
          Tests whether the set is empty
 java.util.Iterator iterator()
          Returns the sequence of points in the set, ordered by y, x
 void removeColumns(int start, int count)
          Removes count columns at column start
 void removeListener(CellsSet.Listener l)
          Removes Listener l from the list of Listeners that will be notified of any changes to the model by the invocation of their method markAsChanged with a r argument containing all changes.
 void removeRows(int start, int count)
          Removes count rows at row start
 void setCells(java.awt.Rectangle r)
          Ensures that all cells in the specified rectangle are added to the set
 

Method Detail

getCellsCount

public int getCellsCount(int maxwidth,
                         int maxheight)
Returns the number of cells inside some (optional) limits
Parameters:
maxwidth - the excluded horizontal upper bound applied to this call. If no bound, -1.
maxheight - the excluded vertical upper bound applied to this call. If no bound, -1.
Returns:
the number of cells inside the bounds
Preconditions:
maxwidth >= -1 && maxheight >= -1

isEmpty

public boolean isEmpty()
Tests whether the set is empty
Returns:
true only if the set is structurally empty.
Postconditions:
return == (getCellsCount(-1,-1)==0)

containsCell

public boolean containsCell(int x,
                            int y)
Tests whether the cell defined by coordinates x,y is in the set
Parameters:
x - the x coord of the tested cell.
y - the y coord of the tested cell.
Preconditions:
x >= 0 && y >= 0

getBounds

public java.awt.Rectangle getBounds()
Returns the smallest rectangle including all the cells in the subset
Postconditions:
return != null

iterator

public java.util.Iterator iterator()
Returns the sequence of points in the set, ordered by y, x

clear

public void clear()
Empties the set
Postconditions:
isEmpty()

setCells

public void setCells(java.awt.Rectangle r)
Ensures that all cells in the specified rectangle are added to the set
Parameters:
r - The rectangle to add.
Preconditions:
r != null && r.x >= 0 && r.y >= 0
Postconditions:
forall int x in [r.x, r.x+r.width[ | forall int y in [r.y, r.y+r.height[ | containsCell(x,y)

clearCells

public void clearCells(java.awt.Rectangle r)
Ensures that all cells in the specified rectangle are withdrawn from the set
Parameters:
r - The rectangle to exclude.
Preconditions:
r != null && r.x >= 0 && r.y >= 0
Postconditions:
forall int x in [r.x, r.x+r.width[ | forall int y in [r.y, r.y+r.height[ | !containsCell(x,y)

addListener

public void addListener(CellsSet.Listener l)
Adds Listener l to the list of Listeners that will be notified of any changes to the model by the invocation of their method markAsChanged with a r argument containing all changes.

removeListener

public void removeListener(CellsSet.Listener l)
Removes Listener l from the list of Listeners that will be notified of any changes to the model by the invocation of their method markAsChanged with a r argument containing all changes.

insertRows

public void insertRows(int start,
                       int count)
Inserts count rows before position start.
Parameters:
start - the position of insertion.
count - the number of inserted positions.
Preconditions:
start >= 0
count > 0
Postconditions:
forall int x >= 0 | forall int y in [0, start[ | containsCell(x,y) == contains(x,y)@pre
forall int y >= 0 | forall int y in [start, start+count[ | containsCell(x,y) == (start > 0 && containsCell(x,start-1) && containsCell(x,start)@pre)
forall int x >= 0 | forall int y >= start+count | containsCell(x,y) == containsCell(x,y-count)@pre

removeRows

public void removeRows(int start,
                       int count)
Removes count rows at row start
Parameters:
start - the position of deletion.
count - the number of deleted rows.
Preconditions:
start >= 0
count > 0
Postconditions:
forall int x >= 0 | forall int y in [0, start[ | containsCell(x,y) == contains(x,y)@pre
forall int x >= 0 | forall int y >= start | containsCell(x,y) == contains(x,y-count)@pre

insertColumns

public void insertColumns(int start,
                          int count)
Inserts count columns before position start.
Parameters:
start - the position of insertion.
count - the number of inserted positions.
Preconditions:
start >= 0
count > 0
Postconditions:
forall int y >= 0 | forall int x in [0, start[ | containsCell(x,y) == contains(x,y)@pre
forall int y >= 0 | forall int x in [start, start+count[ | containsCell(x,y) == (start > 0 && containsCell(start-1,y) && containsCell(start,y)@pre)
forall int y >= 0 | forall int x >= start+count | containsCell(x,y) == contains(x-count,y)@pre

removeColumns

public void removeColumns(int start,
                          int count)
Removes count columns at column start
Parameters:
start - the position of deletion.
count - the number of deleted columns.
Preconditions:
start >= 0
count > 0
Postconditions:
forall int y >= 0 | forall int x in [0, start[ | containsCell(x,y) == contains(x,y)@pre
forall int y >= 0 | forall int x >= start | containsCell(x,y) == contains(x-count,y)@pre

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Necessary to allow public access to the clone method. Yet it seems also to be necessary so that the Factory.copy method loads without a VerifyError, though it compiles properly!
Overrides:
clone in class java.lang.Object