icegem-core/src/main/java/com/googlecode/icegem/query/bucketoriented/BucketOrientedQueryService.java
@SuppressWarnings({ "unchecked" })
    private static SelectResults<Object> formatSelectResults(List<List<Object>> queryResults, int limit) {
	List<Object> list = new ArrayList<Object>();

	ObjectType baseElementType = null;

	for (List<Object> queryResult : queryResults) {
	    ObjectType elementType = (ObjectType) queryResult.remove(queryResult.size() - 1);

	    if (baseElementType == null) {
		baseElementType = elementType;
	    } else if (!baseElementType.equals(elementType)) {
		throw new IllegalStateException("Collection types for query result are different.");
	    }

	    list.addAll(queryResult);

	    if (limit != -1 && list.size() >= limit) {
		break;
	    }
	}

	return limit == -1 ? new ResultsCollectionWrapper(baseElementType, list) : new ResultsCollectionWrapper(
		baseElementType, list, limit);
    }
@SuppressWarnings({ "unchecked" })
    private static SelectResults<Object> formatSelectResults(List<List<Object>> queryResults, int limit) {
	List<Object> list = new ArrayList<Object>();

	ObjectType baseElementType = null;

	for (List<Object> queryResult : queryResults) {
	    ObjectType elementType = (ObjectType) queryResult.remove(queryResult.size() - 1);

	    if (baseElementType == null) {
		baseElementType = elementType;
	    } else if (!baseElementType.equals(elementType)) {
		throw new IllegalStateException("Collection types for query result are different.");
	    }

	    list.addAll(queryResult);

	    if (limit != -1 && list.size() >= limit) {
		break;
	    }
	}

	return limit == -1 ? new ResultsCollectionWrapper(baseElementType, list) : new ResultsCollectionWrapper(
		baseElementType, list, limit);
    }
@ SuppressWarnings ( { "unchecked" } ) private static SelectResults < Object > formatSelectResults ( List < List < Object > > queryResults , int limit ) { List < Object > list = new ArrayList < Object > ( ) ; ObjectType baseElementType = null ; for ( List < Object > queryResult : queryResults ) { ObjectType elementType = ( ObjectType ) queryResult . remove ( queryResult . size ( ) - 1 ) ; if ( baseElementType == null ) { baseElementType = elementType ; } else if ( ! baseElementType . equals ( elementType ) ) { throw new IllegalStateException ( "Collection types for query result are different." ) ; } list . addAll ( queryResult ) ; if ( limit != - 1 && list . size ( ) >= limit ) { break ; } } return limit == - 1 ? new ResultsCollectionWrapper ( baseElementType , list ) : new ResultsCollectionWrapper ( baseElementType , list , limit ) ; }
Collects and formats query results into SelectResults. Limits query results based on limit value.

@param queryResults Query results from several nodes.
@param limit Query results limit.
@return Aggregated query results represented by instance of {@link SelectResults}.
Collects and formats query results into SelectResults . Limits query results based on limit value .