5 |
|
*/ |
6 |
|
|
7 |
|
package extra166y; |
8 |
+ |
|
9 |
|
import java.util.*; |
10 |
|
|
11 |
|
/** |
13 |
|
* within parallel methods on aggregates. This class provides type |
14 |
|
* names for all operation signatures accepting zero, one or two |
15 |
|
* arguments, and returning zero or one results, for parameterized |
16 |
< |
* types, as well as specializations to <tt>int</tt>, <tt>long</tt>, |
17 |
< |
* and <tt>double</tt>. In keeping with normal Java evaluation rules |
18 |
< |
* that promote, for example <tt>short</tt> to <tt>int</tt>, operation |
16 |
> |
* types, as well as specializations to {@code int}, {@code long}, |
17 |
> |
* and {@code double}. In keeping with normal Java evaluation rules |
18 |
> |
* that promote, for example {@code short} to {@code int}, operation |
19 |
|
* names for these smaller types are absent. |
20 |
|
* |
21 |
|
* <p><b>Preliminary release note: Some of the declarations in this |
26 |
|
* <p>The naming conventions are as follows: |
27 |
|
* <ul> |
28 |
|
* |
29 |
< |
* <li> The name of the single method declared in each interface is |
30 |
< |
* simply <tt>op</tt> (short for "operate"). |
29 |
> |
* <li>The name of the single method declared in each interface is |
30 |
> |
* simply {@code op} (short for "operate"). |
31 |
|
* |
32 |
< |
* <li> An <tt>Op</tt> (short for "operation") maps a single argument to |
32 |
> |
* <li>An {@code Op} (short for "operation") maps a single argument to |
33 |
|
* a result. Example: negating a value. |
34 |
|
* |
35 |
< |
* <li> The names for scalar ops accepting and returning the same type |
35 |
> |
* <li>The names for scalar ops accepting and returning the same type |
36 |
|
* are prefaced by their type name. |
37 |
|
* |
38 |
< |
* <li> A <tt>BinaryOp</tt> maps two arguments to a result. Example: |
38 |
> |
* <li>A {@code BinaryOp} maps two arguments to a result. Example: |
39 |
|
* dividing two numbers |
40 |
|
* |
41 |
< |
* <li>A <tt>Reducer</tt> is an <em>associative</em> binary op |
41 |
> |
* <li>A {@code Reducer} is an <em>associative</em> binary op |
42 |
|
* accepting and returning values of the same type; where op(a, op(b, |
43 |
|
* c)) should have the same result as op(op(a, b), c). Example: |
44 |
|
* adding two numbers. |
45 |
|
* |
46 |
< |
* <li> Scalar binary ops accepting and returning the same type |
46 |
> |
* <li>Scalar binary ops accepting and returning the same type |
47 |
|
* include their type name. |
48 |
|
* |
49 |
< |
* <li> Mixed-type operators are named just by their argument type |
49 |
> |
* <li>Mixed-type operators are named just by their argument type |
50 |
|
* names. |
51 |
|
* |
52 |
< |
* <li> A <tt>Generator</tt> takes no arguments and returns a result. |
52 |
> |
* <li>A {@code Generator} takes no arguments and returns a result. |
53 |
|
* Examples: random number generators, builders |
54 |
|
* |
55 |
< |
* <li> A <tt>Procedure</tt> accepts an argument but doesn't return a |
56 |
< |
* result. Example: printing a value. An <tt>Action</tt> is a |
55 |
> |
* <li>A {@code Procedure} accepts an argument but doesn't return a |
56 |
> |
* result. Example: printing a value. An {@code Action} is a |
57 |
|
* Procedure that takes no arguments. |
58 |
|
* |
59 |
< |
* <li>A <tt>Predicate</tt> accepts a value and returns a boolean indicator |
59 |
> |
* <li>A {@code Predicate} accepts a value and returns a boolean indicator |
60 |
|
* that the argument obeys some property. Example: testing if a number is even. |
61 |
|
* |
62 |
< |
* <li>A <tt>BinaryPredicate</tt> accepts two values and returns a |
62 |
> |
* <li>A {@code BinaryPredicate} accepts two values and returns a |
63 |
|
* boolean indicator that the arguments obeys some relation. Example: |
64 |
|
* testing if two numbers are relatively prime. |
65 |
|
* |
89 |
|
* <td > |
90 |
|
* <th >a |
91 |
|
* <th >b |
92 |
< |
* <th ><tt>int</tt> |
93 |
< |
* <th ><tt>long</tt> |
94 |
< |
* <th ><tt>double</tt> |
92 |
> |
* <th >{@code int} |
93 |
> |
* <th >{@code long} |
94 |
> |
* <th >{@code double} |
95 |
|
* <th >Object |
96 |
|
* <td > |
97 |
|
* <tr> |
105 |
|
* <td > |
106 |
|
* <tr> |
107 |
|
* <td > |
108 |
< |
* <td ><tt>int</tt> |
108 |
> |
* <td >{@code int} |
109 |
|
* <td ><em><none></em> |
110 |
|
* <td ><a href="Ops.IntOp.html">Ops.IntOp</a> |
111 |
|
* <td ><a href="Ops.IntToLong.html">Ops.IntToLong</a> |
115 |
|
* <tr> |
116 |
|
* <td > |
117 |
|
* <td > |
118 |
< |
* <td ><tt>int</tt> |
118 |
> |
* <td >{@code int} |
119 |
|
* <td ><a href="Ops.BinaryIntOp.html">Ops.BinaryIntOp</a> |
120 |
|
* <td ><a href="Ops.IntAndIntToLong.html">Ops.IntAndIntToLong</a> |
121 |
|
* <td ><a href="Ops.IntAndIntToDouble.html">Ops.IntAndIntToDouble</a> |
124 |
|
* <tr> |
125 |
|
* <td > |
126 |
|
* <td > |
127 |
< |
* <td ><tt>long</tt> |
127 |
> |
* <td >{@code long} |
128 |
|
* <td ><a href="Ops.IntAndLongToInt.html">Ops.IntAndLongToInt</a> |
129 |
|
* <td ><a href="Ops.IntAndLongToLong.html">Ops.IntAndLongToLong</a> |
130 |
|
* <td ><a href="Ops.IntAndLongToDouble.html">Ops.IntAndLongToDouble</a> |
133 |
|
* <tr> |
134 |
|
* <td > |
135 |
|
* <td > |
136 |
< |
* <td ><tt>double</tt> |
136 |
> |
* <td >{@code double} |
137 |
|
* <td ><a href="Ops.IntAndDoubleToInt.html">Ops.IntAndDoubleToInt</a> |
138 |
|
* <td ><a href="Ops.IntAndDoubleToLong.html">Ops.IntAndDoubleToLong</a> |
139 |
|
* <td ><a href="Ops.IntAndDoubleToDouble.html">Ops.IntAndDoubleToDouble</a> |
159 |
|
* <td > |
160 |
|
* <tr> |
161 |
|
* <td > |
162 |
< |
* <td ><tt>long</tt> |
162 |
> |
* <td >{@code long} |
163 |
|
* <td ><em><none></em> |
164 |
|
* <td ><a href="Ops.LongToInt.html">Ops.LongToInt</a> |
165 |
|
* <td ><a href="Ops.LongOp.html">Ops.LongOp</a> |
169 |
|
* <tr> |
170 |
|
* <td > |
171 |
|
* <td > |
172 |
< |
* <td ><tt>int</tt> |
172 |
> |
* <td >{@code int} |
173 |
|
* <td ><a href="Ops.LongAndIntToInt.html">Ops.LongAndIntToInt</a> |
174 |
|
* <td ><a href="Ops.LongAndIntToLong.html">Ops.LongAndIntToLong</a> |
175 |
|
* <td ><a href="Ops.LongAndIntToDouble.html">Ops.LongAndIntToDouble</a> |
178 |
|
* <tr> |
179 |
|
* <td > |
180 |
|
* <td > |
181 |
< |
* <td ><tt>long</tt> |
181 |
> |
* <td >{@code long} |
182 |
|
* <td ><a href="Ops.LongAndLongToInt.html">Ops.LongAndLongToInt</a> |
183 |
|
* <td ><a href="Ops.BinaryLongOp.html">Ops.BinaryLongOp</a> |
184 |
|
* <td ><a href="Ops.LongAndLongToDouble.html">Ops.LongAndLongToDouble</a> |
187 |
|
* <tr> |
188 |
|
* <td > |
189 |
|
* <td > |
190 |
< |
* <td ><tt>double</tt> |
190 |
> |
* <td >{@code double} |
191 |
|
* <td ><a href="Ops.LongAndDoubleToInt.html">Ops.LongAndDoubleToInt</a> |
192 |
|
* <td ><a href="Ops.LongAndDoubleToLong.html">Ops.LongAndDoubleToLong</a> |
193 |
|
* <td ><a href="Ops.LongAndDoubleToDouble.html">Ops.LongAndDoubleToDouble</a> |
213 |
|
* <td > |
214 |
|
* <tr> |
215 |
|
* <td > |
216 |
< |
* <td ><tt>double</tt> |
216 |
> |
* <td >{@code double} |
217 |
|
* <td ><em><none></em> |
218 |
|
* <td ><a href="Ops.DoubleToInt.html">Ops.DoubleToInt</a> |
219 |
|
* <td ><a href="Ops.DoubleToLong.html">Ops.DoubleToLong</a> |
223 |
|
* <tr> |
224 |
|
* <td > |
225 |
|
* <td > |
226 |
< |
* <td ><tt>int</tt> |
226 |
> |
* <td >{@code int} |
227 |
|
* <td ><a href="Ops.DoubleAndIntToInt.html">Ops.DoubleAndIntToInt</a> |
228 |
|
* <td ><a href="Ops.DoubleAndIntToLong.html">Ops.DoubleAndIntToLong</a> |
229 |
|
* <td ><a href="Ops.DoubleAndIntToDouble.html">Ops.DoubleAndIntToDouble</a> |
232 |
|
* <tr> |
233 |
|
* <td > |
234 |
|
* <td > |
235 |
< |
* <td ><tt>long</tt> |
235 |
> |
* <td >{@code long} |
236 |
|
* <td ><a href="Ops.DoubleAndLongToInt.html">Ops.DoubleAndLongToInt</a> |
237 |
|
* <td ><a href="Ops.DoubleAndLongToLong.html">Ops.DoubleAndLongToLong</a> |
238 |
|
* <td ><a href="Ops.DoubleAndLongToDouble.html">Ops.DoubleAndLongToDouble</a> |
241 |
|
* <tr> |
242 |
|
* <td > |
243 |
|
* <td > |
244 |
< |
* <td ><tt>double</tt> |
244 |
> |
* <td >{@code double} |
245 |
|
* <td ><a href="Ops.DoubleAndDoubleToInt.html">Ops.DoubleAndDoubleToInt</a> |
246 |
|
* <td ><a href="Ops.DoubleAndDoubleToLong.html">Ops.DoubleAndDoubleToLong</a> |
247 |
|
* <td ><a href="Ops.BinaryDoubleOp.html">Ops.BinaryDoubleOp</a> |
276 |
|
* <tr> |
277 |
|
* <td > |
278 |
|
* <td > |
279 |
< |
* <td ><tt>int</tt> |
279 |
> |
* <td >{@code int} |
280 |
|
* <td ><a href="Ops.ObjectAndIntToInt.html">Ops.ObjectAndIntToInt</a> |
281 |
|
* <td ><a href="Ops.ObjectAndIntToLong.html">Ops.ObjectAndIntToLong</a> |
282 |
|
* <td ><a href="Ops.ObjectAndIntToDouble.html">Ops.ObjectAndIntToDouble</a> |
285 |
|
* <tr> |
286 |
|
* <td > |
287 |
|
* <td > |
288 |
< |
* <td ><tt>long</tt> |
288 |
> |
* <td >{@code long} |
289 |
|
* <td ><a href="Ops.ObjectAndLongToInt.html">Ops.ObjectAndLongToInt</a> |
290 |
|
* <td ><a href="Ops.ObjectAndLongToLong.html">Ops.ObjectAndLongToLong</a> |
291 |
|
* <td ><a href="Ops.ObjectAndLongToDouble.html">Ops.ObjectAndLongToDouble</a> |
294 |
|
* <tr> |
295 |
|
* <td > |
296 |
|
* <td > |
297 |
< |
* <td ><tt>double</tt> |
297 |
> |
* <td >{@code double} |
298 |
|
* <td ><a href="Ops.ObjectAndDoubleToInt.html">Ops.ObjectAndDoubleToInt</a> |
299 |
|
* <td ><a href="Ops.ObjectAndDoubleToLong.html">Ops.ObjectAndDoubleToLong</a> |
300 |
|
* <td ><a href="Ops.ObjectAndDoubleToDouble.html">Ops.ObjectAndDoubleToDouble</a> |
326 |
|
* constructions. Additionally, they should not block waiting for |
327 |
|
* synchronization. |
328 |
|
* |
329 |
< |
* <p>This class is normally best used via <tt>import static</tt>. |
329 |
> |
* <p>This class is normally best used via {@code import static}. |
330 |
|
*/ |
331 |
|
public class Ops { |
332 |
|
private Ops() {} // disable construction |
340 |
|
public static interface BinaryPredicate<A,B> { boolean op(A a, B b);} |
341 |
|
public static interface Procedure<A> { void op(A a);} |
342 |
|
public static interface Generator<R> { R op();} |
343 |
< |
public static interface Reducer<A> extends BinaryOp<A, A, A>{} |
343 |
> |
public static interface Reducer<A> extends BinaryOp<A,A,A> {} |
344 |
|
|
345 |
|
public static interface IntOp { int op(int a);} |
346 |
|
public static interface BinaryIntOp { int op(int a, int b);} |
348 |
|
public static interface IntProcedure { void op(int a);} |
349 |
|
public static interface IntGenerator { int op();} |
350 |
|
public static interface BinaryIntPredicate { boolean op(int a, int b);} |
351 |
< |
public static interface IntReducer extends BinaryIntOp{} |
351 |
> |
public static interface IntReducer extends BinaryIntOp {} |
352 |
|
public static interface IntComparator { int compare(int a, int b);} |
353 |
|
|
354 |
|
public static interface LongOp { long op(long a);} |
357 |
|
public static interface BinaryLongPredicate { boolean op(long a, long b);} |
358 |
|
public static interface LongProcedure { void op(long a);} |
359 |
|
public static interface LongGenerator { long op();} |
360 |
< |
public static interface LongReducer extends BinaryLongOp{} |
360 |
> |
public static interface LongReducer extends BinaryLongOp {} |
361 |
|
public static interface LongComparator { int compare(long a, long b);} |
362 |
|
|
363 |
|
public static interface DoubleOp { double op(double a);} |
366 |
|
public static interface BinaryDoublePredicate { boolean op(double a, double b);} |
367 |
|
public static interface DoubleProcedure { void op(double a);} |
368 |
|
public static interface DoubleGenerator { double op();} |
369 |
< |
public static interface DoubleReducer extends BinaryDoubleOp{} |
369 |
> |
public static interface DoubleReducer extends BinaryDoubleOp {} |
370 |
|
public static interface DoubleComparator { int compare(double a, double b);} |
371 |
|
|
372 |
|
public static interface Action { void op();} |