Ejemplo n.º 1
0
 public double calculatePostage() {
   // create a visitor
   PostageVisitor visitor = new PostageVisitor();
   // iterate through all items
   for (Visitable item : items) {
     item.accept(visitor);
   }
   double postage = visitor.getTotalPostage();
   return postage;
 }
Ejemplo n.º 2
0
 // Work around HAPI #224: TSComponentOne implementation of isEmpty is buggy
 private static boolean isEmpty(Visitable v) throws HL7Exception {
   if (v == null) return true;
   if (v instanceof TSComponentOne) {
     TSComponentOne tsc1 = (TSComponentOne) v;
     return tsc1.getValue() == null || tsc1.getValue().isEmpty();
   }
   if (v instanceof Composite && v.getClass().getName().endsWith(".TS")) {
     Composite ts = (Composite) v;
     return isEmpty(ts.getComponent(0));
   }
   return v.isEmpty();
 }
Ejemplo n.º 3
0
 public Visitable visit(Visitable any) throws VisitFailure {
   int childCount = any.getChildCount();
   Visitable result = any;
   int successCount = 0;
   for (int i = 0; i < childCount; i++) {
     try {
       result = result.setChildAt(i, v.visit(any.getChildAt(i)));
       successCount++;
     } catch (VisitFailure f) {
     }
   }
   if (successCount == 0) {
     failure.setMessage(
         "Some: None of the " + childCount + " arguments of " + any + " succeeded.");
     throw failure;
   }
   return result;
 }
 @SuppressWarnings("rawtypes")
 @Override
 public void visit(Collection collection) {
   Iterator iterator = collection.iterator();
   while (iterator.hasNext()) {
     Object o = iterator.next();
     if (o instanceof Visitable) ((Visitable) o).accept(this);
     else if (o instanceof Collection) visit((Collection) o);
   }
 }
 public void visitVisitableCollection(VisitableCollection collection) {
   for (Object o : collection.value) {
     if (o instanceof Visitable) ((Visitable) o).accept(this);
   }
 }
 public T defaultVisit(Visitable visitable) {
   return visitable.visit(this);
 }