org.ckkloverdos.collection
Interface IL

All Superinterfaces:
IToStringAware
All Known Implementing Classes:
L

public interface IL
extends IToStringAware

A generalized list with several element-processing methods, mainly influenced by functional-oriented programming.

All the methods that return an IL list always construct a new list unless specifically stated.

Indices start from zero. An improper index is an index beyond the bounds of this list (either negative or greater than size-1).

Author:
Christos KK Loverdos

Method Summary
 IL add(java.lang.Object o)
          Adds the element to the list.
 IL addAll(java.util.Collection c)
          Adds all the elements of the collection to this list.
 IL addAll(IL l)
          Adds all the elements of the given list to this one.
 IL addAll(java.lang.Object[] array)
          Adds all the elements of the array to this list.
 boolean all(IFilter filter)
          Returns true iff all the elements can be accepted by the filter.
 boolean all(IFilter filter, java.lang.Object hints)
          Returns true iff all the elements can be accepted by the filter.
 boolean any(IFilter filter)
          Returns true iff all the elements can be accepted by the filter.
 boolean any(IFilter filter, java.lang.Object hints)
          Returns true iff all the elements can be accepted by the filter.
 IL chopPrefix(java.lang.String prefix)
          Chops the prefix from all elements, which are assumed to be strings.
 IL chopPrefixRE(java.lang.String prefix)
          Chops the regular expression prefix from all elements, which are assumed to be strings.
 IL chopSuffix(java.lang.String suffix)
          Chops the suffix from all elements, which are assumed to be strings.
 IL chopSuffixRE(java.lang.String suffix)
          Chops the regula expression suffix from all elements, which are assumed to be strings.
 IL clear(java.lang.Object o)
          Completely removes the element from the list.
 boolean contains(java.lang.Object o)
          Returns true if this list contains the specified element.
 IL copy()
          Returns a copy of this list.
 IL filter(IFilter filter)
          Returns a new list with all the elements that are accepted by filter.
 IL filter(IFilter filter, java.lang.Object hints)
          Returns a new list with all the elements that are accepted by filter.
 IL filterEndsWith(java.lang.String s)
          Filters all elements that end with s, assuming that elements are strings.
 IL filterEndsWithRE(java.lang.String re)
           
 IL filterEndsWithRE(java.lang.String re, int modifiers)
           
 IL filterFindRE(java.lang.String re)
          Uses Matcher.find().
 IL filterFindRE(java.lang.String re, int modifiers)
          Uses Matcher.find().
 void filterForEach(IFilterProcedure procedure)
          Combines filtering and processing in one place.
 void filterForEach(IFilterProcedure procedure, java.lang.Object hints)
          Combines filtering and processing in one place.
 IL filterMap(IFilterFunction ff)
          Combines filtering and mapping in one place.
 IL filterMap(IFilterFunction ff, java.lang.Object hints)
          Combines filtering and mapping in one place.
 IL filterMatchesRE(java.lang.String re)
          Uses Matcher.matches().
 IL filterMatchesRE(java.lang.String re, int modifiers)
          Uses Matcher.matches().
 IL filterNotEndsWith(java.lang.String s)
          Filters all elements that end with s, assuming that elements are strings.
 IL filterNotEndsWithRE(java.lang.String re)
           
 IL filterNotEndsWithRE(java.lang.String re, int modifiers)
           
 IL filterNotFindRE(java.lang.String re)
          Uses Matcher.find().
 IL filterNotFindRE(java.lang.String re, int modifiers)
          Uses Matcher.find().
 IL filterNotMatchesRE(java.lang.String re)
          Uses Matcher.matches().
 IL filterNotMatchesRE(java.lang.String re, int modifiers)
          Uses Matcher.matches().
 IL filterNotStartsWith(java.lang.String s)
          Filters all elements that do not start with s, assuming that elements are strings.
 IL filterNotStartsWithRE(java.lang.String re)
           
 IL filterNotStartsWithRE(java.lang.String re, int modifiers)
           
 IL filterStartsWith(java.lang.String s)
          Filters all elements that start with s, assuming that elements are strings.
 IL filterStartsWithRE(java.lang.String re)
           
 IL filterStartsWithRE(java.lang.String re, int modifiers)
           
 void forEach(IProcedure procedure)
          Processes all alements with procedure.
 void forEach(IProcedure procedure, java.lang.Object hints)
          Processes all alements with procedure.
 java.lang.Object get(int i)
          Returns the i-th element of this list.
 java.lang.String getString(int i)
          Convenience method that returns the i-th string of this list, assuming that the list contains strings.
 java.lang.Object head()
          Returns the first element of this list, retrieved from the iterator.
 java.lang.Object head(IFilter filter)
          Returns the first element of this list that is accepted by filter.
 java.lang.Object head(IFilter filter, java.lang.Object hints)
          Returns the first element of this list that is accepted by filter.
 IL intersect(IL other)
          Returns a new list containg the elements of this list that also belong to the other list.
 boolean isArray()
          Returns true if this list wraps an Object array.
 boolean isCollection()
          Returns true if this list wraps a Collection.
 boolean isList()
          Returns true if this list wraps a Collection and more specifically a List.
 boolean isSet()
          Returns true if this list wraps a Collection and more specifically a Set.
 java.util.Iterator iterator()
          Returns an iterator over the elements in this list.
 java.util.Iterator iterator(IFilter filter)
          Returns an iterator over the elements in this list that are accepted by the given filter.
 java.util.Iterator iterator(IFilter filter, java.lang.Object hints)
          Returns an iterator over the elements in this list that are accepted by the given filter.
 IL map(IFunction function)
          Returns a new list containing all the elements of this list, mapped by function.
 IL map(IFunction function, java.lang.Object hints)
          Returns a new list containing all the elements of this list, mapped by function.
 IL minus(IL other)
          Returns a new list containg the elements of this list that do not belong to the other list.
 void print()
          Prints the elements to standard output.
 void print(java.io.PrintStream ps)
          Prints the elements to the PrintStream.
 void print(java.io.PrintWriter pw)
          Prints the elements to the PrintWriter.
 IL remove(java.lang.Object o)
          Removes the element from the list (only once).
 IL selectProperty(java.lang.String name)
          Returns a new list with the JavaBean properties of the given name for each element.
 IL setFrom(CollectionProxy proxy)
          Sets the elements of this list from those of the collection proxy.
 int size()
          Returns the number of elements in this list.
 IL sort()
          Sorts the elements of the list.
 IL sort(java.util.Comparator c)
          Sorts the elements of the list, using the given Comparator.
 IL tail()
          Returns the list constructed from this one if we remove the head().
 IL take(int n)
          Returns the first n elements of this list, n starting from one.
 java.lang.Object[] toArray()
          Returns an array containing all of the elements in this collection.
 java.lang.Object[] toArray(java.lang.Class arrayClass)
          Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified class.
 java.util.Collection toCollection()
          Returns a Collection containing the elements of this array.
 java.util.List toList()
          Returns a List containing the elements of this array.
 java.util.Set toSet()
          Returns a Set containing the unique elements of this array.
 java.util.SortedSet toSortedSet()
          Returns a SortedSet containing the unique elements of this array.
 java.lang.String[] toStringArray()
          Convenience method that returns the strings of this list, assuming of course that this list contains strings.
 IL union(IL other)
          Returns a new list containg the elements of this list along with the elements of other.
 IL unique()
          Returns a set containing the unique elements of this list.
 IL zip(IL other)
          Implements list zipping.
 
Methods inherited from interface org.ckkloverdos.string.IToStringAware
toStringAware
 

Method Detail

iterator

java.util.Iterator iterator()
Returns an iterator over the elements in this list.


iterator

java.util.Iterator iterator(IFilter filter)
Returns an iterator over the elements in this list that are accepted by the given filter.

Parameters:
filter -

iterator

java.util.Iterator iterator(IFilter filter,
                            java.lang.Object hints)
Returns an iterator over the elements in this list that are accepted by the given filter. The hints parameter is passed directly to the filter.

Parameters:
filter -
hints -

size

int size()
Returns the number of elements in this list.


contains

boolean contains(java.lang.Object o)
Returns true if this list contains the specified element.

Parameters:
o -

isArray

boolean isArray()
Returns true if this list wraps an Object array.


isCollection

boolean isCollection()
Returns true if this list wraps a Collection.


isSet

boolean isSet()
Returns true if this list wraps a Collection and more specifically a Set.


isList

boolean isList()
Returns true if this list wraps a Collection and more specifically a List.


toArray

java.lang.Object[] toArray()
Returns an array containing all of the elements in this collection. If this list is already wrapping an Object array, this array is returned.


toArray

java.lang.Object[] toArray(java.lang.Class arrayClass)
Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified class. If this list is already wrapping an Object array, this array is returned and it MUST be of the given type.


