[Date Prev][Date Next][Thread Prev][Thread Next][Author Index][Date Index][Thread Index]
Re: [zzdev] Re: [zzdev] Test if cell exists by ID
- To: "B. Fallenstein" <b.fallenstein@xxxxxx>, Phil Mercurio <mercurio@xxxxxxx>
- Subject: Re: [zzdev] Re: [zzdev] Test if cell exists by ID
- From: Phil Mercurio <mercurio@xxxxxxx>
- Date: Mon, 14 May 2001 10:54:26 -0700
- Cc: zzdev@xxxxxxxxxx
- In-reply-to: <3AFFA22F.F25499AA@xxxxxx>
- References: <126.96.36.199.0.20010513213104.00a2ca80@xxxxxxxxxxxx>
I had a feeling I was experiencing conceptual difficulties,
thanks for the explanation. Benja. Tuomas also mentioned
that this is still in flux. The approach given below for
comparing against nextID would work for now, except that
I assume this won't help in detecting cells that used to
exist but have been deleted.
There's a method called c() in ZZDimSpace
that does what I was looking for, except that it's
private. But a ZZDimSpace-level solution would be fine for me,
any chance this method could be made public (and
At 11:15 AM 5/14/01 +0200, B. Fallenstein wrote:
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,