/**
  * Method that will construct a parser (possibly a sequence) that contains all given sub-parsers.
  * All parsers given are checked to see if they are sequences: and if so, they will be
  * "flattened", that is, contained parsers are directly added in a new sequence instead of adding
  * sequences within sequences. This is done to minimize delegation depth, ideally only having just
  * a single level of delegation.
  */
 public static JsonParserSequence createFlattened(
     boolean checkForExistingToken, JsonParser first, JsonParser second) {
   if (!(first instanceof JsonParserSequence || second instanceof JsonParserSequence)) {
     return new JsonParserSequence(checkForExistingToken, new JsonParser[] {first, second});
   }
   ArrayList<JsonParser> p = new ArrayList<JsonParser>();
   if (first instanceof JsonParserSequence) {
     ((JsonParserSequence) first).addFlattenedActiveParsers(p);
   } else {
     p.add(first);
   }
   if (second instanceof JsonParserSequence) {
     ((JsonParserSequence) second).addFlattenedActiveParsers(p);
   } else {
     p.add(second);
   }
   return new JsonParserSequence(checkForExistingToken, p.toArray(new JsonParser[p.size()]));
 }
 protected void addFlattenedActiveParsers(List<JsonParser> result) {
   for (int i = _nextParser - 1, len = _parsers.length; i < len; ++i) {
     JsonParser p = _parsers[i];
     if (p instanceof JsonParserSequence) {
       ((JsonParserSequence) p).addFlattenedActiveParsers(result);
     } else {
       result.add(p);
     }
   }
 }
 @SuppressWarnings("resource")
 protected void addFlattenedActiveParsers(List<JsonParser> listToAddIn) {
   for (int i = _nextParserIndex - 1, len = _parsers.length; i < len; ++i) {
     JsonParser p = _parsers[i];
     if (p instanceof JsonParserSequence) {
       ((JsonParserSequence) p).addFlattenedActiveParsers(listToAddIn);
     } else {
       listToAddIn.add(p);
     }
   }
 }