net.sf.jga.algorithms
Class Merge

java.lang.Object
  extended by net.sf.jga.algorithms.Merge

public class Merge
extends java.lang.Object

Algorithms that combine the contents of two inputs. The inputs may arrays, collections, or iterations. The append methods that appear here are historical -- the original implementation of append was a Merge where the functor was constant TRUE (always choosing the contents of the first input until it is exhausted). Now, the append methods delegate to the Append class, but due to backwards compatability (and a desire to shield the user from "unchecked" warnings caused by the use of a varargs array of generic types in the Append signatures), these methods will remain to support the most common use-case.

Copyright © 2006 David A. Hall


Nested Class Summary
static class Merge.MergeIterable<T>
          Produces iterators that return all of the merged contents of two inputs
static class Merge.MergeIterator<T>
          Iterator that merges the contents of two input iterators.
 
Constructor Summary
Merge()
           
 
Method Summary
static
<T> java.lang.Iterable<? extends T>
append(java.lang.Iterable<? extends T> input0, java.lang.Iterable<? extends T> input1)
          Returns an Iterable implementation that 'contains' all elements of first iterable followed by all elements of the second iterable
static
<T,TCollection extends java.util.Collection<? super T>>
TCollection
append(java.lang.Iterable<? extends T> cin1, java.lang.Iterable<? extends T> cin2, TCollection cout)
          Appends the values of the first and second collection to the output collection
static
<T> java.util.Iterator<? extends T>
append(java.util.Iterator<? extends T> iter1, java.util.Iterator<? extends T> iter2)
          Returns an Iterator that will return elements from the first input iterator followed by elements from the second input iterator.
static
<T> java.lang.Iterable<T>
append(T[] t0, T[] t1)
          Returns all elements of each array
static
<T extends java.lang.Comparable<? super T>>
java.lang.Iterable<? extends T>
merge(java.lang.Iterable<? extends T> input0, java.lang.Iterable<? extends T> input1)
          Returns an Iterable implementation that 'contains' all elements of both iterables, always choosing the lesser of the two current elements.
static
<T> java.lang.Iterable<T>
merge(java.lang.Iterable<? extends T> i1, java.lang.Iterable<? extends T> i2, BinaryFunctor<T,T,java.lang.Boolean> pred)
          Returns all elements of both iterables, always choosing the lesser of the two current elements by using the given predicate.
static
<T,TCollection extends java.util.Collection<? super T>>
TCollection
merge(java.lang.Iterable<? extends T> cin1, java.lang.Iterable<? extends T> cin2, BinaryFunctor<T,T,java.lang.Boolean> pred, TCollection cout)
          Merges two collections using the given comparator, appending values to the output collection.
static
<T> java.lang.Iterable<T>
merge(java.lang.Iterable<? extends T> i1, java.lang.Iterable<? extends T> i2, java.util.Comparator<T> comp)
          Returns all elements of both iterables, always choosing the lesser of the two current elements.
static
<T,TCollection extends java.util.Collection<? super T>>
TCollection
merge(java.lang.Iterable<? extends T> cin1, java.lang.Iterable<? extends T> cin2, java.util.Comparator<T> comp, TCollection cout)
          Merges two collections using the given comparator, appending values to the output collection.
static
<T extends java.lang.Comparable<? super T>,TCollection extends java.util.Collection<? super T>>
TCollection
merge(java.lang.Iterable<? extends T> cin1, java.lang.Iterable<? extends T> cin2, TCollection cout)
          Merges two collections, appending values to the output collection.
static
<T extends java.lang.Comparable<? super T>>
java.util.Iterator<T>
merge(java.util.Iterator<? extends T> iter1, java.util.Iterator<? extends T> iter2)
          Returns an Iterator that will return elements from both input iterators, choosing the lesser of the two current values.
static
<T> java.util.Iterator<T>
merge(java.util.Iterator<? extends T> iter1, java.util.Iterator<? extends T> iter2, BinaryFunctor<T,T,java.lang.Boolean> pred)
          Returns an Iterator that will return elements from both input iterators, choosing the lesser of the two current values by using the given predicate.
static
<T> java.util.Iterator<T>
merge(java.util.Iterator<? extends T> iter1, java.util.Iterator<? extends T> iter2, java.util.Comparator<T> comp)
          Returns an Iterator that will return elements from both input iterators, choosing the lesser of the two current values using the given comparator.
static
<T extends java.lang.Comparable<? super T>>
java.lang.Iterable<T>
merge(T[] t0, T[] t1)
          Returns all elements of each array, always choosing the least of the current elements.
static
<T> java.lang.Iterable<T>
merge(T[] ts1, T[] ts2, BinaryFunctor<T,T,java.lang.Boolean> pred)
          Returns all elements of both arrays, always choosing the lesser of the two current elements by using the given predicate.
static
<T> java.lang.Iterable<T>
merge(T[] ts1, T[] ts2, java.util.Comparator<T> comp)
          Returns all elements of both arrays, always choosing the lesser of the two current elements using the given comparator.
static
<T,TCollection extends java.util.Collection<? super T>>
TCollection
mergeAppend(TCollection cout, BinaryFunctor<T,T,java.lang.Boolean> pred, java.lang.Iterable<? extends T> cin0, java.lang.Iterable<? extends T> cin1)
          Merges two collections using the given comparator, appending values to the output collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Merge

public Merge()
Method Detail

append

public static <T> java.lang.Iterable<T> append(T[] t0,
                                               T[] t1)
