50
50
import org .codehaus .groovy .util .DoubleArrayIterable ;
51
51
import org .codehaus .groovy .util .DoubleArrayIterator ;
52
52
import org .codehaus .groovy .util .DoubleDoubleArrayColumnIterator ;
53
+ import org .codehaus .groovy .util .FloatArrayIterable ;
53
54
import org .codehaus .groovy .util .FloatArrayIterator ;
54
55
import org .codehaus .groovy .util .FloatFloatArrayColumnIterator ;
55
56
import org .codehaus .groovy .util .IntArrayIterable ;
@@ -4468,6 +4469,22 @@ public static Map<Integer, Long> indexed(long[] self) {
4468
4469
return indexed (self , 0 );
4469
4470
}
4470
4471
4472
+ /**
4473
+ * Zips a float[] with indices in (index, value) order starting from index 0.
4474
+ * <p/>
4475
+ * Example usage:
4476
+ * <pre class="groovyTestCase">
4477
+ * float[] nums = [10.0f, 20.0f, 30.0f]
4478
+ * assert [0: 10.0f, 1: 20.0f, 2: 30.0f] == nums.indexed()
4479
+ * </pre>
4480
+ *
4481
+ * @see #indexed(float[], int)
4482
+ * @since 5.0.0
4483
+ */
4484
+ public static Map <Integer , Float > indexed (float [] self ) {
4485
+ return indexed (self , 0 );
4486
+ }
4487
+
4471
4488
/**
4472
4489
* Zips a double[] with indices in (index, value) order starting from index 0.
4473
4490
* <p/>
@@ -4484,10 +4501,8 @@ public static Map<Integer, Double> indexed(double[] self) {
4484
4501
return indexed (self , 0 );
4485
4502
}
4486
4503
4487
- //
4488
-
4489
4504
/**
4490
- * Zips an int[] with indices in (index, value) order.
4505
+ * Zips an int[] with indices in (index, value) order starting from a given index .
4491
4506
* <p/>
4492
4507
* Example usage:
4493
4508
* <pre class="groovyTestCase">
@@ -4507,7 +4522,7 @@ public static Map<Integer, Integer> indexed(int[] self, int offset) {
4507
4522
}
4508
4523
4509
4524
/**
4510
- * Zips a long[] with indices in (index, value) order.
4525
+ * Zips a long[] with indices in (index, value) order starting from a given index .
4511
4526
* <p/>
4512
4527
* Example usage:
4513
4528
* <pre class="groovyTestCase">
@@ -4526,7 +4541,26 @@ public static Map<Integer, Long> indexed(long[] self, int offset) {
4526
4541
}
4527
4542
4528
4543
/**
4529
- * Zips a double[] with indices in (index, value) order.
4544
+ * Zips a float[] with indices in (index, value) order starting from a given index.
4545
+ * <p/>
4546
+ * Example usage:
4547
+ * <pre class="groovyTestCase">
4548
+ * double[] nums = [10.0f, 20.0f, 30.0f]
4549
+ * assert [5: 10.0f, 6: 20.0f, 7: 30.0f] == nums.indexed(5)
4550
+ * </pre>
4551
+ *
4552
+ * @param self a float[]
4553
+ * @param offset an index to start from
4554
+ * @return a Map (since the keys/indices are unique) containing the elements from the iterable zipped with indices
4555
+ * @see DefaultGroovyMethods#indexed(Iterable, int)
4556
+ * @since 5.0.0
4557
+ */
4558
+ public static Map <Integer , Float > indexed (float [] self , int offset ) {
4559
+ return DefaultGroovyMethods .indexed (new FloatArrayIterable (self ), offset );
4560
+ }
4561
+
4562
+ /**
4563
+ * Zips a double[] with indices in (index, value) order starting from a given index.
4530
4564
* <p/>
4531
4565
* Example usage:
4532
4566
* <pre class="groovyTestCase">
@@ -9205,6 +9239,165 @@ public static <K, V> Map<K, V> withCollectedValues(K[] keys, Map<K, V> collector
9205
9239
return DefaultGroovyMethods .collectEntries (new ArrayIterator <>(keys ), collector , Function .identity (), valueTransform );
9206
9240
}
9207
9241
9242
+ //--------------------------------------------------------------------------
9243
+ // withIndex
9244
+
9245
+ /**
9246
+ * Zips an int array with indices in (value, index) order.
9247
+ * <p/>
9248
+ * Example usage:
9249
+ * <pre class="groovyTestCase">
9250
+ * int[] nums = [42, -1]
9251
+ * assert [[42, 0], [-1, 1]] == nums.withIndex()
9252
+ * assert ["0: 42", "1: -1"] == nums.withIndex().collect { n, idx {@code ->} "$idx: $n" }
9253
+ * </pre>
9254
+ *
9255
+ * @param self an int array
9256
+ * @return a zipped list with indices
9257
+ * @see DefaultGroovyMethods#withIndex(Iterable)
9258
+ * @since 5.0.0
9259
+ */
9260
+ public static List <Tuple2 <Integer , Integer >> withIndex (int [] self ) {
9261
+ return withIndex (self , 0 );
9262
+ }
9263
+
9264
+ /**
9265
+ * Zips an int array with indices in (value, index) order starting from a given index.
9266
+ * <p/>
9267
+ * Example usage:
9268
+ * <pre class="groovyTestCase">
9269
+ * int[] nums = [42, -1]
9270
+ * assert [[42, 5], [-1, 6]] == nums.withIndex(5)
9271
+ * assert ["5: 42", "6: -1"] == nums.withIndex(5).collect { n, idx {@code ->} "$idx: $n" }
9272
+ * </pre>
9273
+ *
9274
+ * @param self an int array
9275
+ * @param offset an index to start from
9276
+ * @return a zipped list with indices
9277
+ * @see DefaultGroovyMethods#withIndex(Iterable, int)
9278
+ * @since 5.0.0
9279
+ */
9280
+ public static List <Tuple2 <Integer , Integer >> withIndex (int [] self , int offset ) {
9281
+ return DefaultGroovyMethods .withIndex (new IntArrayIterable (self ), offset );
9282
+ }
9283
+
9284
+ /**
9285
+ * Zips a long array with indices in (value, index) order.
9286
+ * <p/>
9287
+ * Example usage:
9288
+ * <pre class="groovyTestCase">
9289
+ * long[] nums = [42L, -1L]
9290
+ * assert [[42L, 0], [-1L, 1]] == nums.withIndex()
9291
+ * assert ["0: 42", "1: -1"] == nums.withIndex().collect { n, idx {@code ->} "$idx: $n" }
9292
+ * </pre>
9293
+ *
9294
+ * @param self a long array
9295
+ * @return a zipped list with indices
9296
+ * @see DefaultGroovyMethods#withIndex(Iterable)
9297
+ * @since 5.0.0
9298
+ */
9299
+ public static List <Tuple2 <Long , Integer >> withIndex (long [] self ) {
9300
+ return withIndex (self , 0 );
9301
+ }
9302
+
9303
+ /**
9304
+ * Zips a long array with indices in (value, index) order starting from a given index.
9305
+ * <p/>
9306
+ * Example usage:
9307
+ * <pre class="groovyTestCase">
9308
+ * long[] nums = [42L, -1L]
9309
+ * assert [[42L, 5], [-1L, 6]] == nums.withIndex(5)
9310
+ * assert ["5: 42", "6: -1"] == nums.withIndex(5).collect { n, idx {@code ->} "$idx: $n" }
9311
+ * </pre>
9312
+ *
9313
+ * @param self a long array
9314
+ * @param offset an index to start from
9315
+ * @return a zipped list with indices
9316
+ * @see DefaultGroovyMethods#withIndex(Iterable)
9317
+ * @since 5.0.0
9318
+ */
9319
+ public static List <Tuple2 <Long , Integer >> withIndex (long [] self , int offset ) {
9320
+ return DefaultGroovyMethods .withIndex (new LongArrayIterable (self ), offset );
9321
+ }
9322
+
9323
+ /**
9324
+ * Zips a float array with indices in (value, index) order.
9325
+ * <p/>
9326
+ * Example usage:
9327
+ * <pre class="groovyTestCase">
9328
+ * float[] nums = [42.0f, -1.0f]
9329
+ * assert [[42.0f, 0], [-1.0f, 1]] == nums.withIndex()
9330
+ * assert ["0: 42.0", "1: -1.0"] == nums.withIndex().collect { n, idx {@code ->} "$idx: $n" }
9331
+ * </pre>
9332
+ *
9333
+ * @param self a float array
9334
+ * @return a zipped list with indices
9335
+ * @see DefaultGroovyMethods#withIndex(Iterable)
9336
+ * @since 5.0.0
9337
+ */
9338
+ public static List <Tuple2 <Float , Integer >> withIndex (float [] self ) {
9339
+ return withIndex (self , 0 );
9340
+ }
9341
+
9342
+ /**
9343
+ * Zips a float array with indices in (value, index) order starting from a given index.
9344
+ * <p/>
9345
+ * Example usage:
9346
+ * <pre class="groovyTestCase">
9347
+ * float[] nums = [42.0f, -1.0f]
9348
+ * assert [[42.0f, 5], [-1.0f, 6]] == nums.withIndex(5)
9349
+ * assert ["5: 42.0", "6: -1.0"] == nums.withIndex(5).collect { n, idx {@code ->} "$idx: $n" }
9350
+ * </pre>
9351
+ *
9352
+ * @param self a float array
9353
+ * @param offset an index to start from
9354
+ * @return a zipped list with indices
9355
+ * @see DefaultGroovyMethods#withIndex(Iterable)
9356
+ * @since 5.0.0
9357
+ */
9358
+ public static List <Tuple2 <Float , Integer >> withIndex (float [] self , int offset ) {
9359
+ return DefaultGroovyMethods .withIndex (new FloatArrayIterable (self ), offset );
9360
+ }
9361
+
9362
+ /**
9363
+ * Zips a double array with indices in (value, index) order.
9364
+ * <p/>
9365
+ * Example usage:
9366
+ * <pre class="groovyTestCase">
9367
+ * double[] nums = [42.0d, -1.0d]
9368
+ * assert [[42.0d, 0], [-1.0d, 1]] == nums.withIndex()
9369
+ * assert ["0: 42.0", "1: -1.0"] == nums.withIndex().collect { n, idx {@code ->} "$idx: $n" }
9370
+ * </pre>
9371
+ *
9372
+ * @param self a double array
9373
+ * @return a zipped list with indices
9374
+ * @see DefaultGroovyMethods#withIndex(Iterable)
9375
+ * @since 5.0.0
9376
+ */
9377
+ public static List <Tuple2 <Double , Integer >> withIndex (double [] self ) {
9378
+ return withIndex (self , 0 );
9379
+ }
9380
+
9381
+ /**
9382
+ * Zips a double array with indices in (value, index) order starting from a given index.
9383
+ * <p/>
9384
+ * Example usage:
9385
+ * <pre class="groovyTestCase">
9386
+ * double[] nums = [42.0d, -1.0d]
9387
+ * assert [[42.0d, 5], [-1.0d, 6]] == nums.withIndex(5)
9388
+ * assert ["5: 42.0", "6: -1.0"] == nums.withIndex(5).collect { n, idx {@code ->} "$idx: $n" }
9389
+ * </pre>
9390
+ *
9391
+ * @param self a double array
9392
+ * @param offset an index to start from
9393
+ * @return a zipped list with indices
9394
+ * @see DefaultGroovyMethods#withIndex(Iterable)
9395
+ * @since 5.0.0
9396
+ */
9397
+ public static List <Tuple2 <Double , Integer >> withIndex (double [] self , int offset ) {
9398
+ return DefaultGroovyMethods .withIndex (new DoubleArrayIterable (self ), offset );
9399
+ }
9400
+
9208
9401
//--------------------------------------------------------------------------
9209
9402
// zip
9210
9403
0 commit comments