/** * @see java.util.Iterator#next() */ public Structure next() { if (!hasNext()) { throw new NoSuchElementException("No more nodes in message"); } Structure next = myRemaining.remove(myRemaining.size() - 1); if (next instanceof Group) { addChildren((Group) next); } return next; }
/** * @param theRoot root of depth first iteration, which starts with the first child * @return an iterator that skips groups and empty segments, returning only populated * segments */ public static Iterator<Structure> createPopulatedSegmentIterator(Group theRoot) { return createPopulatedStructureIterator(theRoot, Segment.class); }
/** * @param theRoot root of depth first iteration, which starts with the first child */ public ReadOnlyMessageIterator(Group theRoot) { myRemaining = new ArrayList<Structure>(40); addChildren(theRoot); }
/** * @param theRoot root of depth first iteration, which starts with the first child * @param structureFilter filter class * @return iterator that skips all structures that the filter does not accept */ public static Iterator<Structure> createPopulatedStructureIterator(Group theRoot, FilterIterator.Predicate<Structure> structureFilter) { Iterator<Structure> allIterator = new ReadOnlyMessageIterator(theRoot); Iterator<Structure> structureIterator = new FilterIterator<Structure>(allIterator, structureFilter); FilterIterator.Predicate<Structure> populatedOnly = new FilterIterator.Predicate<Structure>() { public boolean evaluate(Structure obj) { try { return !obj.isEmpty(); } catch (HL7Exception e) { return false; // no exception expected } } }; return new FilterIterator<Structure>(structureIterator, populatedOnly); }
private void testPrimitiveRules(Message message, ValidationExceptionHandler<R> handler) throws HL7Exception { LOG.debug("Validating message against primitive type rules"); for (Iterator<Structure> iter = ReadOnlyMessageIterator .createPopulatedSegmentIterator(message); iter.hasNext();) { Segment s = (Segment) iter.next(); for (int field = 1; field <= s.numFields(); field++) { Type[] t = s.getField(field); for (int rep = 0; rep < t.length; rep++) { Location location = new Location(); location .withSegmentName(s.getName()) .withField(field) .withFieldRepetition(rep); testType(t[rep], handler, location); } } } }
/** * @param theRoot root of depth first iteration, which starts with the first child */ public ReadOnlyMessageIterator(Group theRoot) { myRemaining = new ArrayList<Structure>(40); addChildren(theRoot); }
/** * @param theRoot root of depth first iteration, which starts with the first child * @param structureFilter filter class * @return iterator that skips all structures that the filter does not accept */ public static Iterator<Structure> createPopulatedStructureIterator(Group theRoot, FilterIterator.Predicate<Structure> structureFilter) { Iterator<Structure> allIterator = new ReadOnlyMessageIterator(theRoot); Iterator<Structure> structureIterator = new FilterIterator<Structure>(allIterator, structureFilter); FilterIterator.Predicate<Structure> populatedOnly = new FilterIterator.Predicate<Structure>() { public boolean evaluate(Structure obj) { try { return !obj.isEmpty(); } catch (HL7Exception e) { return false; // no exception expected } } }; return new FilterIterator<Structure>(structureIterator, populatedOnly); }
private void testPrimitiveRules(Message message, ValidationExceptionHandler<R> handler) throws HL7Exception { LOG.debug("Validating message against primitive type rules"); for (Iterator<Structure> iter = ReadOnlyMessageIterator .createPopulatedSegmentIterator(message); iter.hasNext();) { Segment s = (Segment) iter.next(); for (int field = 1; field <= s.numFields(); field++) { Type[] t = s.getField(field); for (int rep = 0; rep < t.length; rep++) { Location location = new Location(); location .withSegmentName(s.getName()) .withField(field) .withFieldRepetition(rep); testType(t[rep], handler, location); } } } }
/** * @param theRoot root of depth first iteration, which starts with the first child * @return an iterator that skips groups and empty segments, returning only populated * segments */ public static Iterator<Structure> createPopulatedSegmentIterator(Group theRoot) { return createPopulatedStructureIterator(theRoot, Segment.class); }
/** * @see java.util.Iterator#next() */ public Structure next() { if (!hasNext()) { throw new NoSuchElementException("No more nodes in message"); } Structure next = myRemaining.remove(myRemaining.size() - 1); if (next instanceof Group) { addChildren((Group) next); } return next; }
/** * @param theRoot root of depth first iteration, which starts with the first child * @param c structure class to look for * @return an iterator that skips all structures that do not match the parameter */ public static Iterator<Structure> createPopulatedStructureIterator(Group theRoot, Class<? extends Structure> c) { return createPopulatedStructureIterator(theRoot, new StructurePredicate(c)); }
/** * @param theRoot root of depth first iteration, which starts with the first child * @param structureName structure name to look for * @return an iterator that skips all structures that do not match the parameter */ public static Iterator<Structure> createPopulatedStructureIterator(Group theRoot, String structureName) { return createPopulatedStructureIterator(theRoot, new StructureNamePredicate(structureName)); }
/** * @param theRoot root of depth first iteration, which starts with the first child * @param c structure class to look for * @return an iterator that skips all structures that do not match the parameter */ public static Iterator<Structure> createPopulatedStructureIterator(Group theRoot, Class<? extends Structure> c) { return createPopulatedStructureIterator(theRoot, new StructurePredicate(c)); }
/** * @param theRoot root of depth first iteration, which starts with the first child * @param structureName structure name to look for * @return an iterator that skips all structures that do not match the parameter */ public static Iterator<Structure> createPopulatedStructureIterator(Group theRoot, String structureName) { return createPopulatedStructureIterator(theRoot, new StructureNamePredicate(structureName)); }
public ValidationException[] apply(Message msg) { List<ValidationException> exceptions = new ArrayList<ValidationException>(); for (Iterator<Structure> iter = ReadOnlyMessageIterator .createPopulatedStructureIterator(msg, GenericSegment.class); iter.hasNext();) { String segmentName = iter.next().getName(); ValidationException ve = new ValidationException("Found unknown segment: " + segmentName); Location location = new Location().withSegmentName(segmentName); ve.setLocation(location); exceptions.add(ve); } return exceptions.toArray(new ValidationException[exceptions.size()]); }
public ValidationException[] apply(Message msg) { List<ValidationException> exceptions = new ArrayList<ValidationException>(); for (Iterator<Structure> iter = ReadOnlyMessageIterator .createPopulatedStructureIterator(msg, GenericSegment.class); iter.hasNext();) { String segmentName = iter.next().getName(); ValidationException ve = new ValidationException("Found unknown segment: " + segmentName); Location location = new Location().withSegmentName(segmentName); ve.setLocation(location); exceptions.add(ve); } return exceptions.toArray(new ValidationException[exceptions.size()]); }