* This is because we're aiming for Java 1.1 which does not * have weak references. */ public class DimCell extends ZZCellHandle { protected DimCell(String id) { super(id, null, null); } protected DimCell(ZZSpacePart part, Object parsedID) { this(part.generateID(parsedID), part, parsedID); } protected DimCell(String id, ZZSpacePart p, Object o) { super(id, p, o); } public String[] getRankNames() { throw new ZZError("getRankNames Not implemented"); } public final ZZSpace getSpace() { return ZZDimSpace.this; } public void connect(String dim, ZZCell to) { this.disconnect(dim, 1); to.disconnect(dim, -1); d(dim).connect(this, ((DimCell)to)); } public void disconnect(String dim, int dir) { d(dim).disconnect(this, dir); } public void insert(String dim, int dir, ZZCell to) { d(dim).insert(this, dir, ((DimCell)to)); } public void hop(String dim, int steps) { d(dim).hop(this, steps); } public ZZCell s(String dim, int dir, ZZObs o) { return d(dim).s(this, dir, o); } public ZZCell N(String dim, int dir, ZZObs o, long flags) { synchronized(ZZDimSpace.this) { DimCell n = getNewCell(id); insert(dim, dir, n); if(o != null) d(dim).s(this, dir, o); return n; } } public ZZCell N() { synchronized(ZZDimSpace.this) { return getNewCell(id); } } public void setText(String text) { synchronized(ZZDimSpace.this) { ZZCell rootClone = getRootclone(); if(rootClone != this) { rootClone.setText(text); return; } if(part != null) { part.setContent(this, text); } else { p("TEXT"); ZZDimSpace.this.setText(id, text); textTrig.chg(id); } } } public void setSpan(Span text) { synchronized(ZZDimSpace.this) { ZZCell rootClone = getRootclone(); if(rootClone != this) { rootClone.setSpan(text); return; } if(part != null) { part.setContent(this, text); } else { ZZDimSpace.this.setText(id, text); textTrig.chg(id); } } } // XXX part.getText should NOT BE HERE!!!! public String getText(ZZObs o) { synchronized(ZZDimSpace.this) { String s; // XXX Interaction with slices?? // XXX Interaction with ZZObs ZZCell rootClone = getRootclone(); if(rootClone != this) return rootClone.getText(o); if(o != null) textTrig.addObs(id, o); if(part != null) s = part.getText(this); else s = ZZDimSpace.this.getText(id); if( s == null ) return ""; return s; } } public Span getSpan(ZZObs o) { synchronized(ZZDimSpace.this) { ZZCell rootClone = getRootclone(); // XXX As in getText!!! if(rootClone != this) return rootClone.getSpan(o); if(o != null) textTrig.addObs(id, o); if(part != null) return part.getSpan(this); return ZZDimSpace.this.getSpan(id); } } public boolean equals(ZZCell c) { DimCell o = (DimCell)c; return (this == o) || (ZZDimSpace.this == o.getSpace() && id.equals(o.id)); } public void delete() { synchronized(ZZDimSpace.this) { ZZDimSpace.this.deleteCell(this); } } public ZZCell h(String dim, int dir, boolean ensuremove, ZZObs o) { ZZCell res = d(dim).h(this, dir, o); if(ensuremove && (res == this)) return null; return res; } } void deleteCell(ZZCell c) { for(Enumeration e = dims.keys(); e.hasMoreElements(); ) { ((ZZDimension)(dims.get(e.nextElement()))).excise((DimCell)c); } } String nextID="2"; // first cell is home cell, ID 1 protected void setNextID(String s) { nextID = s; } /** Get the cell ID relative to a given ID, in creation order. * @param id Given ID * @param steps How many steps to take (negative means earlier) */ public String getRelativeCellID(String id, int steps) { try { long i = Long.parseLong(id); if(i<0 || i+steps<1) return null; return ""+(i+steps); } catch(NumberFormatException e) { return null; } } protected String getFreeCellID() { String curID = nextID; setNextID(getRelativeCellID(nextID, 1)); return curID; } // XXX What's this? (compared to the next) protected DimCell getNewCell(String id) { return getNewCell(); } protected DimCell getNewCell() { return (DimCell)getCellByID(nextID); } public ZZCell newCell() { return getNewCell(); } /** A simple dimension listing the cells in creation order. * It uses getRelativeCellID() to find the cells, and will check * nextID to know whether the cell doesn't exist yet. * XXX The positive steps taken must be 1 or skipping nextID * is possible! */ class IDDimension extends ZZRODimension { /** get a cell ID along the dimension. * XXX Obs doesn't work correctly. */ public ZZCellHandle s(ZZCellHandle c, int steps, ZZObs o) { String id = getRelativeCellID(c.id, steps); if(id == null || id.equals(nextID)) return null; return (DimCell)getCellByID(id); } } // XXX posConnections()? public ZZCell[] findLongRankHeads(String dim) { return null; } public void rmAllObs(ZZObs o) { } public String getHomeCellID() { return "1"; } public ZZCell getHomeCell() { return getCellByID(getHomeCellID()); } /** Create a new dimension with the name s. * In order to make things fast, this is the method * to override instead of the d() method (which is final * exactly because of that). *
* The default version simply returns a new ZZLocalDimension, * except for d.cellcreation *
* Note that this routine should NOT touch the dimension hash * but simply return the new dimension. */ protected ZZDimension createDimension(String s) { if(s.indexOf(':') != -1) return createPartDimension(s); if(!validDim(s)) return null; ZZDimension l; if(s.equals("d.cellcreation")) { l = new IDDimension(); } else { l = new ZZLocalDimension(); } l.setSpace(this); return l; } protected ZZDimension createPartDimension(String s) { int ind = s.indexOf(':'); ZZSpacePart part = getSpacePartByID(s.substring(0, ind)); ZZDimension d = part.getDim(s.substring(ind+1)); d.setSpace(this); return d; } }