Returns all elements of each array


merge

public static <T extends java.lang.Comparable<? super T>> java.lang.Iterable<T> merge(T[] t0,
                                                                                      T[] t1)
Returns all elements of each array, always choosing the least of the current elements.


merge

public static <T> java.lang.Iterable<T> merge(T[] ts1,
                                              T[] ts2,
                                              java.util.Comparator<T> comp)
Returns all elements of both arrays, always choosing the lesser of the two current elements using the given comparator.


merge

public static <T> java.lang.Iterable<T> merge(T[] ts1,
                                              T[] ts2,
                                              BinaryFunctor<T,T,java.lang.Boolean> pred)
Returns all elements of both arrays, always choosing the lesser of the two current elements by using the given predicate. When the predicate returns TRUE, an element is taken from the first array: when FALSE, an element is taken from the second array.


append

public static <T> java.lang.Iterable<? extends T> append(java.lang.Iterable<? extends T> input0,
                                                         java.lang.Iterable<? extends T> input1)
Returns an Iterable implementation that 'contains' all elements of first iterable followed by all elements of the second iterable


merge

public static <T extends java.lang.Comparable<? super T>> java.lang.Iterable<? extends T> merge(java.lang.Iterable<? extends T> input0,
                                                                                                java.lang.Iterable<? extends T> input1)
Returns an Iterable implementation that 'contains' all elements of both iterables, always choosing the lesser of the two current elements.


merge

public static <T> java.lang.Iterable<T> merge(java.lang.Iterable<? extends T> i1,
                                              java.lang.Iterable<? extends T> i2,
                                              java.util.Comparator<T> comp)
Returns all elements of both iterables, always choosing the lesser of the two current elements.


merge

public static <T> java.lang.Iterable<T> merge(java.lang.Iterable<? extends T> i1,
                                              java.lang.Iterable<? extends T> i2,
                                              BinaryFunctor<T,T,java.lang.Boolean> pred)
Returns all elements of both iterables, always choosing the lesser of the two current elements by using the given predicate. When the predicate returns TRUE, an element is taken from the first array: when FALSE, an element is taken from the second array.


append

public static <T> java.util.Iterator<? extends T> append(java.util.Iterator<? extends T> iter1,
                                                         java.util.Iterator<? extends T> iter2)
Returns an Iterator that will return elements from the first input iterator followed by elements from the second input iterator.


merge

public static <T extends java.lang.Comparable<? super T>> java.util.Iterator<T> merge(java.util.Iterator<? extends T> iter1,
                                                                                      java.util.Iterator<? extends T> iter2)
Returns an Iterator that will return elements from both input iterators, choosing the lesser of the two current values. Neither input iterator is advanced in this method.


merge

public static <T> java.util.Iterator<T> merge(java.util.Iterator<? extends T> iter1,
                                              java.util.Iterator<? extends T> iter2,
                                              java.util.Comparator<T> comp)
Returns an Iterator that will return elements from both input iterators, choosing the lesser of the two current values using the given comparator. Neither input iterator is advanced in this method.


merge

public static <T> java.util.Iterator<T> merge(java.util.Iterator<? extends T> iter1,
                                              java.util.Iterator<? extends T> iter2,
                                              BinaryFunctor<T,T,java.lang.Boolean> pred)
Returns an Iterator that will return elements from both input iterators, choosing the lesser of the two current values by using the given predicate. When the predicate returns TRUE, an element is taken from the first array: when FALSE, an element is taken from the second iterator. Neither input iterator is advanced in this method.


append

public static <T,TCollection extends java.util.Collection<? super T>> TCollection append(java.lang.Iterable<? extends T> cin1,
                                                                                         java.lang.Iterable<? extends T> cin2,
                                                                                         TCollection cout)
Appends the values of the first and second collection to the output collection

Returns:
the output collection

merge

public static <T extends java.lang.Comparable<? super T>,TCollection extends java.util.Collection<? super T>> TCollection merge(java.lang.Iterable<? extends T> cin1,
                                                                                                                                java.lang.Iterable<? extends T> cin2,
                                                                                                                                TCollection cout)
Merges two collections, appending values to the output collection.

Returns:
the output collection

merge

public static <T,TCollection extends java.util.Collection<? super T>> TCollection merge(java.lang.Iterable<? extends T> cin1,
                                                                                        java.lang.Iterable<? extends T> cin2,
                                                                                        java.util.Comparator<T> comp,
                                                                                        TCollection cout)
Merges two collections using the given comparator, appending values to the output collection.

Returns:
the output collection

merge

public static <T,TCollection extends java.util.Collection<? super T>> TCollection merge(java.lang.Iterable<? extends T> cin1,
                                                                                        java.lang.Iterable<? extends T> cin2,
                                                                                        BinaryFunctor<T,T,java.lang.Boolean> pred,
                                                                                        TCollection cout)
Merges two collections using the given comparator, appending values to the output collection.

Returns:
the output collection

mergeAppend

public static <T,TCollection extends java.util.Collection<? super T>> TCollection mergeAppend(TCollection cout,
                                                                                              BinaryFunctor<T,T,java.lang.Boolean> pred,
                                                                                              java.lang.Iterable<? extends T> cin0,
                                                                                              java.lang.Iterable<? extends T> cin1)
Merges two collections using the given comparator, appending values to the output collection.

Returns:
the output collection


Copyright © 2002-2006 David A. Hall. All Rights Reserved.