toStringArray

java.lang.String[] toStringArray()
Convenience method that returns the strings of this list, assuming of course that this list contains strings.


toList

java.util.List toList()
Returns a List containing the elements of this array. If this list is already wrapping a List, then it is returned intact, otherwise a new one is created.


toSet

java.util.Set toSet()
Returns a Set containing the unique elements of this array. If this list is already wrapping a Set, then it is returned intact, otherwise a new one is created.


toSortedSet

java.util.SortedSet toSortedSet()
Returns a SortedSet containing the unique elements of this array. If this list is already wrapping a SortedSet, then it is returned intact, otherwise a new one is created.


toCollection

java.util.Collection toCollection()
Returns a Collection containing the elements of this array. If this list is already wrapping a Collection, then it is returned intact, otherwise a new one is created.


get

java.lang.Object get(int i)
Returns the i-th element of this list.

Parameters:
i -

getString

java.lang.String getString(int i)
Convenience method that returns the i-th string of this list, assuming that the list contains strings.

Parameters:
i -

head

java.lang.Object head()
Returns the first element of this list, retrieved from the iterator.

Throws:
java.lang.IndexOutOfBoundsException - of the list has no elements.

head

java.lang.Object head(IFilter filter)
Returns the first element of this list that is accepted by filter. Elements are retrieved from the iterator.

Throws:
java.lang.IndexOutOfBoundsException - of the list has no elements or no element is accepted by filter.

head

java.lang.Object head(IFilter filter,
                      java.lang.Object hints)
Returns the first element of this list that is accepted by filter. Elements are retrieved from the iterator. The second parameter hints is directly passed to the filter.

Throws:
java.lang.IndexOutOfBoundsException - of the list has no elements or no element is accepted by filter.

tail

IL tail()
Returns the list constructed from this one if we remove the head(). If this list has no elements, an empty one is returned.


take

IL take(int n)
Returns the first n elements of this list, n starting from one. If the list contains less than n elements, all are returned. If n is less than one, an empty list is returned.

Example:

 IL il = new L("zero", "one", "two", "three", "four");
 StdLog.log("il = " + il.take(3));
 
prints:
 [0="zero", 1="one", 2="two"]
 

Parameters:
n -

filter

IL filter(IFilter filter)
Returns a new list with all the elements that are accepted by filter.

Parameters:
filter -

filter

IL filter(IFilter filter,
          java.lang.Object hints)
Returns a new list with all the elements that are accepted by filter. The second parameter hints is directly passed to the filter.


map

IL map(IFunction function)
Returns a new list containing all the elements of this list, mapped by function.

Parameters:
function -

map

IL map(IFunction function,
       java.lang.Object hints)
Returns a new list containing all the elements of this list, mapped by function. The second parameter hints is directly passed to the function.


filterMap

IL filterMap(IFilterFunction ff)
Combines filtering and mapping in one place.

Parameters:
ff -

filterMap

IL filterMap(IFilterFunction ff,
             java.lang.Object hints)
Combines filtering and mapping in one place. The second parameter hints is directly passed to ff.

If hints is an implementation of BinaryHint, then BinaryHint.getHintA() is passed to IFilter.accept(Object, Object) and BinaryHint.getHintB() is passed to IFunction.evaluate(Object, Object).

Parameters:
ff -
See Also:
BinaryHint

selectProperty

IL selectProperty(java.lang.String name)
Returns a new list with the JavaBean properties of the given name for each element.

If name ends with (), then the name is treated as a method, which is used to give the new elements.

Example

