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 String ToString() { String ret = ""; FormIndex ref_ = this; while (ref_ != null) { ret += ref_.getLocalIndex(); ret += ref_.getInstanceIndex() == -1 ? ", " : "_" + ref_.getInstanceIndex() + ", "; ref_ = ref_.nextLevel; } return(ret); }
/** * Constructs an index which references an element past the level of * specificity of the current context, founded by the currentLevel * index. * (currentLevel, (nextLevel...)) */ 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.getLocalIndex(); this.instanceIndex = currentLevel.getInstanceIndex(); this.reference = currentLevel.reference; } }