|
Orbital library | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object orbital.util.Setops
public final class Setops
Contains utility methods for common set operations and more general collection operations.
The selection methods (select(Function, Collection,
Predicate, Comparator, boolean)
) encapsulate a generalization of
queries over Collections. These queries are build just like data
queries over tables with SQL. In a selection query, a Collection
is filtered to obtain the desired subset of data which matches the
criteria, with the order being induced by a Comparator.
With its highly flexible bulk-style data-processing operations,
Functionals
is a worthwhile and
extremely powerful supplement to Setops
.
Utility
,
Selectors
,
Collections
,
Functionals
,
Structured Query Language (SQL)Field Summary | |
---|---|
static java.util.Iterator |
EMPTY_ITERATOR
An iterator over the empty collection. |
static java.util.Iterator |
EMPTY_LIST_ITERATOR
A list iterator over the empty list. |
static BinaryFunction |
intersection
intersection of two collections. |
static Function |
intersectionFold
n-ary intersection of a list of collections. |
static BinaryFunction |
union
union of two collections. |
static Function |
unionFold
n-ary union of a list of collections. |
Method Summary | |
---|---|
static boolean |
all(java.util.Collection a,
java.util.Collection b,
BinaryPredicate found)
Checks whether all corresponding pairs of objects in two collection satisfy the specified predicate. |
static boolean |
all(java.util.Collection coll,
Predicate found)
Checks whether all objects in a collection satisfy the specified predicate. |
static boolean |
all(java.util.Iterator i,
java.util.Iterator j,
BinaryPredicate found)
|
static boolean |
all(java.util.Iterator i,
Predicate found)
|
static java.lang.Object |
any(java.util.Collection coll)
Get any object of a collection. |
static java.lang.Object |
argmax(java.util.Iterator choices,
Function f)
Get the maximum argument. |
static java.lang.Object |
argmin(java.util.Iterator choices,
Function f)
Get the minimum argument. |
static java.util.List |
asList(java.util.Iterator it)
Returns a list filled with the elements in the iterator. |
static java.util.Map |
asMap(java.lang.Object[][] entries)
Converts an array of key and values to a map. |
static java.util.Set |
asSet(java.util.Iterator it)
Returns a set filled with the elements in the iterator. |
static java.util.Collection |
complement(java.util.Collection universal,
java.util.Collection a)
Returns the complement of a collection in a universal set. |
static java.util.Set |
complement(java.util.Set universal,
java.util.Set a)
|
static java.util.SortedSet |
complement(java.util.SortedSet universal,
java.util.SortedSet a)
|
static void |
copy(java.util.ListIterator dest,
java.util.Iterator src)
Copies all of the elements from one list-iterator into another. |
static int |
count(java.util.Collection coll,
Predicate cond)
Counts the number of objects in a collection that satisfy the specified predicate. |
static int |
count(java.util.Iterator i,
Predicate cond)
|
static Function |
createSelection(Function what,
Predicate where,
java.util.Comparator orderBy,
boolean asc)
Creates a sophisticated selection filter. |
static Function |
createSelection(Predicate where)
|
static java.util.Collection |
cross(java.util.Collection a,
java.util.Collection b)
Returns the cross product (or cartesian product) of two collections. a × b = {(x,y) ¦ x∈a ∧ y∈b} |
static java.util.Iterator |
cross(java.util.Iterator a,
java.util.Iterator b)
|
static java.util.Collection |
cross(java.util.List a)
Returns the n-ary cross product (or cartesian product) of n collections. ×i=1,...,n ai = ∏i=1,...,n ai = {(xi)i=1,...,n ¦ ∀i=1,...,n xi∈ai} |
static java.util.Collection |
difference(java.util.Collection a,
java.util.Collection b)
Returns the difference of one collection to another. |
static java.util.Set |
difference(java.util.Set a,
java.util.Set b)
|
static java.util.SortedSet |
difference(java.util.SortedSet a,
java.util.SortedSet b)
|
static java.lang.Object |
epsilon(java.util.Collection coll,
Predicate found)
Return any element of a collection that satisfies the specified predicate. |
static java.lang.Object |
find(java.util.Collection coll,
Predicate found)
Return the first object in a collection that satisfies the specified predicate. |
static java.lang.Object |
find(java.util.Iterator i,
Predicate found)
|
static boolean |
hasDuplicates(java.util.Iterator i)
Check whether the given iterator produces duplicate entries. |
static void |
insert(java.util.List l,
java.lang.Object object)
insert object into l such that l is still sorted. |
static java.util.Collection |
intersection(java.util.Collection a,
java.util.Collection b)
Returns the intersection of two collections. |
static java.util.Set |
intersection(java.util.Set a,
java.util.Set b)
|
static java.util.SortedSet |
intersection(java.util.SortedSet a,
java.util.SortedSet b)
|
static java.util.List |
merge(java.util.Iterator x,
java.util.Iterator y,
java.util.Comparator comp)
Merge two iterator-views according to the order induced by a comparator. |
static java.util.List |
merge(java.util.List x,
java.util.List y,
java.util.Comparator comp)
Merge two collections according to the order induced by a comparator. |
static java.util.Collection |
newCollectionLike(java.util.Collection c)
Get a new instance of an empty collection of the same type as the one specified. |
static java.util.Set |
powerset(java.util.Set s)
Returns the powerset of a set, i.e. |
static java.util.Collection |
select(Function what,
java.util.Collection from)
|
static java.util.Collection |
select(Function what,
java.util.Collection from,
java.util.Collection wherePredicates)
|
static java.util.Collection |
select(Function what,
java.util.Collection from,
Predicate where)
|
static java.util.Collection |
select(Function what,
java.util.Collection from,
Predicate where,
java.util.Comparator orderBy,
boolean asc)
Select filter operation. |
static boolean |
some(java.util.Collection a,
java.util.Collection b,
BinaryPredicate found)
|
static boolean |
some(java.util.Collection coll,
Predicate found)
Checks whether some objects (at least one) in a collection satisfy the specified predicate. |
static boolean |
some(java.util.Iterator i,
java.util.Iterator j,
BinaryPredicate found)
|
static boolean |
some(java.util.Iterator i,
Predicate found)
|
static java.util.Collection |
symmetricDifference(java.util.Collection a,
java.util.Collection b)
Returns the symmetric difference of two collections. a Δ b := (a∖b) ∪ (b∖a) |
static java.util.Set |
symmetricDifference(java.util.Set a,
java.util.Set b)
|
static java.util.SortedSet |
symmetricDifference(java.util.SortedSet a,
java.util.SortedSet b)
|
static java.util.Collection |
union(java.util.Collection a,
java.util.Collection b)
Returns the union of two collections. |
static java.util.Iterator |
union(java.util.Iterator a,
java.util.Iterator b)
|
static java.util.Set |
union(java.util.Set a,
java.util.Set b)
|
static java.util.SortedSet |
union(java.util.SortedSet a,
java.util.SortedSet b)
|
static java.util.Collection |
unmodifiableCollectionLike(java.util.Collection c)
Returns an unmodifiable view of the same type as the collection specified. |
static java.util.Iterator |
unmodifiableIterator(java.util.Iterator i)
Returns an unmodifiable view of the specified iterator. |
static java.util.ListIterator |
unmodifiableListIterator(java.util.ListIterator i)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.util.Iterator EMPTY_ITERATOR
public static final java.util.Iterator EMPTY_LIST_ITERATOR
public static final BinaryFunction union
public static final Function unionFold
public static final BinaryFunction intersection
public static final Function intersectionFold
Method Detail |
---|
public static java.lang.Object find(java.util.Collection coll, Predicate found)
public static java.lang.Object find(java.util.Iterator i, Predicate found)
public static java.lang.Object epsilon(java.util.Collection coll, Predicate found)
null
if no such object exists.any(Collection)
public static int count(java.util.Collection coll, Predicate cond)
public static int count(java.util.Iterator i, Predicate cond)
public static boolean all(java.util.Collection coll, Predicate found)
Functionals.map(and, Functionals.map(Functionals.asFunction(found), i))
.Functionals
public static boolean all(java.util.Iterator i, Predicate found)
public static boolean all(java.util.Collection a, java.util.Collection b, BinaryPredicate found)
Functionals.map(and, Functionals.map(Functionals.asFunction(found), i), j)
.Functionals
public static boolean all(java.util.Iterator i, java.util.Iterator j, BinaryPredicate found)
public static boolean some(java.util.Collection coll, Predicate found)
Functionals.map(or, Functionals.map(Functionals.asFunction(found), i))
.Functionals
public static boolean some(java.util.Iterator i, Predicate found)
public static boolean some(java.util.Collection a, java.util.Collection b, BinaryPredicate found)
public static boolean some(java.util.Iterator i, java.util.Iterator j, BinaryPredicate found)
public static final java.lang.Object argmin(java.util.Iterator choices, Function f)
choices
- the available choices M.f
- the evaluation function f:M→R.
java.util.NoSuchElementException
- if !choices.hasNext()Operations.inf
,
Collections.min(Collection,Comparator)
,
Functionals.foldLeft(BinaryFunction, Object,Object[])
,
EvaluativeAlgorithm.EvaluationComparator
public static final java.lang.Object argmax(java.util.Iterator choices, Function f)
choices
- the available choices M.f
- the evaluation function f:M→R.
java.util.NoSuchElementException
- if !choices.hasNext()Operations.sup
,
Collections.max(Collection,Comparator)
,
Functionals.foldLeft(BinaryFunction, Object, Object[])
,
EvaluativeAlgorithm.EvaluationComparator
public static java.util.Collection union(java.util.Collection a, java.util.Collection b)
public static java.util.Set union(java.util.Set a, java.util.Set b)
public static java.util.SortedSet union(java.util.SortedSet a, java.util.SortedSet b)
public static java.util.Iterator union(java.util.Iterator a, java.util.Iterator b)
public static java.util.Collection intersection(java.util.Collection a, java.util.Collection b)
public static java.util.Set intersection(java.util.Set a, java.util.Set b)
public static java.util.SortedSet intersection(java.util.SortedSet a, java.util.SortedSet b)
public static java.util.Collection complement(java.util.Collection universal, java.util.Collection a)
public static java.util.Set complement(java.util.Set universal, java.util.Set a)
public static java.util.SortedSet complement(java.util.SortedSet universal, java.util.SortedSet a)
public static final java.util.Collection difference(java.util.Collection a, java.util.Collection b)
public static final java.util.Set difference(java.util.Set a, java.util.Set b)
public static final java.util.SortedSet difference(java.util.SortedSet a, java.util.SortedSet b)
public static java.util.Collection symmetricDifference(java.util.Collection a, java.util.Collection b)
public static java.util.Set symmetricDifference(java.util.Set a, java.util.Set b)
public static java.util.SortedSet symmetricDifference(java.util.SortedSet a, java.util.SortedSet b)
public static java.util.Collection cross(java.util.Collection a, java.util.Collection b)
Pair
objects.#outer(BinaryFunction, Collection, Collection)
public static java.util.Iterator cross(java.util.Iterator a, java.util.Iterator b)
public static java.util.Collection cross(java.util.List a)
Implemented as an iterative unrolling of a recursion.
a
- the list 〈a1,...,an〉 of collections ai to choose from.
List
objects.#outer(BinaryFunction, Collection, Collection)
,
"Axiom of Choice (for infinite case)"public static java.util.Set powerset(java.util.Set s)
public static java.lang.Object any(java.util.Collection coll)
// expresses don't care nondeterminism Object o = Setops.any(someCollection);
epsilon(Collection,Predicate)
public static java.util.List asList(java.util.Iterator it)
This method works somewhat like java.util.Arrays.asList(Object[]) but is not backed by the iterator.
Arrays.asList(Object[])
public static java.util.Set asSet(java.util.Iterator it)
Except for set notation, this method works somewhat like java.util.Arrays.asList(Object[]) but is not backed by the iterator.
Arrays.asList(Object[])
public static java.util.Collection newCollectionLike(java.util.Collection c)
If no such collection could be instantiated, a similar collection is used.
public static java.util.Iterator unmodifiableIterator(java.util.Iterator i)
Query operations on the returned iterator "read through" to the specified iterator, and attempts to modify the returned iterator result in an UnsupportedOperationException.
public static java.util.ListIterator unmodifiableListIterator(java.util.ListIterator i)
public static java.util.Collection unmodifiableCollectionLike(java.util.Collection c)
newCollectionLike(Collection)
,
Collections.unmodifiableCollection(Collection)
,
Collections.unmodifiableList(List)
,
Collections.unmodifiableSet(Set)
,
Collections.unmodifiableSortedSet(SortedSet)
public static void copy(java.util.ListIterator dest, java.util.Iterator src)
Of course the list-iterators will be at different positions when this method finishes.
dest
- The destination list-iterator.src
- The source list-iterator.
java.lang.IndexOutOfBoundsException
- if the destination list-iterator is too small to contain the entire source List.
java.lang.UnsupportedOperationException
- if the destination list-iterator does not support the set operation.Collections.copy(List,List)
public static java.util.List merge(java.util.List x, java.util.List y, java.util.Comparator comp)
public static java.util.List merge(java.util.Iterator x, java.util.Iterator y, java.util.Comparator comp)
public static final void insert(java.util.List l, java.lang.Object object)
public static final java.util.Map asMap(java.lang.Object[][] entries)
entries
- Contains keys and their values.
Stored as an array of length-2 arrays
with entries[i][0] being the key String
,
and entries[i][1] being the value Object
.Arrays.asList(Object[])
public static final Function createSelection(Function what, Predicate where, java.util.Comparator orderBy, boolean asc)
When applied upon a collection of objects the filter will perform an operation like ResultSet: SELECT whatFilter FROM ObjectCollection WHERE Predicate ORDER BY Comparator ASC|DESC.
This is a (minor) generalization offilter p | = | (|∅,f|) | )|
Where | |||
f a as | = | [a|as] | ⇐ p(a) |
f a as | = | as | ⇐ ¬p(a) |
what
- states what data in the collection is requested. All if null
. See Also Filters
.where
- states what predicate is checked as condition for selecting data elements. No condition if null
.orderBy
- states how to sort every two data elements. No sorting if null
.asc
- whether to use ascending order, or descending.
If false
, orderBy comparator will be used reverse.
Collection
,Iterator
.Filters
,
Functionals.Catamorphism
,
orbital.logic.functor.Functionals#filter(Predicate,Iterator)
public static final Function createSelection(Predicate where)
public static final java.util.Collection select(Function what, java.util.Collection from, Predicate where, java.util.Comparator orderBy, boolean asc)
ResultSet: SELECT whatFilter FROM ObjectCollection WHERE Predicate ORDER BY Comparator ASC|DESC.
what
- states what data in the collection is requested. All if null. See Also Filters
.from
- sets the source of data.where
- states what predicate is checked as condition for selecting data elements. None if null.orderBy
- states how to sort every two data elements. No sorting if null.asc
- whether to use ascending order, or descending.
If false, orderBy comparator will be used reverse.Filters
,
createSelection(Function,Predicate,Comparator,boolean)
public static final java.util.Collection select(Function what, java.util.Collection from, Predicate where)
public static final java.util.Collection select(Function what, java.util.Collection from)
public static final java.util.Collection select(Function what, java.util.Collection from, java.util.Collection wherePredicates)
public static boolean hasDuplicates(java.util.Iterator i)
|
Orbital library 1.3.0: 11 Apr 2009 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |