public String toString() { return "SCatSequence(var=\"" + ((v == null) ? "<null>" : v.getName()) + "\",cats=" + cats + ((seqToCat == null) ? ",straight" : ",mapped") + ")"; }
public void reset() { if (seqToCat != null || catToSeq != null) { seqToCat = catToSeq = null; // easy - we drop everything ;) if (notifyVar) v.NotifyAll(new NotifyMsg(this, Common.NM_VarSeqChange)); else NotifyAll(new NotifyMsg(this, Common.NM_CatSeqChange)); } return; }
public boolean moveCatAtPosTo(int p1, int p2) { if (p1 == p2) return true; if (p1 < 0 || p2 < 0 || p1 >= cats || p2 >= cats) return Global.runtimeWarning( "SCatSequence on " + ((v == null) ? "<null>" : v.getName()) + ": moveCatAtPosTo(" + p1 + "," + p2 + ") out of range (" + cats + " cats)") != -1; if (seqToCat == null) createFields(); int c1 = seqToCat[p1]; if (p1 < p2) { // move to back int r = p1; while (r < p2) { int c = seqToCat[r + 1]; seqToCat[r] = c; catToSeq[c] = r; r++; } seqToCat[r] = c1; catToSeq[c1] = r; } else { // move to front int r = p1; while (r > p2) { int c = seqToCat[r - 1]; seqToCat[r] = c; catToSeq[c] = r; r--; } seqToCat[r] = c1; catToSeq[c1] = r; } if (notifyVar) v.NotifyAll(new NotifyMsg(this, Common.NM_VarSeqChange)); else NotifyAll(new NotifyMsg(this, Common.NM_CatSeqChange)); return true; }
/** returns the position of the category id */ public int posOfCat(int id) { if (id < 0 || id >= cats) return Global.runtimeWarning( "SCatSequence on " + ((v == null) ? "<null>" : v.getName()) + ": posOfCat(" + id + ") out of range (" + cats + " cats)"); return (catToSeq == null) ? id : catToSeq[id]; }
/** returns the category ID at position pos */ public int catAtPos(int id) { if (id < 0 || id >= cats) return Global.runtimeWarning( "SCatSequence on " + ((v == null) ? "<null>" : v.getName()) + ": catAtPos(" + id + ") out of range (" + cats + " cats)"); return (seqToCat == null) ? id : seqToCat[id]; }
void updateCats() { if (v == null) return; int cc = v.getNumCats(); if (cc == cats) return; if (cc == 0 || seqToCat == null || catToSeq == null) { seqToCat = catToSeq = null; cats = cc; return; } /* what do we do if a sequence already existed and the number of categories changed? currenty we simply discard any order - but that could be changed ... */ seqToCat = catToSeq = null; cats = cc; }
public boolean swapCats(int c1, int c2) { if (c1 < 0 || c2 < 0 || c1 >= cats || c2 >= cats) return Global.runtimeWarning( "SCatSequence on " + ((v == null) ? "<null>" : v.getName()) + ": swapCats(" + c1 + "," + c2 + ") out of range (" + cats + " cats)") != -1; if (seqToCat == null) createFields(); int p1 = catToSeq[c1]; int p2 = catToSeq[c2]; seqToCat[p1] = c2; seqToCat[p2] = c1; catToSeq[c1] = p2; catToSeq[c2] = p1; if (notifyVar) v.NotifyAll(new NotifyMsg(this, Common.NM_VarSeqChange)); else NotifyAll(new NotifyMsg(this, Common.NM_CatSeqChange)); return true; }
public SCatSequence(SVarInterface var, Object theOwner, boolean notifyVariable) { v = var; owner = theOwner; cats = (v != null) ? v.getNumCats() : 0; notifyVar = notifyVariable; }