jsr166y.forkjoin
Class ParallelArray.WithBounds<T>

java.lang.Object
  extended by jsr166y.forkjoin.ParallelArray.WithMapping<T,T>
      extended by jsr166y.forkjoin.ParallelArray.WithFilter<T>
          extended by jsr166y.forkjoin.ParallelArray.WithBounds<T>
Enclosing class:
ParallelArray<T>

public static final class ParallelArray.WithBounds<T>
extends ParallelArray.WithFilter<T>

A restriction of parallel array operations to apply only within a given range of indices.


Method Summary
 ParallelArray<T> all()
          Returns a new ParallelArray holding elements
 ParallelArray<T> all(java.lang.Class<? super T> elementType)
          Returns a new ParallelArray with the given element type holding elements
 ParallelArray<T> allNonidenticalElements()
          Returns a new ParallelArray containing only non-null unique elements (that is, without any duplicates).
 ParallelArray<T> allUniqueElements()
          Returns a new ParallelArray containing only non-null unique elements (that is, without any duplicates).
 T any()
          Returns some element matching bound and filter constraints, or null if none.
 int anyIndex()
          Returns the index of some element matching bound and filter constraints, or -1 if none.
 int binarySearch(T target)
          Assuming this array is sorted, returns the index of an element equal to given target, or -1 if not present.
 int binarySearch(T target, java.util.Comparator<? super T> comparator)
          Assuming this array is sorted with respect to the given comparator, returns the index of an element equal to given target, or -1 if not present.
<U,V> ParallelArray<V>
combine(ParallelArray.WithBounds<? extends U> other, Ops.Combiner<? super T,? super U,? extends V> combiner)
          Returns a ParallelArray containing results of applying combine(thisElement, otherElement) for each element.
<U,V> ParallelArray<V>
combine(ParallelArray.WithBounds<? extends U> other, Ops.Combiner<? super T,? super U,? extends V> combiner, java.lang.Class<? super V> elementType)
          Returns a ParallelArray containing results of applying combine(thisElement, otherElement) for each element.
<U,V> ParallelArray<V>
combine(ParallelArray<? extends U> other, Ops.Combiner<? super T,? super U,? extends V> combiner)
          Returns a ParallelArray containing results of applying combine(thisElement, otherElement) for each element.
<U,V> ParallelArray<V>
combine(ParallelArray<? extends U> other, Ops.Combiner<? super T,? super U,? extends V> combiner, java.lang.Class<? super V> elementType)
          Returns a ParallelArray containing results of applying combine(thisElement, otherElement) for each element.
<U,V> ParallelArray<V>
combine(U[] other, Ops.Combiner<? super T,? super U,? extends V> combiner)
          Returns a ParallelArray containing results of applying combine(thisElement, otherElement) for each element.
<U,V> ParallelArray<V>
combine(U[] other, Ops.Combiner<? super T,? super U,? extends V> combiner, java.lang.Class<? super V> elementType)
          Returns a ParallelArray containing results of applying combine(thisElement, otherElement) for each element.
 void cumulate(Ops.Reducer<T> reducer, T base)
          Replaces each element with the running cumulation of applying the given reducer.
 int indexOf(T target)
          Returns the index of some element equal to given target, or -1 if not present
 ParallelArray.WithFilter<T> orFilter(Ops.Predicate<? super T> selector)
          Returns an operation prefix that causes a method to operate only on elements for which the current selector (if present) or the given selector returns true
 T precumulate(Ops.Reducer<T> reducer, T base)
          Replaces each element with the cumulation of applying the given reducer to all previous values, and returns the total reduction.
 void removeAll()
          Removes from the array all elements matching bound and/or filter constraints.
 void removeConsecutiveDuplicates()
          Removes consecutive elements that are equal (or null), shifting others leftward, and possibly decreasing size.
 void removeNulls()
          Removes null elements, shifting others leftward, and possibly decreasing size.
 int size()
          Return the number of elements selected using bound or filter restrictions.
 void sort()
          Sorts the elements, assuming all elements are Comparable.
 void sort(java.util.Comparator<? super T> cmp)
          Sorts the elements.
 ParallelArray.WithBounds<T> withBounds(int firstIndex, int upperBound)
          Returns an operation prefix that causes a method to operate only on the elements of the array between firstIndex (inclusive) and upperBound (exclusive).
 ParallelArray.WithFilter<T> withFilter(Ops.Predicate<? super T> selector)
          Returns an operation prefix that causes a method to operate only on elements for which the current selector (if present) and the given selector returns true
<U> ParallelArray.WithMapping<T,U>
withMapping(Ops.Mapper<? super T,? extends U> mapper)
          Returns an operation prefix that causes a method to operate on mapped elements of the array using the given mapper applied to current mapper's results
 ParallelArray.WithDoubleMapping<T> withMapping(Ops.MapperToDouble<? super T> mapper)
          Returns an operation prefix that causes a method to operate on mapped elements of the array using the given mapper applied to current mapper's results
 ParallelArray.WithLongMapping<T> withMapping(Ops.MapperToLong<? super T> mapper)
          Returns an operation prefix that causes a method to operate on mapped elements of the array using the given mapper applied to current mapper's results
 
