Code example for Collection

Methods: iteratorsize

0
	 * @throws IncorrectResultSizeDataAccessException if more than one 
	 * result object has been found in the given Collection 
	 * @see org.springframework.util.CollectionUtils#hasUniqueObject 
	 */ 
	public static <T> T uniqueResult(Collection<T> results) throws IncorrectResultSizeDataAccessException {
		int size = (results != null ? results.size() : 0);
		if (size == 0) {
			return null; 
		} 
		if (!CollectionUtils.hasUniqueObject(results)) {
			throw new IncorrectResultSizeDataAccessException(1, size);
		} 
		return results.iterator().next();
	} 
 
	/** 
	 * Return a unique result object from the given Collection. 
	 * <p>Throws an exception if 0 or more than 1 instance found. 
	 * @param results the result Collection (can be {@code null}) 
	 * @return the unique result object