de.hpi.fgis.dude.util
Class CollectionUtil

java.lang.Object
  extended by de.hpi.fgis.dude.util.CollectionUtil

public class CollectionUtil
extends Object

Convenience methods for collections.

Author:
Arvid.Heise

Constructor Summary
CollectionUtil()
           
 
Method Summary
static
<T> List<T>
asList(Iterator<T> iterator)
          Materializes the elements of the given Iterator into a List.
static
<T> T
first(Iterable<T> iterable)
          Returns the first element of the collection.
static
<T> T
first(List<T> list)
          Returns the first element of the collection.
static
<T> T
last(Iterable<T> iterable)
          Returns the last element of the collection.
static
<T> T
last(List<T> list)
          Returns the last element of the collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionUtil

public CollectionUtil()
Method Detail

last

public static <T> T last(List<T> list)
Returns the last element of the collection.

Type Parameters:
T - the element type
Parameters:
list - the collection
Returns:
the last element or null if the list is empty

last

public static <T> T last(Iterable<T> iterable)
Returns the last element of the collection.

Type Parameters:
T - the element type
Parameters:
iterable - the collection
Returns:
the last element or null if the list is empty

first

public static <T> T first(List<T> list)
Returns the first element of the collection.

Type Parameters:
T - the element type
Parameters:
list - the collection
Returns:
the first element or null if the list is empty

first

public static <T> T first(Iterable<T> iterable)
Returns the first element of the collection.

Type Parameters:
T - the element type
Parameters:
iterable - the collection
Returns:
the first element or null if the list is empty

asList

public static <T> List<T> asList(Iterator<T> iterator)
Materializes the elements of the given Iterator into a List.

Type Parameters:
T - the element type
Parameters:
iterator - the Iterator to materialize
Returns:
the List containing the materialized elements.


Copyright © 2011 Hasso Plattner Institute - Chair of Information Systems. All Rights Reserved.