|
7 | 7 | * expose an optional parameter "{@code int a}" with the same meaning and default values. |
8 | 8 | * <p> |
9 | 9 | * To maintain convenience and type-safety, both {@code FactoryAOptions} and {@code FactoryBOptions} should expose |
10 | | - * a method {@code a(int)} to set the optional parameter. But {@code FactoryAOptions::a} should return an {@code FactoryAOptions}, |
11 | | - * and {@code FactoryBOptions::a} should return an {@code FactoryBOptions} to allow chaining more parameters of |
| 10 | + * a method {@code a(int)} to set the optional parameter. But {@code FactoryAOptions::a} should return a {@code FactoryAOptions}, |
| 11 | + * and {@code FactoryBOptions::a} should return a {@code FactoryBOptions} to allow chaining more parameters of |
12 | 12 | * {@code FactoryAOptions} and {@code FactoryBOptions} respectively, while retaining the type of the builder. |
13 | 13 | * <p> |
14 | 14 | * Using this package, this can be achieved as follows: |
15 | 15 | * <p> |
16 | 16 | * Each subset of optional parameters ("{@code int a}" in the above example) is implemented as two interfaces, |
17 | | - * one exposing methods to set the parameters, one exposing methods to retrieve parameter values. |
| 17 | + * one exposing methods to set the parameters, the other exposing methods to retrieve parameter values. |
18 | 18 | * <p> |
19 | 19 | * For setting: |
20 | 20 | * <pre>{@code |
21 | | - * interface OptionA< T extends OptionA< T > > extends Options< T > { |
| 21 | + * interface OptionA<T> extends Options<T> { |
22 | 22 | * default T a( int a ) { |
23 | | - * return add( "a", a ); |
| 23 | + * return setValue( "a", a ); |
24 | 24 | * } |
25 | 25 | * }}</pre> where the {@code a()} method records the parameter value (with key {@code "a"}) via the |
26 | | - * {@code add()} method of the {@code Options} super-interface. |
| 26 | + * {@code setValue()} method of the {@code Options} super-interface. |
27 | 27 | * <p> |
28 | 28 | * For getting: |
29 | 29 | * <pre>{@code |
30 | 30 | * interface ValueA extends Values { |
31 | 31 | * ... |
32 | 32 | * default int a() {} |
33 | | - * return value( "a", 0 ); |
| 33 | + * return getValueOrDefault( "a", 0 ); |
34 | 34 | * } |
35 | 35 | * }}</pre> where the {@code a()} method returns the parameter value (with key {@code "a"} and default value {@code 0}) |
36 | | - * via the {@code value()} method of the {@code Values} super-interface. |
| 36 | + * via the {@code getValueOrDefault()} method of the {@code Values} super-interface. |
37 | 37 | * <p> |
38 | 38 | * Finally, the implementation of {@code FactoryAOptions} derives from {@code AbstractOptions} and all desired |
39 | 39 | * subsets of options |
40 | 40 | * <pre>{@code public class FactoryAOptions |
41 | | - * extends AbstractOptions< FactoryAOptions > |
42 | | - * implements OptionA< FactoryAOptions >, ... |
| 41 | + * extends AbstractOptions<FactoryAOptions> |
| 42 | + * implements OptionA<FactoryAOptions>, ... |
43 | 43 | * { |
44 | | - * static class FactoryAValues |
| 44 | + * public class FactoryAValues |
45 | 45 | * extends AbstractValues |
46 | 46 | * implements ValueA, ... |
47 | | - * { |
48 | | - * ... |
49 | | - * public FactoryAValues( final FactoryAOptions options ) { |
50 | | - * super( options ); |
51 | | - * } |
52 | | - * } |
| 47 | + * {} |
53 | 48 | * |
54 | | - * public final FactoryAValues values = new FactoryAValues( this ); |
| 49 | + * public final FactoryAValues values = new FactoryAValues(); |
55 | 50 | * |
56 | 51 | * // ======================================================================= |
57 | 52 | * |
|
60 | 55 | * |
61 | 56 | * public FactoryAOptions() {} |
62 | 57 | * |
63 | | - * private FactoryAOptions(FactoryAOptions that) { |
64 | | - * super(that); |
| 58 | + * private FactoryAOptions( FactoryAOptions that ) { |
| 59 | + * super( that ); |
65 | 60 | * } |
66 | 61 | * |
67 | 62 | * \@Override |
68 | 63 | * protected FactoryAOptions copyOrThis() { |
69 | | - * return new FactoryAOptions(this); |
70 | | - * } |
71 | | - * |
72 | | - * // ======================================================================= |
73 | | - * |
74 | | - * // The following is not necessary, but can be overridden like this |
75 | | - * // to make it show up more nicely in IDE auto-complete |
76 | | - * |
77 | | - * \@Override |
78 | | - * public FactoryAOptions a(int a) { |
79 | | - * return OptionA.super.a(a); |
| 64 | + * return new FactoryAOptions( this ); |
80 | 65 | * } |
81 | 66 | * }}</pre> The parameter values are exposed through inner class {@code FactoryAValues} that derives from {@code AbstractValues} |
82 | 67 | * and all desired subsets of option values. |
83 | 68 | * <p> |
84 | 69 | * The only thing that has been omitted from the above example is the parts that provide a nice {@code toString} implementation |
85 | | - * for the values. This is be achieved by |
| 70 | + * for the values. This is be achieved by overriding the {@code forEach()} methods in the {@code Values} interfaces and |
| 71 | + * implementation |
86 | 72 | * <pre>{@code |
87 | 73 | * interface ValueA extends Values { |
88 | | - * default void buildToString( AbstractValues.ValuesToString sb ) { |
89 | | - * sb.append( "a", a() ); |
| 74 | + * default void forEach( BiConsumer<String, Object> action ) { |
| 75 | + * action.accept( "a", a() ); |
| 76 | + * // and so on, for other parameters defined in this Values interface |
90 | 77 | * } |
91 | 78 | * |
92 | 79 | * default int a() { |
93 | | - * return value( "a", 0 ); |
| 80 | + * return getValueOrDefault( "a", 0 ); |
94 | 81 | * } |
95 | 82 | * }}</pre> and <pre>{@code |
96 | | - * static class FactoryAValues |
| 83 | + * public class FactoryAValues |
97 | 84 | * extends AbstractValues |
98 | 85 | * implements ValueA, ... |
99 | 86 | * { |
100 | 87 | * \@Override |
101 | | - * public String toString() { |
102 | | - * final ValuesToString sb = new ValuesToString(); |
103 | | - * ValueA.super.buildToString( sb ); |
104 | | - * return sb.toString(); |
105 | | - * } |
106 | | - * |
107 | | - * public FactoryAValues( final FactoryAOptions options ) { |
108 | | - * super( options ); |
| 88 | + * public void forEach( BiConsumer<String, Object> action ) |
| 89 | + * ValueA.super.forEach( action ); |
| 90 | + * // and so on, for other implemented Values interfaces |
109 | 91 | * } |
110 | 92 | * }}</pre> |
111 | 93 | */ |
|
0 commit comments