public IFormElement getChild(FormIndex index) { IFormElement element = this; while (index != null && index.isInForm()) { element = element.getChild(index.getLocalIndex()); index = index.getNextLevel(); } return element; }
public void collapseIndex( FormIndex index, Vector indexes, Vector multiplicities, Vector elements) { if (!index.isInForm()) { return; } IFormElement element = this; while (index != null) { int i = index.getLocalIndex(); element = element.getChild(i); indexes.addElement(new Integer(i)); multiplicities.addElement( new Integer(index.getInstanceIndex() == -1 ? 0 : index.getInstanceIndex())); elements.addElement(element); index = index.getNextLevel(); } }
public int compareTo(Object o) { if (!(o instanceof FormIndex)) throw new IllegalArgumentException( "Attempt to compare Object of type " + o.getClass().getName() + " 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; }