net.sf.jga.util |
Provides Facade objects for working with the algorithm functors, and a variety
of utility iterators for various purposes.
The functionality that is adapted from STL is provided by a set of functors in
the net.sf.jga.fn.algorithm package operate on iterators. To ease the
transition to this approach, there are two facade objects whose methods
correspond to the algorithms provided by STL.
The first, Algorithms, operates on collections, and is appropriate for getting
easy answers to common questions over collections. The second, Iterators, is
closer conceptually to the implementation, and is more appropriate if the same
function is to be called several times for a given collection. Most of the
methods in these two facades are a single logical statement (although sometimes
the singe statement is broken up for formatting reasons) that constructs and
invokes the appropriate algorithm functor.
The summary of the functions adapted from STL is as follows:
STL Function name | Facade method name | functor |
accumulate() | accumulate() | Accumulate |
adjacentDiff() | adjacentDiff() | TransformAdjacent(Minus) |
adjacent_find() | findAdjacent() | FindAdjacent |
count() | count() | Count |
count_if() | count() | Count |
equal() | equal() | varies based on form (3) |
find() | find() | Find |
find_first_of() | findElement() | FindElement |
find_if() | find() | Find |
for_each() | forEach() | ForEach (2) |
lexicographical_compare() | lessThan() | varies based on form (3) |
max() | maximum() | Find,MaxValue (4) |
max_element() | maximumValue() | MaxValue [collection] Accumulate [iteration] |
merge() | merge() | Merge |
min() | minimum() | Find,MinValue (4) |
min_element() | minimumValue() | MaxValue [collection] Accumulate [iteration] |
mismatch() | mismatch() | FindMismatch |
remove() | removeAll | n/a(5) |
remove_if() | removeAll | RemoveAll |
remove_copy() | removeAllCopy | RemoveAll(6) |
remove_copy_if() | removeAllCopy | RemoveAll(6) |
replace() | replaceAll | n/a(5) |
replace_if() | replaceAll | ReplaceAll |
replace_copy() | replaceAllCopy | ReplaceAll(6) |
replace_copy_if() | replaceAllCopy | ReplaceAll(6) |
search() | match() | FindSequence |
search_n() | findRepeated() | FindRepeated |
transform (unary form) | transformCopy | TransformUnary |
transform (binary form) | transformCopy | TransformUnary |
unique() | unique | n/a(5) |
unique_copy() | uniqueCopy | Unique(6) |
(2) - The ForEach functor returns the result of the final call to the
given functor, where the method returns the given functor.
(3) - The comparison operations are not implemented in terms of
functors found in net.sf.jga.fn.algorithm: they are generally implemented via
Comparators defined in net.sf.jga.util and comparison functors from
net.sf.jga.fn.comparison.
(4) - Only supported for collections, not for iterations. Again, we'd
need to be able to clone iterators in order to support them.
(5) - Works with Lists only (not general Collections). The only option
available for updating in place is via a ListIterator.
(6) - Unlike C++, the X_copy forms append to the output collection,
instead of overwriting it. In C++, the implementations can't assume the right to
enlarge the output collection (it might be an array or some other fixed size
structure) while in Java, the collections aren't inherently fixed size (if the
user passes a fixed size or capped size collection to one of these methods, we'll
pass through the appropriate exception, if necessary)
|
Java Source File Name | Type | Comment |
Algorithms.java | Class | Facade for the Algorithms adapted from STL, defined to work primarily with
collections. |
ArrayIterator.java | Class | Iterates over an array of objects. |
Arrays.java | Class | Miscellaneous utilities for working with arrays.
Copyright © 2004-2005 David A. |
ArrayUtils.java | Class | Miscellaneous utilities for working with arrays.
Copyright © 2004-2005 David A. |
CachingIterator.java | Class | Iterator that allows the program to retain the last few elements returned.
Copyright © 2003-2005 David A. |
ChainedComparator.java | Class | Comparator wrapper that uses a pair of comparators internally. |
CollectionUtils.java | Class | General utilites for working with collections. |
ComparableComparator.java | Class | Comparator used for objects that extend Comparable. |
EmptyIterator.java | Class | Iterator over an empty set of elements.
author: David A. |
EnumerationIterator.java | Class | Adapts an Enumeration to the Iterator and Iterable interfaces.
Copyright © 2003-2005 David A. |
FilterIterable.java | Class | Produces Iterators that only return elements that meet a given condition.
Copyright © 2005 David A. |
FilterIterator.java | Class | Iterator that only returns elements that meet the given selection criteria.
Note -- in addition to this class being deprecated in order to be moved,
its implementation of Iterable is also deprecated: the successor class
will not implement Iterable.
Copyright © 2002-2005 David A. |
FindAllIterator.java | Class | Iterator that applies one of the FindX functors as many times as possible.
Formally, this iterator uses a functor that takes one iterator and returns
an iterator, and repeatedly applies it to a given iterator until the result
iterator's hasNext() method is false.
Copyright © 2004-2005 David A. |
FindIterator.java | Class | Iterator that provides the ability to skip to the first/next element that
meets a particular criteria.
Copyright © 2003-2005 David A. |
Formattable.java | Interface | Interface for classes that can support the formatting of values via a UnaryFunctor,String>.
Copyright © 2005 David A. |
GenericComparator.java | Class | Comparator that applies a functor to each argument, then compares the
results. |
Iterables.java | Class | Facade for the Iterators in this package, supporting the new forloop syntax.
Only iterators that perform their service during the hasNext()/next()
sequence are given in this facade. |
IteratorComparator.java | Class | Comparator used to compare iterations lexically.
author: David A. |
Iterators.java | Class | Facade for the Algorithms adapted from STL, defined to work primarily with
iterators. |
LookAheadIterator.java | Class | Iterator that allows the program to look at and operate on the next few
elements without consuming them.
Copyright © 2003-2005 David A. |
MergeIterable.java | Class | Produces iterators over the combined contents of two iterables.
Iterator that merges the contents of two input iterators.
Copyright © 2005 David A. |
MergeIterator.java | Class | Iterator that merges the contents of two input iterators.
Note -- in addition to this class being deprecated in order to be moved,
its implementation of Iterable is also deprecated: the successor class
will not implement Iterable.
Copyright © 2003-2005 David A. |
NullComparator.java | Class | Comparator Decorator used to gracefully compare null and non-null values.
In most cases, passing a null to a Comparator results in a NullPointerException,
as (in the general case) null is not part of a class' strict ordering.
However, in many applications, null objects must be included in an ordering.
This wrapper can be used to shield an underlying Comparator from dealing
with where in the ordering null values should fall.
A flag is provided that determines whether nulls are less than non-nulls,
(the default case) or greater than non-nulls. |
SingletonIterator.java | Class | Iterates over a single item. |
StringTokenizerIterator.java | Class | Adapts a StringTokenizer to the Iterator interface.
Copyright © 2003-2005 David A. |
TransformAdjacentIterator.java | Class | Iterator that applies a given BinaryFunctor to successive pairs of elements
from a given iterator, returning the results as elements.
Note -- in addition to this class being deprecated in order to be moved,
its implementation of Iterable is also deprecated: the successor class
will not implement Iterable.
Copyright © 2004-2005 David A. |
TransformBinaryIterator.java | Class | Iterator that returns the results of applying the given functor to
corresponding elements of two given iterators. |
TransformIterator.java | Class | Iterator that returns the results of applying the given functor to the
elements of the given iterator.
Note -- in addition to this class being deprecated in order to be moved,
its implementation of Iterable is also deprecated: the successor class
will not implement Iterable.
Copyright © 2002-2005 David A. |
UniqueIterable.java | Class | Produces iterators that will not return the same element twice in succession.
Copyright © 2005 David A. |
UniqueIterator.java | Class | Iterator that will not return the same element twice in succession.
Note -- in addition to this class being deprecated in order to be moved,
its implementation of Iterable is also deprecated: the successor class
will not implement Iterable.
Copyright © 2003-2005 David A. |