|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jpaul.DataStructs.DSUtil
public final class DSUtil
DSUtil
is a wrapper for commonly used data-structure
utilities. It is a non-instantiatable class with useful
static members, similar to java.util.Collections
.
Method Summary | ||
---|---|---|
static
|
checkEq(E obj1,
E obj2)
Checks equality of two objects; deals with the case when obj1 is null, and next invokes
equals . |
|
static
|
disjoint(java.util.Collection<A> c1,
java.util.Collection<B> c2)
Checks whether two collections are disjoint. |
|
static
|
filterColl(java.lang.Iterable<E> coll,
Predicate<E> pred,
java.util.Collection<E> newColl)
Put in newColl all elements of coll
that satisfy the predicate pred . |
|
static
|
getFirst(java.lang.Iterable<E> iterable)
|
|
static
|
iterable2coll(java.lang.Iterable<E> itrbl)
Returns an immutable Collection view of an
Iterable . |
|
static
|
iterableContains(java.lang.Iterable<E> itrbl,
E elem)
Checks whether itrbl contains the element
elem . |
|
static
|
iterableSize(java.lang.Iterable<E> itrbl)
Computes, in linear time, the length of an Iterable . |
|
static
|
iterableSizeEq(java.lang.Iterable<E> itrbl,
int k)
Checks whether the iterable itrbl has exactly
k elements. |
|
static
|
iterableSizeGt(java.lang.Iterable<E> itrbl,
int k)
Checks whether the iterable itrbl has more than
k elements. |
|
static
|
iterableToString(java.lang.Iterable<E> itrbl)
|
|
static
|
map2fun(java.util.Map<K,V> map)
Construct a Function based on a map. |
|
static
|
mapColl(java.lang.Iterable<E1> coll,
Function<E1,E2> func,
java.util.Collection<E2> newColl)
Maps collection coll into a new collection
(stored in newColl ), according to the function
func . |
|
static
|
mapColl(java.lang.Iterable<E1> coll,
java.util.Map<E1,E2> map,
java.util.Collection<E2> newColl)
Similar to teh other mapColl method, but the
function is given as a map. |
|
static
|
mapColl2(java.lang.Iterable<E1> coll,
Function<E1,E2> func,
java.util.Collection<E2> newColl)
Similar to mapColl , but filters out all
null elements produced by func . |
|
static
|
mapIterable(java.lang.Iterable<A> itrblA,
Function<A,B> f)
|
|
static
|
mapIterator(java.util.Iterator<A> it,
Function<A,B> f)
|
|
static
|
mapList(java.util.List<A> list,
Function<A,B> f)
|
|
static
|
select(java.util.List<E> list,
java.util.List<java.lang.Integer> indices,
java.util.List<E> sel)
|
|
static java.lang.String |
toString(java.lang.Object o)
Returns "null" if the argument o is
null, and o.toString() otherwise. |
|
static
|
unionColl(java.util.Collection<E> c1,
java.util.Collection<E> c2)
Returns the immutable union of two collections. |
|
static
|
unionColl(java.util.Collection<E> c1,
java.util.Collection<E> c2,
java.util.Collection<E> c3)
Returns the immutable union of three collections. |
|
static
|
unionIterable(java.lang.Iterable<E> it1,
java.lang.Iterable<E> it2)
Returns an immutable Iterable that is the union
of two Iterable s. |
|
static
|
unionIterable(java.lang.Iterable<java.lang.Iterable<E>> its)
Returns an immutable Iterable that is the union
of several Iterable s (in the order thet are given
in its ). |
|
static
|
unionList(java.util.List<E> l1,
java.util.List<E> l2)
Returns an immutable List that is the union of
two lists: it contains first the elements from
l1 , and next the elements from
l2 . |
|
static
|
unmodifiableIterable(java.lang.Iterable<E> itrbl)
Transforms a normal Iterable into an unmodifiable
one. |
|
static
|
unmodifiableIterator(java.util.Iterator<E> it)
Transforms a normal Iterator into an unmodifiable
one. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static <E> boolean checkEq(E obj1, E obj2)
obj1
is null, and next invokes
equals
.
public static java.lang.String toString(java.lang.Object o)
"null"
if the argument o
is
null, and o.toString()
otherwise.
public static <E> java.util.Iterator<E> unmodifiableIterator(java.util.Iterator<E> it)
Iterator
into an unmodifiable
one. The resulting iterator does not support
remove
.
public static <E> java.lang.Iterable<E> unmodifiableIterable(java.lang.Iterable<E> itrbl)
Iterable
into an unmodifiable
one. The iterator over the resulting Iterable
does not support remove
.
public static <E> int iterableSize(java.lang.Iterable<E> itrbl)
Iterable
. This is done by iterating over all
elements from itrbl
and counting their number.
public static <E> boolean iterableSizeEq(java.lang.Iterable<E> itrbl, int k)
itrbl
has exactly
k
elements. Instead of computing the length of
itrbl
(complexity: linear in the length) and
comparing it with k
, we try to iterate exactly
k
times and next check that itrbl
is
exhausted.
Complexity: linear in k
. Hence, this test is
very fast for small k
s.
public static <E> boolean iterableSizeGt(java.lang.Iterable<E> itrbl, int k)
itrbl
has more than
k
elements. Instead of computing the length of
itrbl
(complexity: linear in the length) and
comparing it with k
, we try to iterate exactly
k
times and next check that itrbl
is NOT
exhausted.
Complexity: linear in k
. Hence, this test is
very fast for small k
s.
public static <E> boolean iterableContains(java.lang.Iterable<E> itrbl, E elem)
itrbl
contains the element
elem
.
public static <E> java.util.Collection<E> iterable2coll(java.lang.Iterable<E> itrbl)
Collection
view of an
Iterable
.
public static <E> java.util.List<E> unionList(java.util.List<E> l1, java.util.List<E> l2)
List
that is the union of
two lists: it contains first the elements from
l1
, and next the elements from
l2
.
public static <E> java.util.Collection<E> unionColl(java.util.Collection<E> c1, java.util.Collection<E> c2)
public static <E> java.util.Collection<E> unionColl(java.util.Collection<E> c1, java.util.Collection<E> c2, java.util.Collection<E> c3)
public static <E> java.lang.Iterable<E> unionIterable(java.lang.Iterable<E> it1, java.lang.Iterable<E> it2)
Iterable
that is the union
of two Iterable
s. The resulting
Iterable
contains first all elements from
it1
, and next all elements from it2
.
public static <E> java.lang.Iterable<E> unionIterable(java.lang.Iterable<java.lang.Iterable<E>> its)
Iterable
that is the union
of several Iterable
s (in the order thet are given
in its
).
public static <E> java.util.Collection<E> filterColl(java.lang.Iterable<E> coll, Predicate<E> pred, java.util.Collection<E> newColl)
newColl
all elements of coll
that satisfy the predicate pred
.
public static <E1,E2> java.util.Collection<E2> mapColl(java.lang.Iterable<E1> coll, Function<E1,E2> func, java.util.Collection<E2> newColl)
coll
into a new collection
(stored in newColl
), according to the function
func
.
public static <E1,E2> java.util.Collection<E2> mapColl2(java.lang.Iterable<E1> coll, Function<E1,E2> func, java.util.Collection<E2> newColl)
mapColl
, but filters out all
null
elements produced by func
.
mapColl(Iterable, Function, Collection)
public static <E1,E2> java.util.Collection<E2> mapColl(java.lang.Iterable<E1> coll, java.util.Map<E1,E2> map, java.util.Collection<E2> newColl)
mapColl
method, but the
function is given as a map. This map is expected to map all
elements from the entry collection coll
.
mapColl(Iterable, Function, Collection)
public static <K,V> Function<K,V> map2fun(java.util.Map<K,V> map)
Function
based on a map. The
resulting function will throw an exception if invoked on an
element that is unassigned in map
.
public static <E> E getFirst(java.lang.Iterable<E> iterable)
iterable
.
Returns null
if iterable
is empty.public static <A,B> java.util.Iterator<B> mapIterator(java.util.Iterator<A> it, Function<A,B> f)
public static <A,B> java.lang.Iterable<B> mapIterable(java.lang.Iterable<A> itrblA, Function<A,B> f)
public static <A,B> java.util.List<B> mapList(java.util.List<A> list, Function<A,B> f)
public static <S,A extends S,B extends S> boolean disjoint(java.util.Collection<A> c1, java.util.Collection<B> c2)
S
. The worst-case complexity is proportional to
the product of the lengths of the two collections. The
implementation checks that none of the elements of the
smallest collection is present in the second one. If
membership testing is O(1), the complexity of the disjointness
test is linear in the length of the smallest of the two
collections.
public static <E> java.util.List<E> select(java.util.List<E> list, java.util.List<java.lang.Integer> indices, java.util.List<E> sel)
public static <E> java.lang.String iterableToString(java.lang.Iterable<E> itrbl)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |