// boolean handleChildShift(AElement element, int expectedOrderHandlingCount) super
 public void handleValidatingReduce() {
   reduce:
   {
     for (int i = 0; i < size; i++) {
       if (childStructureHandlers[i] != null) {
         childStructureHandlers[i].handleValidatingReduce();
         if (childParticleHandlers[i]
             == null) // this handler was already reduced as result of the child's reduction
         break reduce;
         childParticleHandlers[i].reportMissing(rule, startInputRecordIndex);
       } else if (childParticleHandlers[i] != null) {
         childParticleHandlers[i].reportMissing(rule, startInputRecordIndex);
       } else {
         if (rule.isChildRequired(i)) {
           SPattern child = rule.getChild(i);
           int minOccurs = child.getMinOccurs();
           errorCatcher.missingContent(rule, startInputRecordIndex, child, minOccurs, 0, null);
         }
       }
     }
     handleReduce();
   }
 }
  void setCurrentChildParticleHandler(SPattern childPattern) {
    // if(!childPattern.getParent().equals(rule)) throw new IllegalArgumentException();

    boolean missing = true;
    for (int i = 0; i < rule.getChildrenCount(); i++) {
      if (rule.getChild(i) == childPattern) missing = false;
    }
    if (missing) throw new IllegalArgumentException();

    int childIndex = childPattern.getChildIndex();
    if (childParticleHandlers[childIndex] == null) {
      childParticleHandlers[childIndex] = pool.getParticleHandler(childPattern, this, errorCatcher);
    }
    currentChildParticleHandler = childParticleHandlers[childIndex];
  }
  public boolean acceptsMDescendentReduce(SPattern p) {
    // TODO should you be more defensive and check if the p is the actual
    // pattern from the particle handler?
    // First thought: here is not really the case, there can be only one child.

    // if there is no corresponding ParticlEHandler, get one
    // if the ParticleHandler does not expect the last occurrence
    //				return true
    // else determine if this handler is satisfied or if it could be
    // satisfied by the shifting of p // here if the particleHandler's
    // distanceToSatisfaction < 1 it means that it is satisfied and it
    // cannot have any influence on the satisfactionLevel
    // if distanceToSatisfaction > 1 it means it is too far and one shift
    // cannot satisfy the rule anyway
    // if distanceToSatisfaction == 1 then the satisfactionLevel needs to
    // be tested
    // 		yes return parent.acceptsMDescendentReduce(rule)
    //		no return false

    // before every return recycle the ParticleHandler if it was aquired
    // only for this method

    ParticleHandler childParticleHandler = childParticleHandlers[p.getChildIndex()];
    boolean transitoryParticle = false;
    if (childParticleHandler == null) {
      childParticleHandler = pool.getParticleHandler(p, this, errorCatcher);
      transitoryParticle = true;
    }
    if (!childParticleHandler.expectsLastOccurrence()) {
      if (transitoryParticle) {
        childParticleHandler.recycle();
        childParticleHandler = null;
      }
      return true;
    } else {
      int distanceToSatisfaction = childParticleHandler.getDistanceToSatisfaction();
      if (transitoryParticle) {
        childParticleHandler.recycle();
        childParticleHandler = null;
      }
      if (isSatisfied()) return parent.acceptsMDescendentReduce(rule);
      else if (distanceToSatisfaction == 1 && satisfactionLevel == satisfactionIndicator + 1)
        return parent.acceptsMDescendentReduce(rule);
      else return false;
    }
  }
 void closeContentParticle(SPattern pattern) {
   int index = pattern.getChildIndex();
   childParticleHandlers[index].recycle();
   childParticleHandlers[index] = null;
 }
 public void closeContentStructure(SPattern pattern) {
   int index = pattern.getChildIndex();
   childStructureHandlers[index].recycle();
   childStructureHandlers[index] = null;
 }