org.axonframework.common
Class CollectionUtils

java.lang.Object
  extended by org.axonframework.common.CollectionUtils

public abstract class CollectionUtils
extends Object

Utility methods for operations on collections.

Since:
0.7
Author:
Allard Buijze

Method Summary
static
<T> List<T>
filterByType(Iterable<?> collection, Class<T> expectedType)
          Returns a list of objects of expectedType contained in the given collection.
static
<T> T
getAnnotation(Annotation[] annotations, Class<T> annotationType)
          Finds an annotation of given annotationType from the given annotations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

filterByType

public static <T> List<T> filterByType(Iterable<?> collection,
                                       Class<T> expectedType)
Returns a list of objects of expectedType contained in the given collection. Any objects in the collection that are not assignable to the given expectedType are filtered out.

The order of the items in the list is the same as the order they were provided by the collection. The given collection remains unchanged by this method.

If the given collection is null, en empty list is returned.

Type Parameters:
T - The type items in the returned List must be assignable to.
Parameters:
collection - An iterable (e.g. Collection) containing the unfiltered items.
expectedType - The type items in the returned List must be assignable to.
Returns:
a list of objects of expectedType. May be empty, but never null.

getAnnotation

public static <T> T getAnnotation(Annotation[] annotations,
                                  Class<T> annotationType)
Finds an annotation of given annotationType from the given annotations. If annotations contains multiple annotations of the given type, the first one is returned. If none is found, this method returns null.

Type Parameters:
T - The type of annotation to search for
Parameters:
annotations - The annotations to search in
annotationType - The type of annotation to search for
Returns:
the first annotation found, or null if no such annotation is present


Copyright © 2010-2016. All Rights Reserved.