public void parse(Element parent,ElementMetadata<?,?> parentMetadata,Collection<Element> elements,ElementMetadata<?,?> metadata) throws ParseException {
  Preconditions.checkState(path.selectsElement(),"An attribute path cannot be used to parse elements.");
  Path bound=path.toAbsolute(parentMetadata);
  Collection<Element> parents=createParentElements(bound,parent,parentMetadata,elements.size());
  ElementKey<?,?> childKey=bound.getSelectedElementKey();
  ElementMetadata<?,?> childMetadata=bound.getSelectedElement();
  Iterator<Element> pIter=parents.iterator();
  Iterator<Element> eIter=elements.iterator();
  if (parents.size() > 1) {
    checkNotMultiple(childMetadata);
    while (pIter.hasNext() && eIter.hasNext()) {
      Element p=pIter.next();
      p.addElement(eIter.next());
    }
    return;
  }
  if (elements.size() > 1 && childMetadata != null && childMetadata.getCardinality() == Cardinality.SINGLE) {
    throw new IllegalStateException("Metadata for key " + childKey + " represents a single-cardinality element."+ " The path must contain at least one multiple-cardinality"+ " element in order to parse multiple elements.");
  }
  parent=pIter.next();
  while (eIter.hasNext()) {
    parent.addElement(eIter.next());
  }
}

public void parse ( Element parent , ElementMetadata < ? , ? > parentMetadata , Collection < Element > elements , ElementMetadata < ? , ? > metadata ) throws ParseException { Preconditions . checkState ( path . selectsElement ( ) , "An attribute path cannot be used to parse elements." ) ; Path bound = path . toAbsolute ( parentMetadata ) ; Collection < Element > parents = createParentElements ( bound , parent , parentMetadata , elements . size ( ) ) ; ElementKey < ? , ? > childKey = bound . getSelectedElementKey ( ) ; ElementMetadata < ? , ? > childMetadata = bound . getSelectedElement ( ) ; Iterator < Element > pIter = parents . iterator ( ) ; Iterator < Element > eIter = elements . iterator ( ) ; if ( parents . size ( ) > 1 ) { checkNotMultiple ( childMetadata ) ; while ( pIter . hasNext ( ) && eIter . hasNext ( ) ) { Element p = pIter . next ( ) ; p . addElement ( eIter . next ( ) ) ; } return ; } if ( elements . size ( ) > 1 && childMetadata != null && childMetadata . getCardinality ( ) == Cardinality . SINGLE ) { throw new IllegalStateException ( "Metadata for key " + childKey + " represents a single-cardinality element." + " The path must contain at least one multiple-cardinality" + " element in order to parse multiple elements." ) ; } parent = pIter . next ( ) ; while ( eIter . hasNext ( ) ) { parent . addElement ( eIter . next ( ) ) ; } }
parse multiple elements using the path . because the path only allows a single multiple cardinality element , we can correctly parse into the appropriate child locations by matching up our elements with the parents , and creating one element per passed in element once we hit a multiple cardinality path element .
