i3.dragos.util
Class CollectionHelper

java.lang.Object
  extended by i3.dragos.util.CollectionHelper

public final class CollectionHelper
extends java.lang.Object

Helper class for retrieving a single element from a collection while ensuring in the process that the collection contains exactly one item.

Author:
Thorsten Hermes <thermes@i3.informatik.rwth-aachen.de>

Method Summary
static
<T> T
getSingleElement(java.util.Collection<T> c)
          Returns a single element from a Collection, does not specify the caller.
static
<T> T
getSingleElement(java.util.Collection<T> c, java.lang.String caller)
          Returns a single element from a Collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getSingleElement

public static <T> T getSingleElement(java.util.Collection<T> c)
                          throws EntityNotFoundException,
                                 MultipleResultsException
Returns a single element from a Collection, does not specify the caller.

Type Parameters:
T - The type of the elements in the collection.
Parameters:
c - The Collection.
Returns:
the single element.
Throws:
EntityNotFoundException - if the Collection is emtpy.
MultipleResultsException - if the Collection contained more than one element.

getSingleElement

public static <T> T getSingleElement(java.util.Collection<T> c,
                                     java.lang.String caller)
                          throws EntityNotFoundException,
                                 MultipleResultsException
Returns a single element from a Collection.

Type Parameters:
T - The type of the elements in the collection.
Parameters:
c - The Collection.
caller - Name of calling method, used in error messages (may be null).
Returns:
the single element.
Throws:
EntityNotFoundException - if the Collection is emtpy.
MultipleResultsException - if the Collection contained more than one element.


Copyright © 2002-2008 RWTH Aachen, Department of Computer Science 3 (Software Engineering). All Rights Reserved.