37 |
import gzz.errors.*; |
import gzz.errors.*; |
38 |
import java.util.*; |
import java.util.*; |
39 |
import gzz.media.*; |
import gzz.media.*; |
|
import gzz.impl.EvilCellTexter; |
|
40 |
|
|
41 |
/** A class to represent a ZigZag cell. |
/** A class to represent a ZigZag cell. |
42 |
* <p> |
* <p> |
105 |
* @param dir The direction, either positive or negative |
* @param dir The direction, either positive or negative |
106 |
* @diagram zzstruct |
* @diagram zzstruct |
107 |
*/ |
*/ |
|
final public Cell N(Cell dim, int dir) { |
|
|
return N(dim, dir, null); |
|
|
} |
|
|
final public Cell N(Cell dim) { |
|
|
return N(dim, 1, null); |
|
|
} |
|
108 |
final public Cell N(Dim dim, int dir) { |
final public Cell N(Dim dim, int dir) { |
109 |
return N(dim, dir, null); |
return N(dim, dir, null); |
110 |
} |
} |
138 |
final public Cell getOrNew(Dim dim) { |
final public Cell getOrNew(Dim dim) { |
139 |
return getOrNew(dim, 1, null); |
return getOrNew(dim, 1, null); |
140 |
} |
} |
|
final public Cell getOrNew(Cell dim, int dir, Obs o) { |
|
|
return getOrNew(space.getDim(dim), dir, o); |
|
|
} |
|
|
final public Cell getOrNew(Cell dim, int dir) { |
|
|
return getOrNew(dim, dir, null); |
|
|
} |
|
|
final public Cell getOrNew(Cell dim) { |
|
|
return getOrNew(dim, 1, null); |
|
|
} |
|
141 |
/** Create a new cell connected to this cell and attach an observer |
/** Create a new cell connected to this cell and attach an observer |
142 |
* to it |
* to it |
143 |
* atomically. |
* atomically. |
146 |
* @param obs The observer |
* @param obs The observer |
147 |
* @diagram zzstruct |
* @diagram zzstruct |
148 |
*/ |
*/ |
|
final public Cell N(Cell dim, int dir, Obs o) { |
|
|
return space.N(this, dim, dir, o); |
|
|
} |
|
149 |
final public Cell N(Dim dim, int dir, Obs o) { |
final public Cell N(Dim dim, int dir, Obs o) { |
150 |
return space.N(this, dim, dir, o); |
return space.N(this, dim, dir, o); |
151 |
} |
} |
157 |
space.delete(this); |
space.delete(this); |
158 |
} |
} |
159 |
|
|
|
final public void excise(Cell dim) { |
|
|
excise(space.getDim(dim)); |
|
|
} |
|
160 |
/** Delete this cell from a rank along a dimension. |
/** Delete this cell from a rank along a dimension. |
161 |
* @diagram zzstruct |
* @diagram zzstruct |
162 |
*/ |
*/ |
172 |
* @param to Cell to connect to. This cell will |
* @param to Cell to connect to. This cell will |
173 |
* end up poswards from us. |
* end up poswards from us. |
174 |
*/ |
*/ |
|
final public void connect(Cell dim, Cell to) |
|
|
throws ZZAlreadyConnectedException { |
|
|
connect(space.getDim(dim), to); |
|
|
} |
|
175 |
final public void connect(Dim dim, Cell to) |
final public void connect(Dim dim, Cell to) |
176 |
throws ZZAlreadyConnectedException { |
throws ZZAlreadyConnectedException { |
177 |
dim.connect(this, to); |
dim.connect(this, to); |
187 |
* @param to Cell to connect to. |
* @param to Cell to connect to. |
188 |
* @diagram zzstruct |
* @diagram zzstruct |
189 |
*/ |
*/ |
|
final public void connect(Cell dim, int dir, Cell to) |
|
|
throws ZZAlreadyConnectedException { |
|
|
connect(space.getDim(dim), dir, to); |
|
|
} |
|
190 |
final public void connect(Dim dim, int dir, Cell to) |
final public void connect(Dim dim, int dir, Cell to) |
191 |
throws ZZAlreadyConnectedException { |
throws ZZAlreadyConnectedException { |
192 |
if(dir > 0) { |
if(dir > 0) { |
203 |
* @param dir The direction, either positive or negative |
* @param dir The direction, either positive or negative |
204 |
* @param what Cell to insert |
* @param what Cell to insert |
205 |
*/ |
*/ |
|
final public void insert(Cell dim, int dir, Cell what) |
|
|
throws ZZAlreadyConnectedException { |
|
|
insert(space.getDim(dim), dir, what); |
|
|
} |
|
206 |
final public void insert(Dim dim, int dir, Cell what) |
final public void insert(Dim dim, int dir, Cell what) |
207 |
throws ZZAlreadyConnectedException { |
throws ZZAlreadyConnectedException { |
208 |
dim.insert(this, dir, what); |
dim.insert(this, dir, what); |
213 |
* @param dir The direction, either positive or negative |
* @param dir The direction, either positive or negative |
214 |
* @diagram zzstruct |
* @diagram zzstruct |
215 |
*/ |
*/ |
|
final public void disconnect(Cell dim, int dir) { |
|
|
disconnect(space.getDim(dim), dir); |
|
|
} |
|
216 |
final public void disconnect(Dim dim, int dir) { |
final public void disconnect(Dim dim, int dir) { |
217 |
dim.disconnect(this, dir); |
dim.disconnect(this, dir); |
218 |
} |
} |
219 |
|
|
|
/** Set the content of this cell as a Span. |
|
|
* @param text The new text, as a span pointing to a stable scroll |
|
|
* @deprecated To be replaced by VStream methods. |
|
|
*/ |
|
|
final public void setSpan(Span text) { |
|
|
((EvilCellTexter)space.getCellTexter()).setSpan(this, text); |
|
|
} |
|
|
|
|
220 |
/** Set the content of this cell as text. |
/** Set the content of this cell as text. |
221 |
* XXX Need to think about potential other types: int etc. |
* XXX Need to think about potential other types: int etc. |
222 |
* @param text The new text |
* @param text The new text |
266 |
final public Cell s(Dim dim, int steps, Obs o) { |
final public Cell s(Dim dim, int steps, Obs o) { |
267 |
return dim.s(this, steps, o); |
return dim.s(this, steps, o); |
268 |
} |
} |
|
final public Cell s(Cell dim, int steps, Obs o) { |
|
|
return space.getDim(dim).s(this, steps, o); |
|
|
} |
|
269 |
|
|
270 |
/** Find the neighbour of this cell along a dimension |
/** Find the neighbour of this cell along a dimension |
271 |
* atomically. |
* atomically. |
273 |
* @param dir The direction, either positive or negative |
* @param dir The direction, either positive or negative |
274 |
* @return The neighbour, or null if none. |
* @return The neighbour, or null if none. |
275 |
*/ |
*/ |
|
final public Cell s(Cell dim, int dir) { |
|
|
return s(dim,dir,null); |
|
|
} |
|
276 |
final public Cell s(Dim dim, int dir) { |
final public Cell s(Dim dim, int dir) { |
277 |
return s(dim,dir,null); |
return s(dim,dir,null); |
278 |
} |
} |
279 |
|
|
|
final public Cell s(Cell dim) { |
|
|
return s(dim,1,null); |
|
|
} |
|
280 |
final public Cell s(Dim dim) { |
final public Cell s(Dim dim) { |
281 |
return s(dim,1,null); |
return s(dim,1,null); |
282 |
} |
} |
|
final public Cell s(Cell dim, Obs o) { |
|
|
return s(dim,1,o); |
|
|
} |
|
283 |
/** Find the next cell along a dimension. |
/** Find the next cell along a dimension. |
284 |
* Always moves poswards. |
* Always moves poswards. |
285 |
* @param dim Dimension to go along |
* @param dim Dimension to go along |
289 |
return s(dim,1,o); |
return s(dim,1,o); |
290 |
} |
} |
291 |
|
|
|
final public Cell h(Cell dim, int dir) { |
|
|
return h(dim, dir, false, null); |
|
|
} |
|
|
final public Cell h(Cell dim, int dir, Obs o) { |
|
|
return h(dim, dir, false, o); |
|
|
} |
|
|
final public Cell h(Cell dim, boolean ensuremove) { |
|
|
return h(dim, -1, ensuremove, null); |
|
|
} |
|
|
final public Cell h(Cell dim, int dir, boolean ensuremove) { |
|
|
return h(dim, dir, ensuremove, null); |
|
|
} |
|
292 |
/** Find the headcell of a rank. |
/** Find the headcell of a rank. |
293 |
* The headcell is the most negative cell so this call is equivalent |
* The headcell is the most negative cell so this call is equivalent |
294 |
* to h(dim, -1). |
* to h(dim, -1). |
295 |
*/ |
*/ |
|
final public Cell h(Cell dim) { |
|
|
return h(dim, -1, false, null); |
|
|
} |
|
296 |
final public Cell h(Dim dim) { |
final public Cell h(Dim dim) { |
297 |
return h(dim, -1, false, null); |
return h(dim, -1, false, null); |
298 |
} |
} |
299 |
final public Cell h(Dim dim, int dir) { |
final public Cell h(Dim dim, int dir) { |
300 |
return h(dim, dir, false, null); |
return h(dim, dir, false, null); |
301 |
} |
} |
302 |
|
final public Cell h(Dim dim, int dir, boolean ensuremove) { |
303 |
|
return h(dim, dir, ensuremove, null); |
304 |
|
} |
305 |
|
|
306 |
/** Find the headcell of a rank. |
/** Find the headcell of a rank. |
307 |
* Always returns a cell, even if rank is looping. |
* Always returns a cell, even if rank is looping. |
317 |
* @return The headcell |
* @return The headcell |
318 |
* @diagram zzstruct |
* @diagram zzstruct |
319 |
*/ |
*/ |
|
final public Cell h(Cell dim, int dir, boolean ensuremove, |
|
|
Obs o) { |
|
|
return h(space.getDim(dim), dir, ensuremove, o); |
|
|
} |
|
320 |
|
|
321 |
final public Cell h(Dim dim, int dir, boolean ensuremove, |
final public Cell h(Dim dim, int dir, boolean ensuremove, |
322 |
Obs o) { |
Obs o) { |
340 |
return text; |
return text; |
341 |
} |
} |
342 |
|
|
|
/** Returns the stable media reference in the cell. |
|
|
* A null return means either that the cell has been deleted |
|
|
* or that the text inside is not a reference. |
|
|
* @param lang The requested language. |
|
|
*/ |
|
|
final public Span getSpan() { return getSpan(null); } |
|
|
final public Span getSpan(Obs o) { |
|
|
// return ((EvilCellTexter)space.getCellTexter()).getSpan(this, o); |
|
|
return null; |
|
|
} |
|
|
|
|
343 |
/** Tests whether this cell is the same as another cell. |
/** Tests whether this cell is the same as another cell. |
344 |
* There may be more than one Java object representing the same cell |
* There may be more than one Java object representing the same cell |
345 |
* so it is important to use this method instead of the '==' operator |
* so it is important to use this method instead of the '==' operator |
370 |
* in which case the cell will hop negwards. |
* in which case the cell will hop negwards. |
371 |
* @diagram zzstruct |
* @diagram zzstruct |
372 |
*/ |
*/ |
|
final public void hop(Cell dim, int steps) { |
|
|
hop(space.getDim(dim), steps); |
|
|
} |
|
373 |
final public void hop(Dim dim, int steps) { |
final public void hop(Dim dim, int steps) { |
374 |
dim.hop(this, steps); |
dim.hop(this, steps); |
375 |
} |
} |