|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.ckkloverdos.collection.L
public class L
Basic implementation of IL
.
Collection
or an
array of objects and treats theses two cases uniformly.
Arrays of primitive types are not supported, so this will throw an
exception:
L l = new L(new int[]{1, 2, 3}); System.out.println(l);
Field Summary | |
---|---|
protected java.lang.Object[] |
array
|
protected java.util.Collection |
col
|
Constructor Summary | |
---|---|
L()
Constructs a new list. |
|
L(java.util.Collection collection)
Constructs a new list with the provided collection as the backing store. |
|
L(java.util.Iterator iterator)
Constructs a new list from the elements provided by the iterator . |
|
L(java.lang.Object o)
Constructs a new list. |
|
L(java.lang.Object[] array)
Constructs a new list with the provided array as the backing store. |
|
L(java.lang.Object a,
java.lang.Object b)
Constructs a new list with an Object array containing the two
objects as the backing store. |
|
L(java.lang.Object a,
java.lang.Object b,
java.lang.Object c)
Constructs a new list with an Object array containing the three
objects as the backing store. |
|
L(java.lang.Object a,
java.lang.Object b,
java.lang.Object c,
java.lang.Object d)
Constructs a new list with an Object array containing the four
objects as the backing store. |
|
L(java.lang.Object a,
java.lang.Object b,
java.lang.Object c,
java.lang.Object d,
java.lang.Object e)
Constructs a new list with an Object array containing the five
objects as the backing store. |
|
L(java.util.Set set)
Constructs a new list withe the provided set as the backing store. |
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 function)
Combines filtering and processing in one place. |
void |
filterForEach(IFilterProcedure function,
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 function)
Processes all alements with procedure . |
void |
forEach(IProcedure function,
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. |
int |
hashCode()
|
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. |
protected java.util.Collection |
newCollection()
|
protected java.util.Collection |
newCollection(java.util.Collection withItems)
|
protected java.util.Collection |
newCollection(java.util.Iterator withItems)
|
protected java.util.Collection |
newCollection(java.lang.Object[] withItems)
|
protected java.util.List |
newList()
|
protected java.util.List |
newList(java.util.Collection withElements)
|
protected java.util.List |
newList(java.util.Iterator withElements)
|
protected java.util.List |
newList(java.lang.Object[] withElements)
|
protected java.util.Set |
newSet()
|
protected java.util.Set |
newSet(java.util.Collection withElements)
|
protected java.util.Set |
newSet(java.util.Iterator withElements)
|
protected java.util.Set |
newSet(java.lang.Object[] withElements)
|
protected java.util.SortedSet |
newSortedSet()
|
protected java.util.SortedSet |
newSortedSet(java.util.Collection withElements)
|
protected java.util.SortedSet |
newSortedSet(java.util.Collection withElements,
java.util.Comparator c)
|
protected java.util.SortedSet |
newSortedSet(java.util.Comparator c)
|
protected java.util.SortedSet |
newSortedSet(java.lang.Object[] withElements)
|
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 propertyName)
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 |
toString()
|
java.lang.String[] |
toStringArray()
Convenience method that returns the strings of this list, assuming of course that this list contains strings. |
void |
toStringAware(ToString ts)
|
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 class java.lang.Object |
---|
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.util.Collection col
protected java.lang.Object[] array
Constructor Detail |
---|
public L()
List
.
public L(java.lang.Object o)
o
.
In particular:
o
is null
, an empty List
is used.
o
is a Collection
, it is used as the backing store.
o
is an Object
array
, it used as the backing store.
list
containing o
is used as the backing store.
o
- public L(java.lang.Object a, java.lang.Object b)
Object
array containing the two
objects as the backing store.
public L(java.lang.Object a, java.lang.Object b, java.lang.Object c)
Object
array containing the three
objects as the backing store.
public L(java.lang.Object a, java.lang.Object b, java.lang.Object c, java.lang.Object d)
Object
array containing the four
objects as the backing store.
public L(java.lang.Object a, java.lang.Object b, java.lang.Object c, java.lang.Object d, java.lang.Object e)
Object
array containing the five
objects as the backing store.
public L(java.util.Collection collection)
collection
as the backing store.
public L(java.util.Set set)
set
as the backing store.
set
- public L(java.util.Iterator iterator)
iterator
.
public L(java.lang.Object[] array)
Method Detail |
---|
protected java.util.SortedSet newSortedSet()
protected java.util.SortedSet newSortedSet(java.util.Comparator c)
protected java.util.Set newSet()
protected java.util.Set newSet(java.util.Collection withElements)
protected java.util.Set newSet(java.util.Iterator withElements)
protected java.util.SortedSet newSortedSet(java.util.Collection withElements)
protected java.util.SortedSet newSortedSet(java.util.Collection withElements, java.util.Comparator c)
protected java.util.Set newSet(java.lang.Object[] withElements)
protected java.util.SortedSet newSortedSet(java.lang.Object[] withElements)
protected java.util.Collection newCollection()
protected java.util.Collection newCollection(java.util.Collection withItems)
protected java.util.Collection newCollection(java.util.Iterator withItems)
protected java.util.Collection newCollection(java.lang.Object[] withItems)
protected java.util.List newList()
protected java.util.List newList(java.util.Collection withElements)
protected java.util.List newList(java.util.Iterator withElements)
protected java.util.List newList(java.lang.Object[] withElements)
public java.util.Iterator iterator()
iterator
in interface IL
public java.util.Iterator iterator(IFilter filter)
accepted
by the given filter
.
iterator
in interface IL
filter
- public java.util.Iterator iterator(IFilter filter, java.lang.Object hints)
accepted
by the given filter
.
The hints
parameter is passed directly to the filter
.
iterator
in interface IL
filter
- hints
- public int size()
size
in interface IL
public boolean contains(java.lang.Object o)
contains
in interface IL
o
- public boolean isArray()
true
if this list wraps an Object
array.
isArray
in interface IL
public boolean isCollection()
true
if this list wraps a Collection
.
isCollection
in interface IL
public boolean isSet()
true
if this list wraps a Collection
and more specifically a Set
.
isSet
in interface IL
public boolean isList()
true
if this list wraps a Collection
and more specifically a List
.
isList
in interface IL
public java.lang.Object[] toArray()
Object
array, this array
is returned.
toArray
in interface IL
public java.lang.Object[] toArray(java.lang.Class arrayClass)
Object
array, this array
is returned and it MUST be of the given type.
toArray
in interface IL
public java.lang.String[] toStringArray()
toStringArray
in interface IL
public java.util.List toList()
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.
toList
in interface IL
public java.util.Set toSet()
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.
toSet
in interface IL
public java.util.SortedSet toSortedSet()
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.
toSortedSet
in interface IL
public java.util.Collection toCollection()
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.
toCollection
in interface IL
public java.lang.Object get(int i)
i
-th element of this list.
If the underlying backing store is a set, then the order
is that of the set iterator.
get
in interface IL
i
- public java.lang.String getString(int i)
i
-th string of this list,
assuming that the list contains strings.
getString
in interface IL
i
- public java.lang.Object head()
iterator
.
head
in interface IL
java.lang.IndexOutOfBoundsException
- of the list has no elements.public IL tail()
head()
.
If this list has no elements, an empty one is returned.
tail
in interface IL
public IL take(int n)
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.
IL il = new L("zero", "one", "two", "three", "four"); StdLog.log("il = " + il.take(3));prints:
[0="zero", 1="one", 2="two"]
take
in interface IL
n
- public java.lang.Object head(IFilter filter)
filter
.
Elements are retrieved from the iterator
.
head
in interface IL
java.lang.IndexOutOfBoundsException
- of the list has no elements or no element
is accepted by filter
.public java.lang.Object head(IFilter filter, java.lang.Object hints)
filter
.
Elements are retrieved from the iterator
.
The second parameter hints
is directly passed to the filter
.
head
in interface IL
java.lang.IndexOutOfBoundsException
- of the list has no elements or no element
is accepted by filter
.public IL filter(IFilter filter)
filter
.
filter
in interface IL
filter
- public IL filter(IFilter filter, java.lang.Object hints)
filter
.
The second parameter hints
is directly passed to the filter
.
filter
in interface IL
public IL map(IFunction function)
function
.
map
in interface IL
function
- public IL map(IFunction function, java.lang.Object hints)
function
.
The second parameter hints
is directly passed to the function
.
map
in interface IL
public IL filterMap(IFilterFunction ff)
filterMap
in interface IL
ff
- public IL filterMap(IFilterFunction ff, java.lang.Object hints)
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)
.
filterMap
in interface IL
ff
- BinaryHint
public IL selectProperty(java.lang.String propertyName)
name
for each element.
If name
ends with ()
, then the name is treated as a method,
which is used to give the new elements.
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]
selectProperty
in interface IL
public void forEach(IProcedure function)
procedure
.
forEach
in interface IL
public void forEach(IProcedure function, java.lang.Object hints)
procedure
.
The second parameter hints
is directly passed to procedure
.
forEach
in interface IL
public void filterForEach(IFilterProcedure function)
filterForEach
in interface IL
public void filterForEach(IFilterProcedure function, java.lang.Object hints)
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)
.
filterForEach
in interface IL
BinaryHint
public IL copy()
copy
in interface IL
public IL add(java.lang.Object o)
null
.
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]
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
.
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]
add
in interface IL
o
-
public IL addAll(java.util.Collection c)
add(Object)
apply here as well.
addAll
in interface IL
c
- public IL addAll(java.lang.Object[] array)
array
to this list.
The comments of add(Object)
apply here as well.
addAll
in interface IL
array
- public IL addAll(IL l)
add(Object)
apply here as well.
addAll
in interface IL
l
- public IL remove(java.lang.Object o)
remove
in interface IL
o
- public IL clear(java.lang.Object o)
clear
in interface IL
o
- public IL setFrom(CollectionProxy proxy)
proxy
.
This is lightweight and just updates the underlying backing store
reference with that of the proxy
.
setFrom
in interface IL
proxy
- public void toStringAware(ToString ts)
toStringAware
in interface IToStringAware
public boolean all(IFilter filter)
true
iff all the elements can be accepted by the filter
.
In case the list is empty, false
is returned.
all
in interface IL
filter
- public boolean all(IFilter filter, java.lang.Object hints)
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
.
all
in interface IL
filter
- hints
- public boolean any(IFilter filter)
true
iff all the elements can be accepted by the filter
.
In case the list is empty, true
is returned.
any
in interface IL
filter
- public boolean any(IFilter filter, java.lang.Object hints)
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
.
any
in interface IL
filter
- hints
- public IL unique()
unique
in interface IL
public IL zip(IL other)
Pair
. The backing store of the returned
list is a List
.
zip
in interface IL
other
- public IL sort()
sort
in interface IL
public IL sort(java.util.Comparator c)
Comparator
.
sort
in interface IL
public IL union(IL other)
other
.
If the underlying backing store is a set for both lists, then the method
implements the set-theoretic union operation.
union
in interface IL
other
- public IL intersect(IL other)
other
list.
If the underlying backing store is a set for both lists, then the method
implements the set-theoretic intersection operation.
intersect
in interface IL
other
- public IL minus(IL other)
other
list.
If the underlying backing store is a set for both lists, then the method
implements the set-theoretic difference operation.
minus
in interface IL
other
- public java.lang.String toString()
toString
in class java.lang.Object
public IL chopPrefix(java.lang.String prefix)
prefix
from all elements, which are assumed to be strings.
null
s pass through.
chopPrefix
in interface IL
prefix
- public IL chopPrefixRE(java.lang.String prefix)
prefix
from all elements, which are assumed to be strings.
null
s pass through.
chopPrefixRE
in interface IL
prefix
- public IL chopSuffix(java.lang.String suffix)
suffix
from all elements, which are assumed to be strings.
null
s pass through.
chopSuffix
in interface IL
public IL chopSuffixRE(java.lang.String suffix)
suffix
from all elements, which are assumed to be strings.
null
s pass through.
chopSuffixRE
in interface IL
public IL filterStartsWith(java.lang.String s)
s
, assuming that elements are strings.
null
s do not pass through.
filterStartsWith
in interface IL
s
- public IL filterNotStartsWith(java.lang.String s)
s
, assuming that elements are strings.
null
s pass through.
filterNotStartsWith
in interface IL
s
- public IL filterEndsWith(java.lang.String s)
s
, assuming that elements are strings.
null
s do not pass through.
filterEndsWith
in interface IL
s
- public IL filterNotEndsWith(java.lang.String s)
s
, assuming that elements are strings.
null
s pass through.
filterNotEndsWith
in interface IL
s
- public IL filterFindRE(java.lang.String re)
Matcher.find()
.
null
s do not pass through.
filterFindRE
in interface IL
re
- public IL filterNotFindRE(java.lang.String re)
Matcher.find()
.
null
s pass through.
filterNotFindRE
in interface IL
re
- public IL filterFindRE(java.lang.String re, int modifiers)
Matcher.find()
.
null
s do not pass through.
filterFindRE
in interface IL
re
- public IL filterNotFindRE(java.lang.String re, int modifiers)
Matcher.find()
.
null
s pass through.
filterNotFindRE
in interface IL
re
- public IL filterMatchesRE(java.lang.String re)
Matcher.matches()
.
null
s do not pass through.
filterMatchesRE
in interface IL
re
- public IL filterNotMatchesRE(java.lang.String re)
Matcher.matches()
.
null
s pass through.
filterNotMatchesRE
in interface IL
re
- public IL filterMatchesRE(java.lang.String re, int modifiers)
Matcher.matches()
.
null
s do not pass through.
filterMatchesRE
in interface IL
re
- public IL filterNotMatchesRE(java.lang.String re, int modifiers)
Matcher.matches()
.
null
s pass through.
filterNotMatchesRE
in interface IL
re
- public IL filterStartsWithRE(java.lang.String re)
filterStartsWithRE
in interface IL
public IL filterNotStartsWithRE(java.lang.String re)
filterNotStartsWithRE
in interface IL
public IL filterStartsWithRE(java.lang.String re, int modifiers)
filterStartsWithRE
in interface IL
public IL filterNotStartsWithRE(java.lang.String re, int modifiers)
filterNotStartsWithRE
in interface IL
public IL filterEndsWithRE(java.lang.String re)
filterEndsWithRE
in interface IL
public IL filterNotEndsWithRE(java.lang.String re)
filterNotEndsWithRE
in interface IL
public IL filterEndsWithRE(java.lang.String re, int modifiers)
filterEndsWithRE
in interface IL
public IL filterNotEndsWithRE(java.lang.String re, int modifiers)
filterNotEndsWithRE
in interface IL
public int hashCode()
hashCode
in class java.lang.Object
public void print()
IL
print
in interface IL
public void print(java.io.PrintStream ps)
IL
PrintStream
.
print
in interface IL
public void print(java.io.PrintWriter pw)
IL
PrintWriter
.
print
in interface IL
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |