[Date Prev][Date Next][Thread Prev][Thread Next][Author Index][Date Index][Thread Index]
Re: [zzdev] Test if cell exists by ID
- To: Phil Mercurio <mercurio@xxxxxxx>
- Subject: Re: [zzdev] Test if cell exists by ID
- From: "B. Fallenstein" <b.fallenstein@xxxxxx>
- Date: Mon, 14 May 2001 11:15:26 +0200
- Cc: zzdev@xxxxxxxxxx
- References: <126.96.36.199.0.20010513213104.00a2ca80@xxxxxxxxxxxx>
Phil Mercurio wrote:
> Is there a way to test if a cell of a given ID already
> exists? I'm looking for something like ZZSpace.getCellByID(),
> but that doesn't create the cell if it doesn't
> already exist.
Let me state some necessary background first.
A conceptual problem here is that in a way, any cell always exists--
except it may not have ever been connected/no content may have ever been
set to it. On the other hand, there is of course the cell.N() mechanism
of "creating a new cell". Actually this simply increments a counter of
"used" numeric IDs for cells. Cell IDs can be any String, though
(although special magic is associated with the characters ':' and '@').
Thus the concept of 'existance', as in having been created through
cell.N(), is only defined for a subset of all cells. (Another way to
look at this is d.cellcreation: only cells with numeric IDs are listed here).
Now, the way to get what you want depends on what kind of space you use.
- If you want to be on the level of ZZSpace, you are lost, because
ZZSpace makes no assumptions about cells created/not created.
- If you want to be on the level of ZZDimSpace (AFAIK currently the only
ZZSpace implementation), you can either write a class inside the package
org.gzigzag which accesses the (String) nextID field in a ZZDimSpace
object (it is package-private), or you can hack a public getNextID()
method into ZZDimSpace (I'd say that's the prefered way).
- If you want to be on the level of ZZCachedDimSpace (the space used
when stuff is stored on disk), you can simply read the cell with the ID
"nextfreeid" (without quotes, of course) for this purpose (this is an
example for a cell outside the numeric ID framework).
When you know nextID, you can convert it into a long value and then
compare your ID numerically to this value. If nextID is greater than
your ID, your ID exists; if nextID is lower than or equal to your ID,
your ID doesn't exist yet (and in order not to introduce hard-to-track
bugs, you should not use it!). Of course you can also add that as a
method to ZZDimSpace.
Hope this helps,