net.sf.staccatocommons.collections
Class Lists

java.lang.Object
  extended by net.sf.staccatocommons.collections.Lists

public class Lists
extends Object

Class methods for dealing with List

Author:
flbulgarelli

Constructor Summary
Lists()
           
 
Method Summary
static
<A> void
addAfter(List<A> list, A element, A reference)
          Inserts the given element after the reference.
static
<A> void
addBefore(List<A> list, A element, A reference)
          Inserts the given element before the reference.
static
<A> A
first(List<A> list)
          Retrieves the list first element (at position 0)
static
<A> List<A>
from(A... elements)
          Answers a new Unmodifiable list with the given elements.
static
<A> A
last(List<A> list)
          Retrieves the last element (at position size - 1)
static
<A> A
removeLast(List<A> list)
          Removes the list last element
static
<A> A
second(List<A> list)
          Retrieves the list second element (at position 1)
static
<A> A
third(List<A> list)
          Retrieves the list third element (at position 2)
static
<A> Class<List<A>>
type()
          Answers the List class, but preserving its element generic type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Lists

public Lists()
Method Detail

addAfter

public static <A> void addAfter(@NonNull
                                List<A> list,
                                A element,
                                A reference)
Inserts the given element after the reference. Throws NoSuchElementException if the list does not contain the reference

Type Parameters:
A - the list type
Parameters:
list - the list
element - the element to be inserted just afeter the reference element
reference - the reference. The list must contain it

addBefore

public static <A> void addBefore(@NonNull
                                 List<A> list,
                                 A element,
                                 A reference)
Inserts the given element before the reference. Throws NoSuchElementException if the list does not contain the reference

Type Parameters:
A - the list type
Parameters:
list - the list
element - the element to be inserted just before the reference element
reference - the reference. The list must contain it

removeLast

public static <A> A removeLast(@NonNull
                               List<A> list)
Removes the list last element

Type Parameters:
A -
Parameters:
list -
Returns:
the element removed

first

public static <A> A first(@NotEmpty
                          List<A> list)
Retrieves the list first element (at position 0)

Type Parameters:
A - the list elements type
Parameters:
list -
Returns:
the element at position 1 in the list
Throws:
IllegalArgumentException - if list is empty if list is empty is out of range
See Also:
List.get(int)

second

public static <A> A second(@MinSize(value=2)
                           List<A> list)
Retrieves the list second element (at position 1)

Type Parameters:
A - the list elements type
Parameters:
list -
Returns:
the element at position 1 in the list
Throws:
IndexOutOfBoundsException - if index is out of range
See Also:
List.get(int)

third

public static <A> A third(@MinSize(value=3)
                          List<A> list)
Retrieves the list third element (at position 2)

Type Parameters:
A - the list elements type
Parameters:
list -
Returns:
the element at position 2 in the list
Throws:
IndexOutOfBoundsException - if index is out of range
See Also:
List.get(int)

last

public static <A> A last(@NotEmpty
                         List<A> list)
Retrieves the last element (at position size - 1)

Type Parameters:
A - the list elements type
Parameters:
list -
Returns:
the element at position size - 1 in the list
Throws:
IndexOutOfBoundsException - if index is out of range
See Also:
List.get(int)

type

@Constant
public static <A> Class<List<A>> type()
Answers the List class, but preserving its element generic type. This method is mostly aimed to be used with Staccato-Commons-Lambda

Type Parameters:
A -
Returns:
(Class<List<A>>) List

from

public static <A> List<A> from(A... elements)
Answers a new Unmodifiable list with the given elements. This method is not equivalent to Arrays.asList(Object...), which answers mutable lists

Type Parameters:
A -
Parameters:
elements -
Returns:
an unmodifiable list


Get Staccatocommons at SourceForge.net. Fast, secure and Free Open Source software downloads