Esempio n. 1
0
 /**
  * Creates an empty instance of {@link Loop} and adds the loop as a child to the current Loop. The
  * returned instance can be used to add segments to the child loop.
  *
  * @param name name of the loop
  * @return a new child Loop object
  */
 public Loop addChild(String name) {
   Loop l = new Loop(this.context, name);
   l.setParent(this);
   l.depth = this.depth + 1; // debug
   loops.add(l);
   return l;
 }
Esempio n. 2
0
 /**
  * Creates a new {@link Loop} and replaces the child loop at the specified position. The returned
  * instance can be used to add segments to the child loop.
  *
  * @param name name of the loop
  * @param index position at which to add the loop.
  * @return a new child Loop object
  */
 public Loop setChild(int index, String name) {
   Loop l = new Loop(this.context, name);
   l.setParent(this);
   l.depth = this.depth + 1; // debug
   loops.set(index, l);
   return l;
 }
Esempio n. 3
0
 /**
  * Returns number of segments in Loop and child loops
  *
  * @return size
  */
 public int size() {
   int size;
   size = this.segments.size();
   for (Loop l : this.childList()) {
     size += l.size();
   }
   return size;
 }
Esempio n. 4
0
 /**
  * Returns the Loop in X12 {@link java.lang.String} format. This method is used to convert the X12
  * object into a X12 transaction.
  *
  * @param bRemoveTrailingEmptyElements a flag for whether or not empty trailing elements should be
  *     removed.
  * @return String representation of the loop.
  */
 public String toString(boolean bRemoveTrailingEmptyElements) {
   StringBuilder dump = new StringBuilder();
   for (Segment s : this.segments) {
     dump.append(s.toString(bRemoveTrailingEmptyElements));
     dump.append(context.getSegmentSeparator());
   }
   for (Loop l : this.childList()) {
     dump.append(l.toString(bRemoveTrailingEmptyElements));
   }
   return dump.toString();
 }
Esempio n. 5
0
 /**
  * Checks if the Loop contains the specified child Loop. It will check the complete child
  * hierarchy.
  *
  * @param name name of a child loop
  * @return boolean
  */
 public boolean hasLoop(String name) {
   for (Loop l : this.childList()) {
     if (name.equals(l.getName())) {
       return true;
     }
     if (l.hasLoop(name)) {
       return true;
     }
   }
   return false;
 }
Esempio n. 6
0
 /**
  * Returns the Loop in XML {@link java.lang.String} format. This method is used to convert the X12
  * object into a XML string.
  *
  * @param bRemoveTrailingEmptyElements a flag for whether or not empty trailing elements should be
  *     removed.
  * @return String the loop in XML string format.
  */
 public String toXML(boolean bRemoveTrailingEmptyElements) {
   StringBuilder dump = new StringBuilder();
   dump.append("<LOOP NAME=\"").append(this.name).append("\">");
   for (Segment s : this.segments) {
     dump.append(s.toXML(bRemoveTrailingEmptyElements));
   }
   for (Loop l : this.childList()) {
     dump.append(l.toXML(bRemoveTrailingEmptyElements));
   }
   dump.append("</LOOP>");
   return dump.toString();
 }
Esempio n. 7
0
 /**
  * Get the loop in the X12 transaction It will check the complete child hierarchy.
  *
  * @param name name of a loop
  * @return {@link java.util.List}&lt;{@link Loop}&gt;
  */
 public List<Loop> findLoop(String name) {
   List<Loop> foundLoops = new ArrayList<Loop>();
   for (Loop l : this.childList()) {
     if (name.equals(l.getName())) {
       foundLoops.add(l);
     }
     List<Loop> moreLoops = l.findLoop(name);
     if (moreLoops.size() > 0) {
       foundLoops.addAll(moreLoops);
     }
   }
   return foundLoops;
 }
Esempio n. 8
0
 /**
  * Get the segment in the X12 transaction It will check the current loop and the complete child
  * hierarchy.
  *
  * @param name name of a segment
  * @return {@link java.util.List}&lt;{@link Segment}&gt;
  */
 public List<Segment> findSegment(String name) {
   List<Segment> foundSegments = new ArrayList<Segment>();
   for (Segment s : this.segments) {
     if (name.equals(s.getElement(0))) {
       foundSegments.add(s);
     }
   }
   for (Loop l : this.childList()) {
     List<Segment> moreSegments = l.findSegment(name);
     if (moreSegments.size() > 0) {
       foundSegments.addAll(moreSegments);
     }
   }
   return foundSegments;
 }
Esempio n. 9
0
 /**
  * Inserts {@link Loop} as a child loop at the specified position.
  *
  * @param index position at which to add the loop.
  * @param loop a {@link Loop} object.
  */
 public void addChild(int index, Loop loop) {
   loop.setParent(this);
   loop.depth = this.depth + 1; // debug
   loops.add(index, loop);
 }