return groupElt.getElements() ;
List<Element> groupElts = new ArrayList<Element>() ;
BasicPattern prevBGP = null ;
List<ElementFilter> filters = null ;
PathBlock prevPathBlock = null ;
for (Element elt : groupElt.getElements() )
{
if ( elt instanceof ElementFilter )
{
ElementFilter f = (ElementFilter)elt ;
if ( filters == null )
filters = new ArrayList<ElementFilter>() ;
filters.add(f) ;
// Collect filters but do not place them yet.
continue ;
}
// Rather ugly code that combines blocks.
if ( elt instanceof ElementTriplesBlock )
{
if ( prevPathBlock != null )
throw new ARQInternalErrorException("Mixed ElementTriplesBlock and ElementPathBlock (case 1)") ;
ElementTriplesBlock etb = (ElementTriplesBlock)elt ;
if ( prevBGP != null )
{
// Previous was an ElementTriplesBlock.
// Merge because they were adjacent in a group
// in syntax, so it must have been BGP, Filter, BGP.
// Or someone constructed a non-serializable query.
prevBGP.addAll(etb.getPattern()) ;
continue ;
}
// New BGP.
// Copy - so that any later mergings do not change the original query.
ElementTriplesBlock etb2 = new ElementTriplesBlock() ;
etb2.getPattern().addAll(etb.getPattern()) ;
prevBGP = etb2.getPattern() ;
groupElts.add(etb2) ;
continue ;
}
// TIDY UP - grr this is duplication.
// Can't mix ElementTriplesBlock and ElementPathBlock (which subsumes ElementTriplesBlock)
if ( elt instanceof ElementPathBlock )
{
if ( prevBGP != null )
throw new ARQInternalErrorException("Mixed ElementTriplesBlock and ElementPathBlock (case 2)") ;
ElementPathBlock epb = (ElementPathBlock)elt ;
if ( prevPathBlock != null )
{
prevPathBlock.addAll(epb.getPattern()) ;
continue ;
}
ElementPathBlock epb2 = new ElementPathBlock() ;
epb2.getPattern().addAll(epb.getPattern()) ;