Methods inherited from class jsr166y.forkjoin.ParallelArray.WithFilter
apply, max, max, min, min, reduce, replaceWithCombination, replaceWithCombination, replaceWithCombination, replaceWithGeneratedValue, replaceWithMappedIndex, replaceWithTransform, replaceWithValue, summary, summary
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

withBounds

public ParallelArray.WithBounds<T> withBounds(int firstIndex,
                                              int upperBound)
Returns an operation prefix that causes a method to operate only on the elements of the array between firstIndex (inclusive) and upperBound (exclusive). The bound arguments are relative to the current bounds. For example pa.withBounds(2, 8).withBounds(3, 5) indexes the 5th (= 2+3) and 6th elements of pa. However, indices returned by methods such as indexOf are with respect to the underlying ParallelArray.

Parameters:
firstIndex - the lower bound (inclusive)
upperBound - the upper bound (exclusive)
Returns:
operation prefix

withFilter

public ParallelArray.WithFilter<T> withFilter(Ops.Predicate<? super T> selector)
Description copied from class: ParallelArray.WithFilter
Returns an operation prefix that causes a method to operate only on elements for which the current selector (if present) and the given selector returns true

Specified by:
withFilter in class ParallelArray.WithFilter<T>
Parameters:
selector - the selector
Returns:
operation prefix

withMapping

public <U> ParallelArray.WithMapping<T,U> withMapping(Ops.Mapper<? super T,? extends U> mapper)
Description copied from class: ParallelArray.WithMapping
Returns an operation prefix that causes a method to operate on mapped elements of the array using the given mapper applied to current mapper's results

Specified by:
withMapping in class ParallelArray.WithMapping<T,T>
Parameters:
mapper - the mapper
Returns:
operation prefix

withMapping

public ParallelArray.WithDoubleMapping<T> withMapping(Ops.MapperToDouble<? super T> mapper)
Description copied from class: ParallelArray.WithMapping
Returns an operation prefix that causes a method to operate on mapped elements of the array using the given mapper applied to current mapper's results

Specified by:
withMapping in class ParallelArray.WithMapping<T,T>
Parameters:
mapper - the mapper
Returns:
operation prefix

withMapping

public ParallelArray.WithLongMapping<T> withMapping(Ops.MapperToLong<? super T> mapper)
Description copied from class: ParallelArray.WithMapping
Returns an operation prefix that causes a method to operate on mapped elements of the array using the given mapper applied to current mapper's results

Specified by:
withMapping in class ParallelArray.WithMapping<T,T>
Parameters:
mapper - the mapper
Returns:
operation prefix

orFilter

public ParallelArray.WithFilter<T> orFilter(Ops.Predicate<? super T> selector)
Description copied from class: ParallelArray.WithFilter
Returns an operation prefix that causes a method to operate only on elements for which the current selector (if present) or the given selector returns true

Specified by:
orFilter in class ParallelArray.WithFilter<T>
Parameters:
selector - the selector
Returns:
operation prefix

anyIndex

public int anyIndex()
Description copied from class: ParallelArray.WithMapping
Returns the index of some element matching bound and filter constraints, or -1 if none.

Specified by:
anyIndex in class ParallelArray.WithMapping<T,T>
Returns:
index of matching element, or -1 if none.

any

public T any()
Description copied from class: ParallelArray.WithMapping
Returns some element matching bound and filter constraints, or null if none.

Specified by:
any in class ParallelArray.WithMapping<T,T>
Returns:
an element, or null if none.

combine

public <U,V> ParallelArray<V> combine(U[] other,
                                      Ops.Combiner<? super T,? super U,? extends V> combiner)
Returns a ParallelArray containing results of applying combine(thisElement, otherElement) for each element.

Parameters:
other - the other array
combiner - the combiner
Returns:
the array of mappings
Throws:
java.lang.ArrayIndexOutOfBoundsException - if other array is shorter than this array.

combine

public <U,V> ParallelArray<V> combine(U[] other,
                                      Ops.Combiner<? super T,? super U,? extends V> combiner,
                                      java.lang.Class<? super V> elementType)
Returns a ParallelArray containing results of applying combine(thisElement, otherElement) for each element.

Parameters:
other - the other array
combiner - the combiner
elementType - the type of elements of returned array
Returns:
the array of mappings
Throws:
java.lang.ArrayIndexOutOfBoundsException - if other array is shorter than this array.

combine

public <U,V> ParallelArray<V> combine(ParallelArray<? extends U> other,
                                      Ops.Combiner<? super T,? super U,? extends V> combiner)
Returns a ParallelArray containing results of applying combine(thisElement, otherElement) for each element.

Parameters:
other - the other array
combiner - the combiner
Returns:
the array of mappings
Throws:
java.lang.ArrayIndexOutOfBoundsException - if other array is shorter than this array.

combine

public <U,V> ParallelArray<V> combine(ParallelArray<? extends U> other,
                                      Ops.Combiner<? super T,? super U,? extends V> combiner,
                                      java.lang.Class<? super V> elementType)
