|
29 | 29 |
|
30 | 30 | package org.scijava.ops.engine.matcher.convert; |
31 | 31 |
|
| 32 | +import java.util.Collection; |
32 | 33 | import java.util.function.Function; |
33 | 34 |
|
34 | 35 | import org.scijava.collections.ObjectArray; |
@@ -128,95 +129,89 @@ public class PrimitiveArrayConverters<N extends Number> implements |
128 | 129 |
|
129 | 130 | @OpHints(hints = { Conversion.FORBIDDEN }) |
130 | 131 | @OpField(names = "engine.convert") |
131 | | - public final Function<ObjectArray<Number>, Byte[]> toByte = o -> o.stream() |
| 132 | + public final Function<Collection<Number>, Byte[]> toByte = o -> o.stream() |
132 | 133 | .map(b -> b == null ? null : b.byteValue()).toArray(Byte[]::new); |
133 | 134 |
|
134 | 135 | @OpHints(hints = { Conversion.FORBIDDEN }) |
135 | 136 | @OpField(names = "engine.convert") |
136 | | - public final Function<ObjectArray<Number>, Integer[]> toInteger = o -> o |
| 137 | + public final Function<Collection<Number>, Integer[]> toInteger = o -> o |
137 | 138 | .stream().map(i -> i == null ? null : i.intValue()).toArray(Integer[]::new); |
138 | 139 |
|
139 | 140 | @OpHints(hints = { Conversion.FORBIDDEN }) |
140 | 141 | @OpField(names = "engine.convert") |
141 | | - public final Function<ObjectArray<Number>, Short[]> toShort = o -> o.stream() |
| 142 | + public final Function<Collection<Number>, Short[]> toShort = o -> o.stream() |
142 | 143 | .map(s -> s == null ? null : s.shortValue()).toArray(Short[]::new); |
143 | 144 |
|
144 | 145 | @OpHints(hints = { Conversion.FORBIDDEN }) |
145 | 146 | @OpField(names = "engine.convert") |
146 | | - public final Function<ObjectArray<Number>, Long[]> toLong = o -> o.stream() |
| 147 | + public final Function<Collection<Number>, Long[]> toLong = o -> o.stream() |
147 | 148 | .map(l -> l == null ? null : l.longValue()).toArray(Long[]::new); |
148 | 149 |
|
149 | 150 | @OpHints(hints = { Conversion.FORBIDDEN }) |
150 | 151 | @OpField(names = "engine.convert") |
151 | | - public final Function<ObjectArray<Number>, Float[]> toFloat = o -> o.stream() |
| 152 | + public final Function<Collection<Number>, Float[]> toFloat = o -> o.stream() |
152 | 153 | .map(f -> f == null ? null : f.floatValue()).toArray(Float[]::new); |
153 | 154 |
|
154 | 155 | @OpHints(hints = { Conversion.FORBIDDEN }) |
155 | 156 | @OpField(names = "engine.convert") |
156 | | - public final Function<ObjectArray<Number>, Double[]> toDouble = o -> o |
| 157 | + public final Function<Collection<Number>, Double[]> toDouble = o -> o |
157 | 158 | .stream().map(d -> d == null ? null : d.doubleValue()).toArray( |
158 | 159 | Double[]::new); |
159 | 160 |
|
160 | 161 | // -- Primitive Converters -- // |
161 | 162 |
|
162 | 163 | @OpHints(hints = { Conversion.FORBIDDEN }) |
163 | 164 | @OpField(names = "engine.convert") |
164 | | - public final Function<ObjectArray<Number>, byte[]> toPrimitiveByte = o -> { |
| 165 | + public final Function<Collection<Number>, byte[]> toPrimitiveByte = o -> { |
165 | 166 | var arr = new byte[o.size()]; |
166 | | - for (var i = 0; i < o.size(); i++) { |
167 | | - arr[i] = o.get(i).byteValue(); |
168 | | - } |
| 167 | + int i = 0; |
| 168 | + for (var num : o) arr[i++] = num.byteValue(); |
169 | 169 | return arr; |
170 | 170 | }; |
171 | 171 |
|
172 | 172 | @OpHints(hints = { Conversion.FORBIDDEN }) |
173 | 173 | @OpField(names = "engine.convert") |
174 | | - public final Function<ObjectArray<Number>, short[]> toPrimitiveShort = o -> { |
| 174 | + public final Function<Collection<Number>, short[]> toPrimitiveShort = o -> { |
175 | 175 | var arr = new short[o.size()]; |
176 | | - for (var i = 0; i < o.size(); i++) { |
177 | | - arr[i] = o.get(i).shortValue(); |
178 | | - } |
| 176 | + int i = 0; |
| 177 | + for (var num : o) arr[i++] = num.shortValue(); |
179 | 178 | return arr; |
180 | 179 | }; |
181 | 180 |
|
182 | 181 | @OpHints(hints = { Conversion.FORBIDDEN }) |
183 | 182 | @OpField(names = "engine.convert") |
184 | | - public final Function<ObjectArray<Number>, int[]> toPrimitiveInt = o -> { |
| 183 | + public final Function<Collection<Number>, int[]> toPrimitiveInt = o -> { |
185 | 184 | var arr = new int[o.size()]; |
186 | | - for (var i = 0; i < o.size(); i++) { |
187 | | - arr[i] = o.get(i).intValue(); |
188 | | - } |
| 185 | + int i = 0; |
| 186 | + for (var num : o) arr[i++] = num.intValue(); |
189 | 187 | return arr; |
190 | 188 | }; |
191 | 189 |
|
192 | 190 | @OpHints(hints = { Conversion.FORBIDDEN }) |
193 | 191 | @OpField(names = "engine.convert") |
194 | | - public final Function<ObjectArray<Number>, long[]> toPrimitiveLong = o -> { |
| 192 | + public final Function<Collection<Number>, long[]> toPrimitiveLong = o -> { |
195 | 193 | var arr = new long[o.size()]; |
196 | | - for (var i = 0; i < o.size(); i++) { |
197 | | - arr[i] = o.get(i).longValue(); |
198 | | - } |
| 194 | + int i = 0; |
| 195 | + for (var num : o) arr[i++] = num.longValue(); |
199 | 196 | return arr; |
200 | 197 | }; |
201 | 198 |
|
202 | 199 | @OpHints(hints = { Conversion.FORBIDDEN }) |
203 | 200 | @OpField(names = "engine.convert") |
204 | | - public final Function<ObjectArray<Number>, float[]> toPrimitiveFloat = o -> { |
| 201 | + public final Function<Collection<Number>, float[]> toPrimitiveFloat = o -> { |
205 | 202 | var arr = new float[o.size()]; |
206 | | - for (var i = 0; i < o.size(); i++) { |
207 | | - arr[i] = o.get(i).floatValue(); |
208 | | - } |
| 203 | + int i = 0; |
| 204 | + for (var num : o) arr[i++] = num.floatValue(); |
209 | 205 | return arr; |
210 | 206 | }; |
211 | 207 |
|
212 | 208 | @OpHints(hints = { Conversion.FORBIDDEN }) |
213 | 209 | @OpField(names = "engine.convert") |
214 | | - public final Function<ObjectArray<Number>, double[]> toPrimitiveDouble = |
| 210 | + public final Function<Collection<Number>, double[]> toPrimitiveDouble = |
215 | 211 | o -> { |
216 | 212 | var arr = new double[o.size()]; |
217 | | - for (var i = 0; i < o.size(); i++) { |
218 | | - arr[i] = o.get(i).doubleValue(); |
219 | | - } |
| 213 | + int i = 0; |
| 214 | + for (var num : o) arr[i++] = num.doubleValue(); |
220 | 215 | return arr; |
221 | 216 | }; |
222 | 217 |
|
|
0 commit comments