|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.mulgara.util.C
public class C
Generic Collections utility class.
This class defines static methods for operating on Collections and the functors found in
Fn1 and Fn2.
| Constructor Summary | |
|---|---|
C()
|
|
| Method Summary | ||
|---|---|---|
static
|
ascendingInsert(List<T> list,
T c)
Inserts an element into a list in ascending order. |
|
static
|
descendingInsert(List<T> list,
T c)
Inserts an element into an ordered list in descending order. |
|
static
|
first(Collection<T1> arg)
Returns the first item from an Iterable. |
|
static
|
first(LinkedList<T1> arg)
Returns the first item from a Collection. |
|
static
|
head(LinkedList<T1> arg)
Returns the head of a linked list. |
|
static
|
head(List<T1> arg)
Returns the head of a list. |
|
static
|
headN(LinkedList<T1> arg)
Returns the head of a linked list, with a null for an empty list. |
|
static
|
headN(List<T1> arg)
Returns the head of a list. |
|
static
|
intersect(List<T> list,
T[] array)
Method to create an intersection of a list and an array. |
|
static
|
intersect(Set<T> set,
T[] array)
Method to create an intersection of a set and an array. |
|
static
|
join(List<T> list,
String separator)
Method to join the elements of a list into a string. |
|
static
|
join(List<T> list,
String start,
String separator,
String end)
General method to join the elements of a list into a string. |
|
static
|
last(LinkedList<T1> arg)
Returns the final elements of a linked list. |
|
static
|
last(List<T1> arg)
Returns the final element of a list. |
|
static
|
lastN(LinkedList<T1> arg)
Returns the tail of a list. |
|
static
|
lastN(List<T1> arg)
Returns the tail of a list. |
|
static
|
map(Collection<T1> args,
Fn1<T1,T2> op)
Creates a new list by applying an operator to each element of an initial list. |
|
static
|
map(Collection<T1> args,
Fn1E<T1,T2,E> op)
Creates a new list by applying an operator to each element of an initial list. |
|
static
|
map(T1[] args,
Fn1<T1,T2> op)
The same method as map(Collection, Fn1) for arrays. |
|
static
|
map(T1[] args,
Fn1E<T1,T2,E> op)
The same method as map(Collection, Fn1E) for arrays. |
|
static
|
tail(List<T1> arg)
Returns the tail of a list. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public C()
| Method Detail |
|---|
public static final <T1,T2,E extends Exception> List<T2> map(Collection<T1> args,
Fn1E<T1,T2,E> op)
throws E extends Exception
result.get(i) == op( args.get(i) ) for 0 <= i < args.size()The operation in op may throw an exception.
T1 - The type of the elements in the arg list, which is also the
argument type for the operation.T2 - The type of the elements in the result list, which is also
the return type of the operation.E - The exception that my be thrown from Fn1E.call(Object).args - The input list.op - The operation to apply to the elements of the input list.
E - An exception that may be thrown from the Fn1E.call(Object) method.
E extends Exception
public static final <T1,T2,E extends Exception> List<T2> map(T1[] args,
Fn1E<T1,T2,E> op)
throws E extends Exception
map(Collection, Fn1E) for arrays.
E extends Exception
public static final <T1,T2> List<T2> map(Collection<T1> args,
Fn1<T1,T2> op)
result.get(i) == op( args.get(i) ) for 0 <= i < args.size()The operation in op may not throw an exception.
T1 - The type of the elements in the arg list, which is also the
argument type for the operation.T2 - The type of the elements in the result list, which is also
the return type of the operation.args - The input list.op - The operation to apply to the elements of the input list.
public static final <T1,T2> List<T2> map(T1[] args,
Fn1<T1,T2> op)
map(Collection, Fn1) for arrays.
public static final <T1> T1 head(LinkedList<T1> arg)
throws NoSuchElementException
LinkedList.getFirst()
T1 - The list element type.arg - The list.
NoSuchElementException - If the list is empty.
public static final <T1> T1 head(List<T1> arg)
throws NoSuchElementException
T1 - The list element type.arg - The list.
NoSuchElementException - If the list is empty.public static final <T1> T1 headN(LinkedList<T1> arg)
null for an empty list.
T1 - The list element type.arg - The list.
null if the list is empty.public static final <T1> T1 headN(List<T1> arg)
T1 - The list element type.arg - The list.
null if the list is empty.
public static final <T1> T1 last(LinkedList<T1> arg)
throws NoSuchElementException
LinkedList.getLast().
T1 - The list element type.arg - The list.
NoSuchElementException - If the list is empty.
public static final <T1> T1 last(List<T1> arg)
throws NoSuchElementException
T1 - The list element type.arg - The list.
IndexOutOfBoundsException - If the list is empty.
NoSuchElementExceptionpublic static final <T1> List<T1> tail(List<T1> arg)
T1 - The list element type.arg - The list to get the tail of.
public static final <T1> T1 lastN(LinkedList<T1> arg)
T1 - The list element type.arg - The list.
null if the list is empty.public static final <T1> T1 lastN(List<T1> arg)
T1 - The list element type.arg - The list.
null if the list is empty.
public static final <T1> T1 first(LinkedList<T1> arg)
throws NoSuchElementException
LinkedList.getFirst()
T1 - The element type.arg - The list.
NoSuchElementException - If the list is empty.
public static final <T1> T1 first(Collection<T1> arg)
throws NoSuchElementException
T1 - The element type.arg - The iterable collection.
NoSuchElementException - If the collection is empty.
public static final <T extends Comparable<T>> List<T> ascendingInsert(List<T> list,
T c)
T - The type of the element to be inserted. Must be comparable on itself.list - The list to insert into. This must already be ordered.c - The element to insert.
public static final <T extends Comparable<T>> List<T> descendingInsert(List<T> list,
T c)
T - The type of the element to be inserted. Must be comparable on itself.list - The list to insert into. This must already be ordered.c - The element to insert.
public static final <T> String join(List<T> list,
String separator)
T - The type of element in the list.list - The list to be converted to a string.separator - The separator to use between elements of the list. May be null.
public static final <T> String join(List<T> list,
String start,
String separator,
String end)
T - The type of element in the list.list - The list to be converted to a string.start - The start of the string. May be null.separator - The separator to use between elements of the list. May be null.end - The end of the string. May be null.
public static final <T> List<T> intersect(List<T> list,
T[] array)
list - The list to intersect. This will be an ArrayList, no matter the source type.array - The array to intersect against the list.
public static final <T> Set<T> intersect(Set<T> set,
T[] array)
set - The set to intersect. This will be a HashSet, no matter the source type.array - The array to intersect against the set.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||