gzz
Class Cell

gzz.Cell gzz.Dim gzz.Space gzz.CellTexter gzz.VStreamCellTexter gzz.JavaObjector gzz.Obs gzz.ObsTrigger ../../Gzz_CoreAPIs.gen.html#core core_small
java.lang.Object
  |
  +--gzz.Cell

public class Cell
extends java.lang.Object

A class to represent a ZigZag cell.

This class contains convenience methods for accessing and editing cells, but more complicated operations should be used through the specialized dimensions.

There is not necessarily a unique cell to Java object mapping, so there may be several equivalent Java objects representing the same cell. Use the equals method for comparisons.

The cell is identified by the Space space and the String id objects. (Ids are interned-- see String.intern()-- to make comparisons fast; internally, id==id is used.)

There hashCode is also cached.

The intention is that Space.getCell(id) always results in exactly equivalent cells.

It is also meant that all Cell objects of a single space are of the same type.

See Also:
Space, Dim

Field Summary
static int cellFormat
           
static int ID_AND_TEXT
           
static int ID_ONLY
           
static java.lang.String rcsid
           
 Space space
           
static int TEXT_ONLY
           
 
Constructor Summary
protected Cell(Space space, int hashcode)
          Create a Cell with a null (lazy) id, with given hashcode.
  Cell(Space space, java.lang.String id)
          Create a Cell with the given id.
 
Method Summary
 void connect(Dim dim, Cell to)
          Connect this cell to another along a dimension.
 void connect(Dim dim, int dir, Cell to)
          Connect this cell to another along a dimension in a specified direction.
 void copyText(int ind, Cell from, int begin, int end)
          Copy some text from another cell to this cell.
 void delete()
          Delete this cell.
 void deleteText(int begin, int end)
          Delete a piece of text from the cell.
 void disconnect(Dim dim, int dir)
          Disconnect another cell from this cell.
 boolean equals(java.lang.Object c)
          Tests whether this cell is the same as another cell.
 void excise(Dim dim)
          Delete this cell from a rank along a dimension.
 Cell getHomeCell()
           
 java.lang.String getId()
          Get the id of this cell.
 java.lang.Object getJavaObject()
           
 java.lang.Object getJavaObject(Obs o)
          Get the Java object associated with this cell, if any.
 Cell getOrNew(Dim dim)
           
 Cell getOrNew(Dim dim, int dir)
           
 Cell getOrNew(Dim dim, int dir, Obs o)
          Get or create a new cell connected to this cell.
 Cell getRootclone()
           
 Cell getRootclone(Obs o)
          Get the root clone of this cell: the headcell of the clone dimension.
 Cell h(Dim dim)
          Find the headcell of a rank.
 Cell h(Dim dim, int dir)
           
 Cell h(Dim dim, int dir, boolean ensuremove)
           
 Cell h(Dim dim, int dir, boolean ensuremove, Obs o)
          Find the headcell of a rank.
 int hashCode()
           
 void hop(Dim dim, int steps)
          Hops the cell along the dimension.
 void insert(Dim dim, int dir, Cell what)
          Insert a cell next to this one in the rank.
 void insertText(int ind, java.lang.String s)
          Insert some text to this cell.
 void moveText(int ind, Cell from, int begin, int end)
          Move some text from another cell to this cell.
 Cell N()
          Get a new cell associated with this cell (i.e., same slice)
 Cell N(Dim dim)
           
 Cell N(Dim dim, int dir)
          Create a new cell connected to this cell.
 Cell N(Dim dim, int dir, Obs o)
          Create a new cell connected to this cell and attach an observer to it atomically.
 Cell s(Dim dim)
           
 Cell s(Dim dim, int dir)
          Find the neighbour of this cell along a dimension atomically.
 Cell s(Dim dim, int steps, Obs o)
          Find the neighbour of this cell along a dimension and attach an observer to this relation atomically.
 Cell s(Dim dim, Obs o)
          Find the next cell along a dimension.
 void setText(java.lang.String text)
          Set the content of this cell as text.
 java.lang.String t()
          Returns the text contained in the cell.
 java.lang.String t(Obs o)
           
 java.lang.String toString()
          Return a stringized form of this cell.
 Cell zzclone()
           
 Cell zzclone(Cell inSlice)
          Clone this cell in the same slice as a given cell.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