Returns a ParallelArray containing results of applying combine(thisElement, otherElement) for each element.

Parameters:
other - the other array
combiner - the combiner
elementType - the type of elements of returned array
Returns:
the array of mappings
Throws:
java.lang.ArrayIndexOutOfBoundsException - if other array is shorter than this array.

combine

public <U,V> ParallelArray<V> combine(ParallelArray.WithBounds<? extends U> other,
                                      Ops.Combiner<? super T,? super U,? extends V> combiner)
Returns a ParallelArray containing results of applying combine(thisElement, otherElement) for each element.

Parameters:
other - the other array segment
combiner - the combiner
Returns:
the array of mappings
Throws:
java.lang.ArrayIndexOutOfBoundsException - if other segment is shorter than this array.

combine

public <U,V> ParallelArray<V> combine(ParallelArray.WithBounds<? extends U> other,
                                      Ops.Combiner<? super T,? super U,? extends V> combiner,
                                      java.lang.Class<? super V> elementType)
Returns a ParallelArray containing results of applying combine(thisElement, otherElement) for each element.

Parameters:
other - the other array segment
combiner - the combiner
elementType - the type of elements of returned array
Returns:
the array of mappings
Throws:
java.lang.ArrayIndexOutOfBoundsException - if other array is shorter than this array.

all

public ParallelArray<T> all()
Description copied from class: ParallelArray.WithMapping
Returns a new ParallelArray holding elements

Specified by:
all in class ParallelArray.WithMapping<T,T>
Returns:
a new ParallelArray holding elements

all

public ParallelArray<T> all(java.lang.Class<? super T> elementType)
Description copied from class: ParallelArray.WithMapping
Returns a new ParallelArray with the given element type holding elements

Specified by:
all in class ParallelArray.WithMapping<T,T>
Parameters:
elementType - the type of the elements
Returns:
a new ParallelArray holding elements

allUniqueElements

public ParallelArray<T> allUniqueElements()
Description copied from class: ParallelArray.WithFilter
Returns a new ParallelArray containing only non-null unique elements (that is, without any duplicates). This method uses each element's equals method to test for duplication.

Specified by:
allUniqueElements in class ParallelArray.WithFilter<T>
Returns:
the new ParallelArray

allNonidenticalElements

public ParallelArray<T> allNonidenticalElements()
Description copied from class: ParallelArray.WithFilter
Returns a new ParallelArray containing only non-null unique elements (that is, without any duplicates). This method uses reference identity to test for duplication.

Specified by:
allNonidenticalElements in class ParallelArray.WithFilter<T>
Returns:
the new ParallelArray

indexOf

public int indexOf(T target)
Returns the index of some element equal to given target, or -1 if not present

Parameters:
target - the element to search for
Returns:
the index or -1 if not present

binarySearch

public int binarySearch(T target)
Assuming this array is sorted, returns the index of an element equal to given target, or -1 if not present. If the array is not sorted, the results are undefined.

Parameters:
target - the element to search for
Returns:
the index or -1 if not present

binarySearch

public int binarySearch(T target,
                        java.util.Comparator<? super T> comparator)
Assuming this array is sorted with respect to the given comparator, returns the index of an element equal to given target, or -1 if not present. If the array is not sorted, the results are undefined.

Parameters:
target - the element to search for
comparator - the comparator
Returns:
the index or -1 if not present

size

public int size()
Description copied from class: ParallelArray.WithMapping
Return the number of elements selected using bound or filter restrictions. Note that this method must evaluate all selectors to return its result.

Specified by:
size in class ParallelArray.WithMapping<T,T>
Returns:
the number of elements

cumulate

public void cumulate(Ops.Reducer<T> reducer,
                     T base)
Replaces each element with the running cumulation of applying the given reducer.

Parameters:
reducer - the reducer
base - the result for an empty array

precumulate

public T precumulate(Ops.Reducer<T> reducer,
                     T base)
Replaces each element with the cumulation of applying the given reducer to all previous values, and returns the total reduction.

Parameters:
reducer - the reducer
base - the result for an empty array
Returns:
the total reduction

sort

public void sort(java.util.Comparator<? super T> cmp)
Sorts the elements. Unlike Arrays.sort, this sort does not guarantee that elements with equal keys maintain their relative position in the array.

Parameters:
cmp - the comparator to use

sort

public void sort()
Sorts the elements, assuming all elements are Comparable. Unlike Arrays.sort, this sort does not guarantee that elements with equal keys maintain their relative position in the array.

Throws:
java.lang.ClassCastException - if any element is not Comparable.

removeAll

public void removeAll()
Description copied from class: ParallelArray.WithFilter
Removes from the array all elements matching bound and/or filter constraints.

Specified by:
removeAll in class ParallelArray.WithFilter<T>

removeConsecutiveDuplicates

public void removeConsecutiveDuplicates()
Removes consecutive elements that are equal (or null), shifting others leftward, and possibly decreasing size. This method may be used after sorting to ensure that this ParallelArray contains a set of unique elements.


removeNulls

public void removeNulls()
Removes null elements, shifting others leftward, and possibly decreasing size.