The code:
 IL il = new L("zero", "one", "two", "three", "four");
 System.out.println(il.selectProperty("length()"));
 
prints:
 [0=4, 1=3, 2=3, 3=5, 4=4]
 

Parameters:
name -

forEach

void forEach(IProcedure procedure)
Processes all alements with procedure.

Parameters:
procedure -

forEach

void forEach(IProcedure procedure,
             java.lang.Object hints)
Processes all alements with procedure. The second parameter hints is directly passed to procedure.

Parameters:
procedure -
hints -

filterForEach

void filterForEach(IFilterProcedure procedure)
Combines filtering and processing in one place. The elements to be processed are those accepted by the filter.


filterForEach

void filterForEach(IFilterProcedure procedure,
                   java.lang.Object hints)
Combines filtering and processing in one place. The elements to be processed are those accepted by the filter. The second parameter hints is directly passed to procedure.

If hints is an implementation of BinaryHint, then BinaryHint.getHintA() is passed to IFilter.accept(Object,Object) and BinaryHint.getHintB() is passed to IProcedure.process(Object, Object).

See Also:
BinaryHint

copy

IL copy()
Returns a copy of this list. The underlying backing store (collection or array) is preserved in the new list.


add

IL add(java.lang.Object o)
Adds the element to the list. The addition is made directly at the backing store and no new list is created.

If the backing store is an array, then the component type of the array must be assignable from the class of the new element, unless the new element is null.

Example 1

The code:
 IL l = new L("zero", "one", "two", "three", "four");
 System.out.println(l.add(new Integer(1000)));
 
will print:
 [0="zero", 1="one", 2="two", 3="three", 4="four", 5=1000]
 

Example 2

The code:
 IL l = new L(new String[]{"zero", "one", "two", "three", "four"});
 System.out.println(l.add(new Integer(1000)));
 
will throw an exception: java.lang.IllegalArgumentException: array element type mismatch.

Example 3

The code:
 IL l = new L(new Number[] {new Long(1), new Float(2.2)});
 System.out.println(l.add(new Integer(1000)));
 
will print:
 [0=1, 1=2.2, 2=1000]
 

Parameters:
o -
Returns:
this list with the new element added.

addAll

IL addAll(java.util.Collection c)
Adds all the elements of the collection to this list. The comments of add(Object) apply here as well.

Parameters:
c -

addAll

IL addAll(java.lang.Object[] array)
Adds all the elements of the array to this list. The comments of add(Object) apply here as well.

Parameters:
array -

addAll

IL addAll(IL l)
Adds all the elements of the given list to this one. The comments of add(Object) apply here as well.

Parameters:
l -

remove

IL remove(java.lang.Object o)
Removes the element from the list (only once). The deletion is made directly at the backing store and no new list is created.

Parameters:
o -

clear

IL clear(java.lang.Object o)
Completely removes the element from the list. The deletion is made directly at the backing store and no new list is created.

Parameters:
o -

setFrom

IL setFrom(CollectionProxy proxy)
Sets the elements of this list from those of the collection proxy. This is lightweight and just updates the underlying backing store reference with that of the proxy.

Parameters:
proxy -

all

boolean all(IFilter filter)
Returns true iff all the elements can be accepted by the filter. In case the list is empty, false is returned.

Parameters:
filter -

all

boolean all(IFilter filter,
            java.lang.Object hints)
Returns true iff all the elements can be accepted by the filter. In case the list is empty, false is returned. The second parameter hints is directly passed to filter.

Parameters:
filter -
hints -

any

boolean any(IFilter filter)
Returns true iff all the elements can be accepted by the filter. In case the list is empty, true is returned.

Parameters:
filter -

any

boolean any(IFilter filter,
            java.lang.Object hints)
Returns true iff all the elements can be accepted by the filter. In case the list is empty, true is returned. The second parameter hints is directly passed to filter.

Parameters:
filter -
hints -

unique

IL unique()
Returns a set containing the unique elements of this list. If the underlying backing store is already a set, then it is returned as is.


zip

IL zip(IL other)
Implements list zipping. The elements of the new list are instances of Pair. The backing store of the returned list is a List.

Parameters:
other -

sort

IL sort()
Sorts the elements of the list.


sort

