|
1 | | - |
2 | | -package org.scijava.ops.api; |
3 | | - |
4 | | -import java.util.Arrays; |
5 | | - |
6 | | -/** |
7 | | - * A basic interface for storing and accessing Hints. The general structure for |
8 | | - * a Hint is |
9 | | - * <p> |
10 | | - * {@code hint = hintType.option} |
11 | | - * <p> |
12 | | - * <ul> |
13 | | - * <li>{@code hintType} designates the category of hint |
14 | | - * <li>{@code option} designates the preference within the category |
15 | | - * <li>{@code hint} is the combination of {@code hintType} and {@code option} |
16 | | - * with a delimiting {@code .} |
17 | | - * </ul> |
18 | | - * <p> |
19 | | - * For example, you might want a {@code hintType} to designate preferences on |
20 | | - * lossiness (as a tradeoff for performance). That {@code hintType} might be |
21 | | - * {@code Lossiness}, with {@option}s {@code LOSSLESS} and {@LOSSY}. |
22 | | - * |
23 | | - * @author Gabriel Selzer |
24 | | - */ |
25 | | -public interface Hints { |
26 | | - |
27 | | - Hints plus(String... hints); |
28 | | - |
29 | | - Hints minus(String... hints); |
30 | | - |
31 | | - boolean contains(String hint); |
32 | | - |
33 | | - default boolean containsNone(String... hints) { |
34 | | - return !containsAny(hints); |
35 | | - } |
36 | | - |
37 | | - default boolean containsAny(String... hints) { |
38 | | - return Arrays.stream(hints).anyMatch(hint -> contains(hint)); |
39 | | - } |
40 | | - |
41 | | - default boolean containsAll(String... hints) { |
42 | | - return Arrays.stream(hints).allMatch(hint -> contains(hint)); |
43 | | - } |
44 | | - |
45 | | - /** |
46 | | - * Generates a new {@link Hints} with identical hints. |
47 | | - * |
48 | | - * @return a new {@link Hints} Object with the same hints as this |
49 | | - * {@link Hints} |
50 | | - */ |
51 | | - Hints copy(); |
52 | | - |
53 | | -} |
| 1 | + |
| 2 | +package org.scijava.ops.api; |
| 3 | + |
| 4 | +import java.util.Arrays; |
| 5 | + |
| 6 | +/** |
| 7 | + * A basic interface for storing and accessing Hints. The general structure for |
| 8 | + * a Hint is |
| 9 | + * <p> |
| 10 | + * {@code hint = hintType.option} |
| 11 | + * <p> |
| 12 | + * <ul> |
| 13 | + * <li>{@code hintType} designates the category of hint</li> |
| 14 | + * <li>{@code option} designates the preference within the category</li> |
| 15 | + * <li>{@code hint} is the combination of {@code hintType} and {@code option} |
| 16 | + * with a delimiting {@code .}</li> |
| 17 | + * </ul> |
| 18 | + * <p> |
| 19 | + * For example, you might write a {@code hintType} to designate preferences on a |
| 20 | + * tradeoff between performance and loss. That {@code hintType} might be |
| 21 | + * {@code Lossiness}, with options {@code LOSSLESS} and {@code LOSSY}. |
| 22 | + * |
| 23 | + * @author Gabriel Selzer |
| 24 | + */ |
| 25 | +public interface Hints { |
| 26 | + |
| 27 | + /** |
| 28 | + * Returns a <b>new</b> {@link Hints} with: |
| 29 | + * <ol> |
| 30 | + * <li>All hints in this {@link Hints}</li> |
| 31 | + * <li>All hints in {@code hints}</li> |
| 32 | + * </ol> |
| 33 | + * |
| 34 | + * @param hints the hints to add to this {@link Hints} |
| 35 | + * @return a <b>new</b> {@link Hints} containing the union of the two sets of |
| 36 | + * hints |
| 37 | + */ |
| 38 | + Hints plus(String... hints); |
| 39 | + |
| 40 | + /** |
| 41 | + * Returns a <b>new</b> {@link Hints} with <b>only</b> the hints in this |
| 42 | + * {@link Hints} that are not also in {@code hints} |
| 43 | + * |
| 44 | + * @param hints the hints that should not carry over from this {@link Hints} |
| 45 | + * @return a <b>new</b> {@link Hints} containing the hints in this {@link Hints} |
| 46 | + * but <b>not</b> in {@code hints} |
| 47 | + */ |
| 48 | + Hints minus(String... hints); |
| 49 | + |
| 50 | + /** |
| 51 | + * Determines whether {@code hint} is in this {@link Hints} |
| 52 | + * |
| 53 | + * @param hint a hint |
| 54 | + * @return {@code true} iff {@code hint} is in this {@link Hints} |
| 55 | + */ |
| 56 | + boolean contains(String hint); |
| 57 | + |
| 58 | + /** |
| 59 | + * Determines whether any hints in {@code hints} are also in this {@link Hints} |
| 60 | + * |
| 61 | + * @param hints an array of hints |
| 62 | + * @return true iff <b>each</b> hint in {@code hints} is <b>not</b> in this |
| 63 | + * {@link Hints} |
| 64 | + */ |
| 65 | + default boolean containsNone(String... hints) { |
| 66 | + return !containsAny(hints); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Determines whether any hints in {@code hints} are in this {@link Hints} |
| 71 | + * |
| 72 | + * @param hints an array of hints |
| 73 | + * @return true iff <b>any</b> hint in {@code hints} is in this {@link Hints} |
| 74 | + */ |
| 75 | + default boolean containsAny(String... hints) { |
| 76 | + return Arrays.stream(hints).anyMatch(hint -> contains(hint)); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Determines whether any hints in {@code hints} are in this {@link Hints} |
| 81 | + * |
| 82 | + * @param hints an array of hints |
| 83 | + * @return true iff <b>each</b> hint in {@code hints} is in this {@link Hints} |
| 84 | + */ |
| 85 | + default boolean containsAll(String... hints) { |
| 86 | + return Arrays.stream(hints).allMatch(hint -> contains(hint)); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Generates a <b>new</b> {@link Hints} with identical hints. |
| 91 | + * |
| 92 | + * @return a <b>new</b> {@link Hints} Object with the same hints as this |
| 93 | + * {@link Hints} |
| 94 | + */ |
| 95 | + Hints copy(); |
| 96 | + |
| 97 | +} |
0 commit comments