ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/extra166y/ParallelLongArrayWithMapping.java
Revision: 1.7
Committed: Thu Feb 26 06:53:34 2015 UTC (9 years, 2 months ago) by jsr166
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +0 -1 lines
Log Message:
delete unused imports

File Contents

# User Rev Content
1 dl 1.1 /*
2     * Written by Doug Lea with assistance from members of JCP JSR-166
3     * Expert Group and released to the public domain, as explained at
4 jsr166 1.3 * http://creativecommons.org/publicdomain/zero/1.0/
5 dl 1.1 */
6    
7     package extra166y;
8 jsr166 1.6
9 dl 1.1 import jsr166y.*;
10     import static extra166y.Ops.*;
11     import java.util.*;
12     import java.util.concurrent.atomic.*;
13    
14     /**
15     * A prefix view of ParallelLongArray that causes operations to apply
16     * to mappings of elements, not to the elements themselves.
17     * Instances of this class may be constructed only via prefix
18     * methods of ParallelLongArray or its other prefix classes.
19     */
20     public abstract class ParallelLongArrayWithMapping<U> extends AbstractParallelAnyArray.LPap {
21     ParallelLongArrayWithMapping
22     (ForkJoinPool ex, int origin, int fence, long[] array) {
23     super(ex, origin, fence, array);
24     }
25    
26     /**
27 jsr166 1.5 * Applies the given procedure to mapped elements.
28 dl 1.1 * @param procedure the procedure
29     */
30     public void apply(Procedure<? super U> procedure) {
31     ex.invoke(new PAS.FJOApply(this, origin, fence, null, procedure));
32     }
33    
34     /**
35 jsr166 1.5 * Returns reduction of mapped elements.
36 dl 1.1 * @param reducer the reducer
37     * @param base the result for an empty array
38     * @return reduction
39     */
40     public U reduce(Reducer<U> reducer, U base) {
41     PAS.FJOReduce f = new PAS.FJOReduce
42     (this, origin, fence, null, reducer, base);
43     ex.invoke(f);
44     return (U)(f.result);
45     }
46    
47     /**
48     * Returns mapping of some element matching bound and filter
49     * constraints, or null if none.
50 jsr166 1.5 * @return mapping of matching element, or null if none
51 dl 1.1 */
52     public U any() {
53     int i = anyIndex();
54 jsr166 1.2 return (i < 0) ? null : (U)oget(i);
55 dl 1.1 }
56    
57     /**
58 jsr166 1.5 * Returns the minimum mapped element, or null if empty.
59 dl 1.1 * @param comparator the comparator
60     * @return minimum mapped element, or null if empty
61     */
62     public U min(Comparator<? super U> comparator) {
63     return reduce(CommonOps.<U>minReducer(comparator), null);
64     }
65    
66     /**
67     * Returns the minimum mapped element, or null if empty,
68 jsr166 1.5 * assuming that all elements are Comparables.
69 dl 1.1 * @return minimum mapped element, or null if empty
70 jsr166 1.5 * @throws ClassCastException if any element is not Comparable
71 dl 1.1 */
72     public U min() {
73     return reduce((Reducer<U>)(CommonOps.castedMinReducer()), null);
74     }
75    
76     /**
77 jsr166 1.5 * Returns the maximum mapped element, or null if empty.
78 dl 1.1 * @param comparator the comparator
79     * @return maximum mapped element, or null if empty
80     */
81     public U max(Comparator<? super U> comparator) {
82     return reduce(CommonOps.<U>maxReducer(comparator), null);
83     }
84    
85     /**
86 jsr166 1.5 * Returns the maximum mapped element, or null if empty,
87     * assuming that all elements are Comparables.
88 dl 1.1 * @return maximum mapped element, or null if empty
89 jsr166 1.5 * @throws ClassCastException if any element is not Comparable
90 dl 1.1 */
91     public U max() {
92     return reduce((Reducer<U>)(CommonOps.castedMaxReducer()), null);
93     }
94    
95     /**
96     * Returns summary statistics, using the given comparator
97     * to locate minimum and maximum elements.
98     * @param comparator the comparator to use for
99     * locating minimum and maximum elements
100 jsr166 1.5 * @return the summary
101 dl 1.1 */
102     public ParallelArray.SummaryStatistics<U> summary
103     (Comparator<? super U> comparator) {
104     PAS.FJOStats f = new PAS.FJOStats
105     (this, origin, fence, null, comparator);
106     ex.invoke(f);
107     return (ParallelArray.SummaryStatistics<U>)f;
108     }
109    
110     /**
111     * Returns summary statistics, assuming that all elements are
112 jsr166 1.5 * Comparables.
113     * @return the summary
114 dl 1.1 */
115     public ParallelArray.SummaryStatistics<U> summary() {
116     return summary((Comparator<? super U>)(CommonOps.castedComparator()));
117     }
118    
119     /**
120 jsr166 1.5 * Returns a new ParallelArray holding mapped elements.
121 dl 1.1 * @return a new ParallelArray holding mapped elements
122     */
123     public ParallelArray<U> all() {
124     return new ParallelArray<U>(ex, (U[])allObjects(null));
125     }
126    
127     /**
128     * Returns a new ParallelArray with the given element type holding
129 jsr166 1.5 * all elements.
130 dl 1.1 * @param elementType the type of the elements
131     * @return a new ParallelArray holding all elements
132     */
133     public ParallelArray<U> all(Class<? super U> elementType) {
134     return new ParallelArray<U>(ex, (U[])allObjects(elementType));
135     }
136    
137     /**
138     * Returns an operation prefix that causes a method to operate
139     * on mapped elements of the array using the given op
140 jsr166 1.5 * applied to current op's results.
141 dl 1.1 * @param op the op
142     * @return operation prefix
143     */
144     public abstract <V> ParallelLongArrayWithMapping<V> withMapping
145     (Op<? super U, ? extends V> op);
146    
147     /**
148     * Returns an operation prefix that causes a method to operate
149     * on mapped elements of the array using the given op
150 jsr166 1.5 * applied to current op's results.
151 dl 1.1 * @param op the op
152     * @return operation prefix
153     */
154     public abstract ParallelLongArrayWithLongMapping withMapping
155     (ObjectToLong<? super U> op);
156    
157     /**
158     * Returns an operation prefix that causes a method to operate
159     * on mapped elements of the array using the given op
160 jsr166 1.5 * applied to current op's results.
161 dl 1.1 * @param op the op
162     * @return operation prefix
163     */
164     public abstract ParallelLongArrayWithDoubleMapping withMapping
165     (ObjectToDouble<? super U> op);
166    
167     /**
168     * Returns an operation prefix that causes a method to operate
169     * on binary mappings of this array and the other array.
170     * @param combiner the combiner
171     * @param other the other array
172     * @return operation prefix
173     * @throws IllegalArgumentException if other array is a
174 jsr166 1.5 * filtered view (all filters must precede all mappings)
175 dl 1.1 */
176     public <V,W,X> ParallelLongArrayWithMapping<W> withMapping
177     (BinaryOp<? super U, ? super V, ? extends W> combiner,
178     ParallelArrayWithMapping<X,V> other) {
179     if (other.hasFilter()) throw new IllegalArgumentException();
180     return withIndexedMapping
181     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
182     }
183    
184     /**
185     * Returns an operation prefix that causes a method to operate
186     * on binary mappings of this array and the other array.
187     * @param combiner the combiner
188     * @param other the other array
189     * @return operation prefix
190     * @throws IllegalArgumentException if other array is a
191 jsr166 1.5 * filtered view (all filters must precede all mappings)
192 dl 1.1 */
193     public <V> ParallelLongArrayWithMapping<V> withMapping
194     (ObjectAndDoubleToObject<? super U, ? extends V> combiner,
195     ParallelDoubleArrayWithDoubleMapping other) {
196     return withIndexedMapping
197     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
198     }
199    
200     /**
201     * Returns an operation prefix that causes a method to operate
202     * on binary mappings of this array and the other array.
203     * @param combiner the combiner
204     * @param other the other array
205     * @return operation prefix
206     * @throws IllegalArgumentException if other array is a
207 jsr166 1.5 * filtered view (all filters must precede all mappings)
208 dl 1.1 */
209     public <V> ParallelLongArrayWithMapping<V> withMapping
210     (ObjectAndLongToObject<? super U, ? extends V> combiner,
211     ParallelLongArrayWithLongMapping other) {
212     if (other.hasFilter()) throw new IllegalArgumentException();
213     return withIndexedMapping
214     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
215     }
216    
217     /**
218     * Returns an operation prefix that causes a method to operate
219     * on binary mappings of this array and the other array.
220     * @param combiner the combiner
221     * @param other the other array
222     * @return operation prefix
223     * @throws IllegalArgumentException if other array is a
224 jsr166 1.5 * filtered view (all filters must precede all mappings)
225 dl 1.1 */
226     public <V,W> ParallelLongArrayWithDoubleMapping withMapping
227     (ObjectAndObjectToDouble<? super U, ? super V> combiner,
228     ParallelArrayWithMapping<W,V> other) {
229     if (other.hasFilter()) throw new IllegalArgumentException();
230     return withIndexedMapping
231     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
232     }
233    
234     /**
235     * Returns an operation prefix that causes a method to operate
236     * on binary mappings of this array and the other array.
237     * @param combiner the combiner
238     * @param other the other array
239     * @return operation prefix
240     * @throws IllegalArgumentException if other array is a
241 jsr166 1.5 * filtered view (all filters must precede all mappings)
242 dl 1.1 */
243     public ParallelLongArrayWithDoubleMapping withMapping
244     (ObjectAndDoubleToDouble<? super U> combiner,
245     ParallelDoubleArrayWithDoubleMapping other) {
246     if (other.hasFilter()) throw new IllegalArgumentException();
247     return withIndexedMapping
248     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
249     }
250    
251     /**
252     * Returns an operation prefix that causes a method to operate
253     * on binary mappings of this array and the other array.
254     * @param combiner the combiner
255     * @param other the other array
256     * @return operation prefix
257     * @throws IllegalArgumentException if other array is a
258 jsr166 1.5 * filtered view (all filters must precede all mappings)
259 dl 1.1 */
260     public ParallelLongArrayWithDoubleMapping withMapping
261     (ObjectAndLongToDouble<? super U> combiner,
262     ParallelLongArrayWithLongMapping other) {
263     if (other.hasFilter()) throw new IllegalArgumentException();
264     return withIndexedMapping
265     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
266     }
267    
268     /**
269     * Returns an operation prefix that causes a method to operate
270     * on binary mappings of this array and the other array.
271     * @param combiner the combiner
272     * @param other the other array
273     * @return operation prefix
274     * @throws IllegalArgumentException if other array is a
275 jsr166 1.5 * filtered view (all filters must precede all mappings)
276 dl 1.1 */
277     public <V,W> ParallelLongArrayWithLongMapping withMapping
278     (ObjectAndObjectToLong<? super U, ? super V> combiner,
279     ParallelArrayWithMapping<W,V> other) {
280     if (other.hasFilter()) throw new IllegalArgumentException();
281     return withIndexedMapping
282     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
283     }
284    
285     /**
286     * Returns an operation prefix that causes a method to operate
287     * on binary mappings of this array and the other array.
288     * @param combiner the combiner
289     * @param other the other array
290     * @return operation prefix
291     * @throws IllegalArgumentException if other array is a
292 jsr166 1.5 * filtered view (all filters must precede all mappings)
293 dl 1.1 */
294     public ParallelLongArrayWithLongMapping withMapping
295     (ObjectAndDoubleToLong<? super U> combiner,
296     ParallelDoubleArrayWithDoubleMapping other) {
297     if (other.hasFilter()) throw new IllegalArgumentException();
298     return withIndexedMapping
299     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
300     }
301    
302     /**
303     * Returns an operation prefix that causes a method to operate
304     * on binary mappings of this array and the other array.
305     * @param combiner the combiner
306     * @param other the other array
307     * @return operation prefix
308     * @throws IllegalArgumentException if other array is a
309 jsr166 1.5 * filtered view (all filters must precede all mappings)
310 dl 1.1 */
311     public ParallelLongArrayWithLongMapping withMapping
312     (ObjectAndLongToLong<? super U> combiner,
313     ParallelLongArrayWithLongMapping other) {
314     if (other.hasFilter()) throw new IllegalArgumentException();
315     return withIndexedMapping
316     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
317     }
318    
319     /**
320     * Returns an operation prefix that causes a method to operate
321     * on mappings of this array using the given mapper that
322     * accepts as arguments an element's current index and value
323     * (as mapped by preceding mappings, if any), and produces a
324     * new value.
325     * @param mapper the mapper
326     * @return operation prefix
327     */
328     public abstract <V> ParallelLongArrayWithMapping<V> withIndexedMapping
329     (IntAndObjectToObject<? super U, ? extends V> mapper);
330    
331     /**
332     * Returns an operation prefix that causes a method to operate
333     * on mappings of this array using the given mapper that
334     * accepts as arguments an element's current index and value
335     * (as mapped by preceding mappings, if any), and produces a
336     * new value.
337     * @param mapper the mapper
338     * @return operation prefix
339     */
340     public abstract ParallelLongArrayWithDoubleMapping withIndexedMapping
341     (IntAndObjectToDouble<? super U> mapper);
342    
343     /**
344     * Returns an operation prefix that causes a method to operate
345     * on mappings of this array using the given mapper that
346     * accepts as arguments an element's current index and value
347     * (as mapped by preceding mappings, if any), and produces a
348     * new value.
349     * @param mapper the mapper
350     * @return operation prefix
351     */
352     public abstract ParallelLongArrayWithLongMapping withIndexedMapping
353     (IntAndObjectToLong<? super U> mapper);
354    
355     /**
356     * Returns an Iterable view to sequentially step through mapped
357     * elements also obeying bound and filter constraints, without
358 jsr166 1.5 * performing computations to evaluate them in parallel.
359 dl 1.1 * @return the Iterable view
360     */
361     public Iterable<U> sequentially() {
362     return new Sequentially<U>();
363     }
364    
365     }