IL sort(java.util.Comparator c)
Sorts the elements of the list, using the given Comparator.


union

IL union(IL other)
Returns a new list containg the elements of this list along with the elements of other.

Parameters:
other -

intersect

IL intersect(IL other)
Returns a new list containg the elements of this list that also belong to the other list.

Parameters:
other -

minus

IL minus(IL other)
Returns a new list containg the elements of this list that do not belong to the other list.

Parameters:
other -

chopPrefix

IL chopPrefix(java.lang.String prefix)
Chops the prefix from all elements, which are assumed to be strings. nulls pass through.

Parameters:
prefix -

chopPrefixRE

IL chopPrefixRE(java.lang.String prefix)
Chops the regular expression prefix from all elements, which are assumed to be strings. nulls pass through.

Parameters:
prefix -

chopSuffix

IL chopSuffix(java.lang.String suffix)
Chops the suffix from all elements, which are assumed to be strings. nulls pass through.


chopSuffixRE

IL chopSuffixRE(java.lang.String suffix)
Chops the regula expression suffix from all elements, which are assumed to be strings. nulls pass through.


filterStartsWith

IL filterStartsWith(java.lang.String s)
Filters all elements that start with s, assuming that elements are strings. nulls do not pass through.

Parameters:
s -

filterNotStartsWith

IL filterNotStartsWith(java.lang.String s)
Filters all elements that do not start with s, assuming that elements are strings. nulls pass through.

Parameters:
s -

filterEndsWith

IL filterEndsWith(java.lang.String s)
Filters all elements that end with s, assuming that elements are strings. nulls do not pass through.

Parameters:
s -

filterNotEndsWith

IL filterNotEndsWith(java.lang.String s)
Filters all elements that end with s, assuming that elements are strings. nulls pass through.

Parameters:
s -

filterFindRE

IL filterFindRE(java.lang.String re)
Uses Matcher.find(). nulls do not pass through.

Parameters:
re -

filterNotFindRE

IL filterNotFindRE(java.lang.String re)
Uses Matcher.find(). nulls pass through.

Parameters:
re -

filterFindRE

IL filterFindRE(java.lang.String re,
                int modifiers)
Uses Matcher.find(). nulls do not pass through.

Parameters:
re -

filterNotFindRE

IL filterNotFindRE(java.lang.String re,
                   int modifiers)
Uses Matcher.find(). nulls pass through.

Parameters:
re -

filterMatchesRE

IL filterMatchesRE(java.lang.String re)
Uses Matcher.matches(). nulls do not pass through.

Parameters:
re -

filterNotMatchesRE

IL filterNotMatchesRE(java.lang.String re)
Uses Matcher.matches(). nulls pass through.

Parameters:
re -

filterMatchesRE

IL filterMatchesRE(java.lang.String re,
                   int modifiers)
Uses Matcher.matches(). nulls do not pass through.

Parameters:
re -

filterNotMatchesRE

IL filterNotMatchesRE(java.lang.String re,
                      int modifiers)
Uses Matcher.matches(). nulls pass through.

Parameters:
re -

filterStartsWithRE

IL filterStartsWithRE(java.lang.String re)

filterNotStartsWithRE

IL filterNotStartsWithRE(java.lang.String re)

filterStartsWithRE

IL filterStartsWithRE(java.lang.String re,
                      int modifiers)

filterNotStartsWithRE

IL filterNotStartsWithRE(java.lang.String re,
                         int modifiers)

filterEndsWithRE

IL filterEndsWithRE(java.lang.String re)

filterNotEndsWithRE

IL filterNotEndsWithRE(java.lang.String re)

filterEndsWithRE

IL filterEndsWithRE(java.lang.String re,
                    int modifiers)

filterNotEndsWithRE

IL filterNotEndsWithRE(java.lang.String re,
                       int modifiers)

print

void print()
Prints the elements to standard output.


print

void print(java.io.PrintStream ps)
Prints the elements to the PrintStream.

Parameters:
ps -

print

void print(java.io.PrintWriter pw)
Prints the elements to the PrintWriter.

Parameters:
pw -


Copyright © 1999-2007 Christos KK Loverdos. All Rights Reserved.