public static FormIndex createBeginningOfFormIndex() { FormIndex begin = new FormIndex(-1, null); begin.beginningOfForm = true; return(begin); }
public static FormIndex createEndOfFormIndex() { FormIndex end = new FormIndex(-1, null); end.endOfForm = true; return(end); }
public static Boolean isSubElement(FormIndex parent, FormIndex child) { while (!parent.isTerminal() && !child.isTerminal()) { if (parent.getLocalIndex() != child.getLocalIndex()) { return(false); } if (parent.getInstanceIndex() != child.getInstanceIndex()) { return(false); } parent = parent.nextLevel; child = child.nextLevel; } //If we've gotten this far, at least one of the two is terminal if (!parent.isTerminal() && child.isTerminal()) { //can't be the parent if the child is earlier on return(false); } else if (parent.getLocalIndex() != child.getLocalIndex()) { //Either they're at the same level, in which case only //identical indices should match, or they should have //the same root return(false); } else if (parent.getInstanceIndex() != -1 && (parent.getInstanceIndex() != child.getInstanceIndex())) { return(false); } //Barring all of these cases, it should be true. return(true); }
public Boolean Equals(Object o) { if (!(o is FormIndex)) { return(false); } FormIndex a = this; FormIndex b = (FormIndex)o; return(a.compareTo(b) == 0); // //TODO: while(true) loops freak me out, this should probably // //get written more safely. -ctsims // // //Iterate over each level of reference, and identify whether // //each object stays in sync // while(true) { // if(index.isTerminal() != local.isTerminal() || // index.getLocalIndex() != local.getLocalIndex() || // index.getInstanceIndex() != local.getInstanceIndex()) { // return false; // } // if(index.isTerminal()) { // return true; // } // local = local.getNextLevel(); // index = index.getNextLevel(); // } // }
public virtual FormIndex getTerminal() { FormIndex walker = this; while (walker.nextLevel != null) { walker = walker.nextLevel; } return(walker); }
/** * @return the level of this index relative to the top level of the form */ public int getDepth() { int depth = 0; FormIndex ref_ = this; while (ref_ != null) { ref_ = ref_.nextLevel; depth++; } return(depth); }
public String ToString() { String ret = ""; FormIndex ref_ = this; while (ref_ != null) { ret += ref_.getLocalIndex(); ret += ref_.getInstanceIndex() == -1 ? ", " : "_" + ref_.getInstanceIndex() + ", "; ref_ = ref_.nextLevel; } return(ret); }
public static bool isSubIndex(FormIndex parent, FormIndex child) { if (child.Equals(parent)) { return(true); } else { if (parent == null) { return(false); } return(isSubIndex(parent.nextLevel, child)); } }
/// <summary> Takes in a form index which is a subset of this index, and returns the /// total difference between them. This is useful for stepping up the level /// of index specificty. If the subIndex is not a valid subIndex of this index, /// null is returned. Since the FormIndex represented by null is always a subset, /// if null is passed in as a subIndex, the full index is returned /// /// For example: /// Indices /// a = 1_0,2,1,3 /// b = 1,3 /// /// a.diff(b) = 1_0,2 /// /// </summary> /// <param name="subIndex"> /// </param> /// <returns> /// </returns> public virtual FormIndex diff(FormIndex subIndex) { if (subIndex == null) { return(this); } if (!isSubIndex(this, subIndex)) { return(null); } if (subIndex.Equals(this)) { return(null); } return(new FormIndex(nextLevel.diff(subIndex), this.snip())); }
/// <summary> Constructs an index which references an element past the level of /// specificity of the current context, founded by the currentLevel /// index. /// (currentLevel, (nextLevel...)) /// </summary> public FormIndex(FormIndex nextLevel, FormIndex currentLevel) { if (currentLevel == null) { this.nextLevel = nextLevel.nextLevel; this.localIndex = nextLevel.localIndex; this.instanceIndex = nextLevel.instanceIndex; this.reference = nextLevel.reference; } else { this.nextLevel = nextLevel; this.localIndex = currentLevel.LocalIndex; this.instanceIndex = currentLevel.InstanceIndex; this.reference = currentLevel.reference; } }
public override System.String ToString() { StringBuilder b = new StringBuilder(); FormIndex ref_Renamed = this; while (ref_Renamed != null) { b.append(ref_Renamed.LocalIndex); if (ref_Renamed.InstanceIndex != -1) { b.append("_").append(ref_Renamed.InstanceIndex); } b.append(", "); ref_Renamed = ref_Renamed.nextLevel; } return(b.toString()); }
/// <summary> Trims any negative indices from the end of the passed in index. /// /// </summary> /// <param name="index"> /// </param> /// <returns> /// </returns> public static FormIndex trimNegativeIndices(FormIndex index) { if (!index.isTerminal()) { return(new FormIndex(trimNegativeIndices(index.nextLevel), index)); } else { if (index.LocalIndex < 0) { return(null); } else { return(index); } } }
/// <returns> Only the local component of this Form Index. /// </returns> public virtual FormIndex snip() { FormIndex retval = new FormIndex(localIndex, instanceIndex, reference); return(retval); }
public virtual int compareTo(System.Object o) { if (!(o is FormIndex)) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Class.getName' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" throw new System.ArgumentException("Attempt to compare Object of type " + o.GetType().FullName + " to a FormIndex"); } FormIndex a = this; FormIndex b = (FormIndex)o; if (a.beginningOfForm) { return(b.beginningOfForm?0:-1); } else if (a.endOfForm) { return(b.endOfForm?0:1); } else { //a is in form if (b.beginningOfForm) { return(1); } else if (b.endOfForm) { return(-1); } } if (a.localIndex != b.localIndex) { return(a.localIndex < b.localIndex?-1:1); } else if (a.instanceIndex != b.instanceIndex) { return(a.instanceIndex < b.instanceIndex?-1:1); } else if ((a.NextLevel == null) != (b.NextLevel == null)) { return(a.NextLevel == null?-1:1); } else if (a.NextLevel != null) { return(a.NextLevel.compareTo(b.NextLevel)); } else { return(0); } // int comp = 0; // // //TODO: while(true) loops freak me out, this should probably // //get written more safely. -ctsims // while(comp == 0) { // if(index.isTerminal() != local.isTerminal() || // index.getLocalIndex() != local.getLocalIndex() || // index.getInstanceIndex() != local.getInstanceIndex()) { // if(local.localIndex > index.localIndex) { // return 1; // } else if(local.localIndex < index.localIndex) { // return -1; // } else if (local.instanceIndex > index.instanceIndex) { // return 1; // } else if (local.instanceIndex < index.instanceIndex) { // return -1; // } // // //This case is here as a fallback, but it shouldn't really // //ever be the case that two references have the same chain // //of indices without terminating at the same level. // else if (local.isTerminal() && !index.isTerminal()) { // return -1; // } else { // return 1; // } // } // else if(local.isTerminal()) { // break; // } // local = local.getNextLevel(); // index = index.getNextLevel(); // } // return comp; }
/// <summary> Constructs an index which indexes an element, and provides an index /// into that elements children /// /// </summary> /// <param name="nextLevel">An index into the referenced element's index /// </param> /// <param name="localIndex">An index to an element at the current level, a child /// element of which will be referenced by the nextLevel index. /// </param> /// <param name="reference">A reference to the instance element identified by this index; /// </param> public FormIndex(FormIndex nextLevel, int localIndex, TreeReference reference) : this(localIndex, reference) { this.nextLevel = nextLevel; }
/// <summary> Constructs an index which indexes an element, and provides an index /// into that elements children, along with the current index of a /// repeated instance. /// /// </summary> /// <param name="nextLevel">An index into the referenced element's index /// </param> /// <param name="localIndex">An index to an element at the current level, a child /// element of which will be referenced by the nextLevel index. /// </param> /// <param name="instanceIndex">How many times the element referenced has been /// repeated. /// </param> /// <param name="reference">A reference to the instance element identified by this index; /// </param> public FormIndex(FormIndex nextLevel, int localIndex, int instanceIndex, TreeReference reference) : this(nextLevel, localIndex, reference) { this.instanceIndex = instanceIndex; }
public int compareTo(Object o) { if (!(o is FormIndex)) { throw new ArgumentException("Attempt to compare Object of type " + o.GetType().Name + " to a FormIndex"); } FormIndex a = this; FormIndex b = (FormIndex)o; if (a.beginningOfForm) { return(b.beginningOfForm ? 0 : -1); } else if (a.endOfForm) { return(b.endOfForm ? 0 : 1); } else { //a is in form if (b.beginningOfForm) { return(1); } else if (b.endOfForm) { return(-1); } } if (a.localIndex != b.localIndex) { return(a.localIndex < b.localIndex ? -1 : 1); } else if (a.instanceIndex != b.instanceIndex) { return(a.instanceIndex < b.instanceIndex ? -1 : 1); } else if ((a.getNextLevel() == null) != (b.getNextLevel() == null)) { return(a.getNextLevel() == null ? -1 : 1); } else if (a.getNextLevel() != null) { return(a.getNextLevel().compareTo(b.getNextLevel())); } else { return(0); } // int comp = 0; // // //TODO: while(true) loops freak me out, this should probably // //get written more safely. -ctsims // while(comp == 0) { // if(index.isTerminal() != local.isTerminal() || // index.getLocalIndex() != local.getLocalIndex() || // index.getInstanceIndex() != local.getInstanceIndex()) { // if(local.localIndex > index.localIndex) { // return 1; // } else if(local.localIndex < index.localIndex) { // return -1; // } else if (local.instanceIndex > index.instanceIndex) { // return 1; // } else if (local.instanceIndex < index.instanceIndex) { // return -1; // } // // //This case is here as a fallback, but it shouldn't really // //ever be the case that two references have the same chain // //of indices without terminating at the same level. // else if (local.isTerminal() && !index.isTerminal()) { // return -1; // } else { // return 1; // } // } // else if(local.isTerminal()) { // break; // } // local = local.getNextLevel(); // index = index.getNextLevel(); // } // return comp; }