public void setDirection(String direction) { clearNext(); this.direction = direction; }
assert isLast(currPos); boolean nextExists = true; } else if (!makeNewSegmentIfNeeded || matchExistsAfterPosition(currPos, direction, false, true)) { Group grandparent = currPos.parent.getParent(); Index parentIndex = getIndex(grandparent, currPos.parent); Position parentPos = new Position(grandparent, parentIndex); if (parentRepeats && contains(parentPos.parent.get(parentPos.index.name, 0), direction, false, true)) { nextRep(parentPos); } else { nextExists = nextPosition(parentPos, direction, makeNewSegmentIfNeeded); newSegment(currPos.parent, direction);
/** * Sets this.next to the next position in the message (from the given position), * which could be the next sibling, a new segment, or the next rep * of the parent. See next() for details. */ private boolean nextPosition(Position currPos, String direction, boolean makeNewSegmentIfNeeded) throws HL7Exception { boolean nextExists = true; if (isLast(currPos)) { nextExists = nextFromGroupEnd(currPos, direction, makeNewSegmentIfNeeded); } else { nextSibling(currPos); } return nextExists; }
/** * Returns true if another object exists in the iteration sequence. */ public boolean hasNext() { boolean has = true; if (next == null) { if (Group.class.isAssignableFrom(currentStructure.getClass())) { groupNext((Group) currentStructure); } else { Group parent = currentStructure.getParent(); Index i = getIndex(parent, currentStructure); Position currentPosition = new Position(parent, i); try { if (parent.isRepeating(i.name) && currentStructure.getName().equals(direction)) { nextRep(currentPosition); } else { has = nextPosition(currentPosition, this.direction, this.handleUnexpectedSegments); } } catch (HL7Exception e) { throw new Error("HL7Exception arising from bad index: " + e.getMessage()); } } } log.debug("MessageIterator.hasNext() in direction {}? {}", direction, has); return has; }
matchExists = contains(s, name, firstDescendentsOnly, upToFirstRequired); for (int i = 0; i < siblings.length && !matchExists; i++) { if (after) { matchExists = contains(pos.parent.get(siblings[i]), name, firstDescendentsOnly, upToFirstRequired); if (upToFirstRequired && pos.parent.isRequired(siblings[i])) break; Position parentPos = new Position(grandparent, getIndex(grandparent, pos.parent)); matchExists = matchExistsAfterPosition(parentPos, name, firstDescendentsOnly, upToFirstRequired);
public void parse(Message message, String string) throws HL7Exception { MessageIterator messageIter = new MessageIterator(message, "MSH", true); FilterIterator.Predicate<Structure> segmentsOnly = new FilterIterator.Predicate<Structure>() { public boolean evaluate(Structure obj) { messageIter.setDirection(name); FilterIterator.Predicate<Structure> byDirection = new FilterIterator.Predicate<Structure>() { public boolean evaluate(Structure obj) {
Stack<MessageIterator.Index> indexStack = new Stack<MessageIterator.Index>(); do { MessageIterator.Index index = MessageIterator.getIndex(pathElem.getParent(), pathElem); indexStack.push(index); pathElem = pathElem.getParent();
for (int i = 0; i < names.length && !contains; i++) { try { contains = contains(g.get(names[i], 0), name, firstDescendentsOnly, upToFirstRequired); if (firstDescendentsOnly) break; if (upToFirstRequired && g.isRequired(names[i])) break;
Iterator<Structure> it = new MessageIterator(start, "doesn't exist", false); if (segmentsOnly) { it = new FilterIterator<Structure>(it, new StructurePredicate(Segment.class));
/** * Returns true if another object exists in the iteration sequence. */ public boolean hasNext() { boolean has = true; if (next == null) { if (Group.class.isAssignableFrom(currentStructure.getClass())) { groupNext((Group) currentStructure); } else { Group parent = currentStructure.getParent(); Index i = getIndex(parent, currentStructure); Position currentPosition = new Position(parent, i); try { if (parent.isRepeating(i.name) && currentStructure.getName().equals(direction)) { nextRep(currentPosition); } else { has = nextPosition(currentPosition, this.direction, this.handleUnexpectedSegments); } } catch (HL7Exception e) { throw new Error("HL7Exception arising from bad index: " + e.getMessage()); } } } log.debug("MessageIterator.hasNext() in direction {}? {}", direction, has); return has; }
matchExists = contains(s, name, firstDescendentsOnly, upToFirstRequired); for (int i = 0; i < siblings.length && !matchExists; i++) { if (after) { matchExists = contains(pos.parent.get(siblings[i]), name, firstDescendentsOnly, upToFirstRequired); if (upToFirstRequired && pos.parent.isRequired(siblings[i])) break; Position parentPos = new Position(grandparent, getIndex(grandparent, pos.parent)); matchExists = matchExistsAfterPosition(parentPos, name, firstDescendentsOnly, upToFirstRequired);
public void parse(Message message, String string) throws HL7Exception { MessageIterator messageIter = new MessageIterator(message, "MSH", true); FilterIterator.Predicate<Structure> segmentsOnly = new FilterIterator.Predicate<Structure>() { public boolean evaluate(Structure obj) { messageIter.setDirection(name); FilterIterator.Predicate<Structure> byDirection = new FilterIterator.Predicate<Structure>() { public boolean evaluate(Structure obj) {
Stack<MessageIterator.Index> indexStack = new Stack<MessageIterator.Index>(); do { MessageIterator.Index index = MessageIterator.getIndex(pathElem.getParent(), pathElem); indexStack.push(index); pathElem = pathElem.getParent();
for (int i = 0; i < names.length && !contains; i++) { try { contains = contains(g.get(names[i], 0), name, firstDescendentsOnly, upToFirstRequired); if (firstDescendentsOnly) break; if (upToFirstRequired && g.isRequired(names[i])) break;
Iterator<Structure> it = new MessageIterator(start, "doesn't exist", false); if (segmentsOnly) { it = new FilterIterator<Structure>(it, new StructurePredicate(Segment.class));
assert isLast(currPos); boolean nextExists = true; } else if (!makeNewSegmentIfNeeded || matchExistsAfterPosition(currPos, direction, false, true)) { Group grandparent = currPos.parent.getParent(); Index parentIndex = getIndex(grandparent, currPos.parent); Position parentPos = new Position(grandparent, parentIndex); if (parentRepeats && contains(parentPos.parent.get(parentPos.index.name, 0), direction, false, true)) { nextRep(parentPos); } else { nextExists = nextPosition(parentPos, direction, makeNewSegmentIfNeeded); newSegment(currPos.parent, direction);
/** * Sets this.next to the next position in the message (from the given position), * which could be the next sibling, a new segment, or the next rep * of the parent. See next() for details. */ private boolean nextPosition(Position currPos, String direction, boolean makeNewSegmentIfNeeded) throws HL7Exception { boolean nextExists = true; if (isLast(currPos)) { nextExists = nextFromGroupEnd(currPos, direction, makeNewSegmentIfNeeded); } else { nextSibling(currPos); } return nextExists; }
e.setSegmentRepetition(MessageIterator.getIndex(destination.getParent(), destination).rep); e.setSegmentName(destination.getName()); throw e;