net.sf.jga.algorithms
Class ListAlgorithms

java.lang.Object
  extended by net.sf.jga.algorithms.ListAlgorithms

public class ListAlgorithms
extends java.lang.Object

Algorithms that modify a given list. Unlike the static algorithm classes within this package, this class will change the contents of its input.

Copyright © 2007 David A. Hall


Constructor Summary
ListAlgorithms()
           
 
Method Summary
static
<T,LT extends java.util.List<? extends T>>
LT
filter(LT list, UnaryFunctor<T,java.lang.Boolean> uf)
          Removes all elements from the list that do not meet the given selection criteria.
static
<T,LT extends java.util.List<? extends T>>
LT
remove(LT list, T value)
          removes all elements equal to the given value from the list,
static
<T,LT extends java.util.List<? extends T>>
LT
remove(LT list, T value, Equality<T> eq)
          removes elements equal to the given value from the list, using the given functor to compare for equality.
static
<T,LT extends java.util.List<? extends T>>
LT
remove(LT list, UnaryFunctor<T,java.lang.Boolean> pred)
          removes elements from the list that do meet the given selection criteria
static
<T,LT extends java.util.List<T>>
LT
replace(LT list, T value, T replacement)
          Replaces elements equal to the given value with the given replacement value.
static
<T,LT extends java.util.List<T>>
LT
replace(LT list, UnaryFunctor<T,java.lang.Boolean> test, T replacement)
          Tests each element in the list, and replaces elements that pass with the given value.
static
<T,LT extends java.util.List<T>>
LT
replace(LT list, UnaryFunctor<T,java.lang.Boolean> test, UnaryFunctor<T,T> fn)
          Tests each element in the list, and replaces elements that pass with the result of passing the element to the given replacement function.
static
<T,LT extends java.util.List<T>>
LT
reverse(LT list)
          Reverses the order of the list.
static
<T,LT extends java.util.List<T>>
LT
transform(LT list, UnaryFunctor<T,T> uf)
          Applies the UnaryFunctor to each element in the list, replacing each element with the result.
static
<T,LT extends java.util.List<? extends T>>
LT
unique(LT list)
          Removes all adjacent duplicate values in the given list, using equals() to compare adjacent elements.
static
<T,LT extends java.util.List<? extends T>>
LT
unique(LT list, BinaryFunctor<T,T,java.lang.Boolean> eq)
          Deprecated. use Unique.unique(Iterable,BinaryFunctor)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListAlgorithms

public ListAlgorithms()
Method Detail

filter

public static <T,LT extends java.util.List<? extends T>> LT filter(LT list,
                                                                   UnaryFunctor<T,java.lang.Boolean> uf)
Removes all elements from the list that do not meet the given selection criteria.

Returns:
the modified list

remove

public static <T,LT extends java.util.List<? extends T>> LT remove(LT list,
                                                                   T value)
removes all elements equal to the given value from the list,

Returns:
the modified list

remove

public static <T,LT extends java.util.List<? extends T>> LT remove(LT list,
                                                                   T value,
                                                                   Equality<T> eq)
removes elements equal to the given value from the list, using the given functor to compare for equality.

Returns:
the modified list

remove

public static <T,LT extends java.util.List<? extends T>> LT remove(LT list,
                                                                   UnaryFunctor<T,java.lang.Boolean> pred)
removes elements from the list that do meet the given selection criteria

Returns:
the modified list

transform

public static <T,LT extends java.util.List<T>> LT transform(LT list,
                                                            UnaryFunctor<T,T> uf)
Applies the UnaryFunctor to each element in the list, replacing each element with the result.

Returns:
the modified list

replace

public static <T,LT extends java.util.List<T>> LT replace(LT list,
                                                          T value,
                                                          T replacement)
Replaces elements equal to the given value with the given replacement value.

Returns:
the modified list

replace

public static <T,LT extends java.util.List<T>> LT replace(LT list,
                                                          UnaryFunctor<T,java.lang.Boolean> test,
                                                          T replacement)
Tests each element in the list, and replaces elements that pass with the given value.

Returns:
the modified list

replace

public static <T,LT extends java.util.List<T>> LT replace(LT list,
                                                          UnaryFunctor<T,java.lang.Boolean> test,
                                                          UnaryFunctor<T,T> fn)
Tests each element in the list, and replaces elements that pass with the result of passing the element to the given replacement function.

Returns:
the modified list

reverse

public static <T,LT extends java.util.List<T>> LT reverse(LT list)
Reverses the order of the list.

Returns:
the modified list

unique

public static <T,LT extends java.util.List<? extends T>> LT unique(LT list)
Removes all adjacent duplicate values in the given list, using equals() to compare adjacent elements.

Returns:
the modified list

unique

public static <T,LT extends java.util.List<? extends T>> LT unique(LT list,
                                                                   BinaryFunctor<T,T,java.lang.Boolean> eq)
Deprecated. use Unique.unique(Iterable,BinaryFunctor)

Removes all adjacent duplicate values in the given list, using the given functor to compare adjacent elements

Returns:
the modified list


Copyright © 2002-2006 David A. Hall. All Rights Reserved.