rcsid

public static final java.lang.String rcsid
See Also:
Constant Field Values

space

public final Space space

TEXT_ONLY

public static final int TEXT_ONLY
See Also:
Constant Field Values

ID_AND_TEXT

public static final int ID_AND_TEXT
See Also:
Constant Field Values

ID_ONLY

public static final int ID_ONLY
See Also:
Constant Field Values

cellFormat

public static int cellFormat
Constructor Detail

Cell

public Cell(Space space,
            java.lang.String id)
Create a Cell with the given id.


Cell

protected Cell(Space space,
               int hashcode)
Create a Cell with a null (lazy) id, with given hashcode.

Method Detail

getId

public java.lang.String getId()
Get the id of this cell. If the id member of this class is allowed to be null, then this method must be overridden; calling getId SHALL never return null.


N

public final Cell N(Dim dim,
                    int dir)
Create a new cell connected to this cell.

Parameters:
dim - Dimension to create the cell along
dir - The direction, either positive or negative

N

public final Cell N(Dim dim)

N

public final Cell N()
Get a new cell associated with this cell (i.e., same slice)


getOrNew

public final Cell getOrNew(Dim dim,
                           int dir,
                           Obs o)
Get or create a new cell connected to this cell. A convenience function which first tries to use getNeighbour and if that returns null, creates a new neighbour.

Parameters:
dim - Dimension to create the cell along
dir - The direction, either positive or negative

getOrNew

public final Cell getOrNew(Dim dim,
                           int dir)

getOrNew

public final Cell getOrNew(Dim dim)

N

public final Cell N(Dim dim,
                    int dir,
                    Obs o)
Create a new cell connected to this cell and attach an observer to it atomically.

Parameters:
dim - Dimension to create the cell along
dir - The direction, either positive or negative

delete

public final void delete()
Delete this cell.


excise

public final void excise(Dim dim)
Delete this cell from a rank along a dimension.


connect

public final void connect(Dim dim,
                          Cell to)
                   throws gzz.errors.ZZAlreadyConnectedException
Connect this cell to another along a dimension. If there is a former connection, a ZZAlreadyConnectedException is thrown.

Parameters:
dim - Dimension to connect along
to - Cell to connect to. This cell will end up poswards from us.
gzz.errors.ZZAlreadyConnectedException

connect

public final void connect(Dim dim,
                          int dir,
                          Cell to)
                   throws gzz.errors.ZZAlreadyConnectedException
Connect this cell to another along a dimension in a specified direction. If there is a former connection, a ZZAlreadyConnectedException is thrown.

Parameters:
dim - Dimension to connect along
dir - The direction, either positive or negative
to - Cell to connect to.
gzz.errors.ZZAlreadyConnectedException

insert

public final void insert(Dim dim,
                         int dir,
                         Cell what)
                  throws gzz.errors.ZZAlreadyConnectedException
Insert a cell next to this one in the rank. Both connections of the what cell along the specified dimension are deleted before inserting it.

Parameters:
dim - Dimension to connect along
dir - The direction, either positive or negative
what - Cell to insert
gzz.errors.ZZAlreadyConnectedException

disconnect

public final void disconnect(Dim dim,
                             int dir)
Disconnect another cell from this cell.

Parameters:
dim - Dimension to disconnect along
dir - The direction, either positive or negative

setText

public final void setText(java.lang.String text)
Set the content of this cell as text. XXX Need to think about potential other types: int etc.

Parameters:
text - The new text

insertText

public final void insertText(int ind,
                             java.lang.String s)
Insert some text to this cell.


copyText

public final void copyText(int ind,
                           Cell from,
                           int begin,
                           int end)
Copy some text from another cell to this cell.


moveText

public final void moveText(int ind,
                           Cell from,
                           int begin,
                           int end)
Move some text from another cell to this cell.


deleteText

