|
8 | 8 |
|
9 | 9 | import static java.util.Arrays.asList; |
10 | 10 | import static java.util.Collections.unmodifiableList; |
11 | | -import static java.util.Collections.unmodifiableSet; |
12 | 11 | import static java.util.Comparator.comparingInt; |
13 | 12 |
|
14 | 13 | /** |
@@ -38,49 +37,41 @@ enum Wave { |
38 | 37 | /** |
39 | 38 | * A <i>SINE</i> wave. |
40 | 39 | */ |
41 | | - SINE(GenerateWaveByteBuffer::sine, "SIN"), |
| 40 | + SINE(GenerateWaveByteBuffer::sine, "SIN", Set.of("SINE","SIN")), |
42 | 41 |
|
43 | 42 | /** |
44 | 43 | * A <i>SQUARE</i> wave. |
45 | 44 | */ |
46 | | - SQUARE(GenerateWaveByteBuffer::square, "SQR"), |
| 45 | + SQUARE(GenerateWaveByteBuffer::square, "SQR", Set.of("SQUARE", "SQR")), |
47 | 46 |
|
48 | 47 | /** |
49 | 48 | * A <i>TRIANGLE</i> wave. |
50 | 49 | */ |
51 | | - TRIANGLE(GenerateWaveByteBuffer::triangle, "TRI"), |
| 50 | + TRIANGLE(GenerateWaveByteBuffer::triangle, "TRI", Set.of("TRIANGLE", "TRI")), |
52 | 51 |
|
53 | 52 | /** |
54 | 53 | * A <i>SAW UP</i> wave. |
55 | 54 | */ |
56 | | - SAW_UP(GenerateWaveByteBuffer::sawUp, "SUP", Set.of("SAWUP")), |
| 55 | + SAW_UP(GenerateWaveByteBuffer::sawUp, "SUP", Set.of("SAW_UP", "SAWUP", "SUP")), |
57 | 56 |
|
58 | 57 | /** |
59 | 58 | * A <i>SAW DOWN</i> wave. |
60 | 59 | */ |
61 | | - SAW_DOWN(GenerateWaveByteBuffer::sawDown, "SDN", Set.of("SAWDOWN")); |
| 60 | + SAW_DOWN(GenerateWaveByteBuffer::sawDown, "SDN", Set.of("SAW_DOWN", "SAWDOWN", "SDN")); |
62 | 61 |
|
63 | | - private final static List<Wave> _waves = unmodifiableList(asList(Wave.values())); |
| 62 | + private final static List<Wave> WAVES = unmodifiableList(asList(Wave.values())); |
64 | 63 |
|
65 | 64 | private final BiFunction<Double, Integer, byte[]> _generatorFunc; |
66 | 65 |
|
67 | 66 | private final String _stringValue; |
68 | 67 |
|
69 | 68 | private final Set<String> _stringValueAliases; |
70 | 69 |
|
71 | | - private Wave(BiFunction<Double, Integer, byte[]> generatorFunc, String stringValue) { |
72 | | - this._generatorFunc = generatorFunc; |
73 | | - this._stringValue = stringValue; |
74 | | - this._stringValueAliases = Set.of(this._stringValue, this.name()); |
75 | | - } |
76 | | - |
77 | 70 | private Wave(BiFunction<Double, Integer, byte[]> generatorFunc, String stringValue, |
78 | 71 | Set<String> stringValueAliases) { |
79 | 72 | this._generatorFunc = generatorFunc; |
80 | 73 | this._stringValue = stringValue; |
81 | | - final Set<String> stringSet = new HashSet<String>(asList(this._stringValue, this.name())); |
82 | | - stringSet.addAll(stringValueAliases); |
83 | | - this._stringValueAliases = unmodifiableSet(stringSet); |
| 74 | + this._stringValueAliases = stringValueAliases; |
84 | 75 | } |
85 | 76 |
|
86 | 77 | /** |
@@ -167,7 +158,7 @@ boolean prefixes(String aString) { |
167 | 158 | * present or an empty optional if not. |
168 | 159 | */ |
169 | 160 | static Optional<String> extractPrefix(String aString, boolean ignoreCase) { |
170 | | - return _waves.stream() |
| 161 | + return WAVES.stream() |
171 | 162 | .flatMap(wave -> wave.stringValueAliases().stream()) |
172 | 163 | .filter(waveStringAlias -> aString.length() >= waveStringAlias.length() |
173 | 164 | && aString.regionMatches(ignoreCase, 0, waveStringAlias, 0, waveStringAlias.length())) |
@@ -217,11 +208,11 @@ static Optional<Wave> parse(String aString, boolean ignoreCase) { |
217 | 208 | } |
218 | 209 |
|
219 | 210 | if (ignoreCase) { |
220 | | - return _waves.stream().filter(wave -> wave._stringValueAliases.stream() |
| 211 | + return WAVES.stream().filter(wave -> wave._stringValueAliases.stream() |
221 | 212 | .anyMatch(waveStringValue -> aString.equalsIgnoreCase(waveStringValue))).findFirst(); |
222 | 213 | } |
223 | 214 |
|
224 | | - return _waves.stream().filter(wave -> wave._stringValueAliases.stream() |
| 215 | + return WAVES.stream().filter(wave -> wave._stringValueAliases.stream() |
225 | 216 | .anyMatch(waveStringValue -> aString.equals(waveStringValue))).findFirst(); |
226 | 217 | } |
227 | 218 |
|
|
0 commit comments