public final void deleteText(int begin,
                             int end)
Delete a piece of text from the cell. For example, if the text is "abcde", then after deleteText(2, 3), the text will be "abde", i.e. the parameters are as in String.substring.


s

public final Cell s(Dim dim,
                    int steps,
                    Obs o)
Find the neighbour of this cell along a dimension and attach an observer to this relation atomically.

Parameters:
dim - Dimension to go along
steps - The direction, either positive or negative
Returns:
The neighbour, or null if none.

s

public final Cell s(Dim dim,
                    int dir)
Find the neighbour of this cell along a dimension atomically.

Parameters:
dim - Dimension to go along
dir - The direction, either positive or negative
Returns:
The neighbour, or null if none.

s

public final Cell s(Dim dim)

s

public final Cell s(Dim dim,
                    Obs o)
Find the next cell along a dimension. Always moves poswards.

Parameters:
dim - Dimension to go along
Returns:
The neighbour, or null if none.

h

public final Cell h(Dim dim)
Find the headcell of a rank. The headcell is the most negative cell so this call is equivalent to h(dim, -1).


h

public final Cell h(Dim dim,
                    int dir)

h

public final Cell h(Dim dim,
                    int dir,
                    boolean ensuremove)

h

public final Cell h(Dim dim,
                    int dir,
                    boolean ensuremove,
                    Obs o)
Find the headcell of a rank. Always returns a cell, even if rank is looping. Looking for null going poswards from the headcell might be infinite and needs the user to explicitly detect loops. Just in case of synch problems, it is recommended that the user check both for equality to the headcell and use a LoopDetector, in case the loop changed.

Parameters:
dim - Dimension to go along
dir - The direction, either positive or negative
ensuremove - If true, this function returns null if the given cell already is the headcell.
Returns:
The headcell

t

public final java.lang.String t()
Returns the text contained in the cell. A null return means that the cell has been deleted. XXX Really? What about empty cells / image spans etc. At least for now, t() is never null: easier to use


t

public final java.lang.String t(Obs o)

equals

public boolean equals(java.lang.Object c)
Tests whether this cell is the same as another cell. There may be more than one Java object representing the same cell so it is important to use this method instead of the '==' operator to test for equality.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

hop

public final void hop(Dim dim,
                      int steps)
Hops the cell along the dimension. This means that all other connections remain the same but that this cell changes places in the rank given by the dimension. This operation may be given interesting meanings when e.g. hopping over the end of a rank.

Parameters:
dim - The dimension to hop along
steps - The number of places to hop. May be negative, in which case the cell will hop negwards.

getHomeCell

public final Cell getHomeCell()

zzclone

public final Cell zzclone()

zzclone

public final Cell zzclone(Cell inSlice)
Clone this cell in the same slice as a given cell.


getRootclone

public final Cell getRootclone()

getRootclone

public final Cell getRootclone(Obs o)
Get the root clone of this cell: the headcell of the clone dimension. Clones are a feature of ZZ structure by which a new cell that "means" the same thing as an existing cell can be created.

Parameters:
o - The observer to call if the return value of this function would have changed as a result of a structural or other change.

toString

public java.lang.String toString()
Return a stringized form of this cell. This form is unstable and its use for anything except human-readable debugging is not recommended.

Currently the format is: The cell ID in single quotes and the text content after that, in parentheses, for example '53' (Text in cell).

(Changed now to exclude id - still thinking about it...) (Benja: changed it back because it's a pain in the neck for tests and Tuomas isn't there to ask. We can change it again later (when IDs get longer), but at this point in time this is better-- too many test cells do not have content and thus render as a simple and misleading "(null)".)

Ok, here's a solution: nothing should depend on it. we'll read the format from a property.

Overrides:
toString in class java.lang.Object

getJavaObject

public final java.lang.Object getJavaObject()

getJavaObject

public final java.lang.Object getJavaObject(Obs o)
Get the Java object associated with this cell, if any. Currently the manner in which Java objects are associated with cells is implementation-defined by the space.

Parameters:
o - The observer to call if the return value of this function would have changed as a result of a structural or other change.