-
-
Notifications
You must be signed in to change notification settings - Fork 938
Expand file tree
/
Copy pathRubyArray.java
More file actions
1424 lines (1092 loc) · 51 KB
/
RubyArray.java
File metadata and controls
1424 lines (1092 loc) · 51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
**** BEGIN LICENSE BLOCK *****
* Version: EPL 2.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Eclipse Public
* License Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.eclipse.org/legal/epl-v20.html
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Copyright (C) 2001 Alan Moore <alan_moore@gmx.net>
* Copyright (C) 2001 Chad Fowler <chadfowler@chadfowler.com>
* Copyright (C) 2001-2002 Benoit Cerrina <b.cerrina@wanadoo.fr>
* Copyright (C) 2001-2004 Jan Arne Petersen <jpetersen@uni-bonn.de>
* Copyright (C) 2002-2004 Anders Bengtsson <ndrsbngtssn@yahoo.se>
* Copyright (C) 2002-2005 Thomas E Enebo <enebo@acm.org>
* Copyright (C) 2004-2005 Charles O Nutter <headius@headius.com>
* Copyright (C) 2004 Stefan Matthias Aust <sma@3plus4.de>
* Copyright (C) 2006 Ola Bini <Ola.Bini@ki.se>
* Copyright (C) 2006 Daniel Steer <damian.steer@hp.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the EPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the EPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****/
package org.jruby;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.RandomAccess;
import java.util.stream.Stream;
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.api.Create;
import org.jruby.api.JRubyAPI;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Block;
import org.jruby.runtime.Builtins;
import org.jruby.runtime.CallSite;
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.JavaSites;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.callsite.CachingCallSite;
import org.jruby.runtime.marshal.MarshalDumper;
import org.jruby.runtime.marshal.MarshalLoader;
import org.jruby.specialized.RubyArrayOneObject;
import org.jruby.specialized.RubyArrayTwoObject;
import org.jruby.util.TypeConverter;
import org.jruby.util.collections.StringArraySet;
import org.jruby.util.io.RubyInputStream;
import org.jruby.util.io.RubyOutputStream;
import static org.jruby.RubyEnumerator.SizeFn;
import static org.jruby.api.Access.fixnumClass;
import static org.jruby.api.Access.stringClass;
import static org.jruby.api.Define.defineClass;
import static org.jruby.api.Error.argumentError;
import static org.jruby.api.Warn.warn;
import static org.jruby.runtime.Visibility.PRIVATE;
/**
* The implementation of the built-in class Array in Ruby.
*
* Concurrency: no synchronization is required among readers, but
* all users must synchronize externally with writers.
*
* Note: elt(long) is based on notion if we exceed precision by passing in a long larger
* than int (actually Integer.MAX - 8) then it will just return nil. Anything using eltOk
* must know this already to avoid an AIOOBE. We do catch that in eltOk but only as an
* attempt at detecting concurrent modifications to the length. So if you improperly
* use eltOk you will get a conc error and not AIOOBE.
*
* Guidance for elt(long) is that if the Ruby method should raise if it is too large
* then you need to do that before you call this (toLong vs getValue/asLong).
*
* @param <T> What array holds
*
*/
@JRubyClass(name="Array", include = { "Enumerable" },
overrides = {RubyArrayNative.class, RubyArrayOneObject.class, RubyArrayTwoObject.class, StringArraySet.class})
public abstract class RubyArray<T extends IRubyObject> extends RubyObject implements List, RandomAccess {
public static final int DEFAULT_INSPECT_STR_SIZE = 10;
public static RubyClass createArrayClass(ThreadContext context, RubyClass Object, RubyModule Enumerable) {
return defineClass(context, "Array", Object, RubyArray::newEmptyArray).
reifiedClass(RubyArray.class).
kindOf(new RubyModule.JavaClassKindOf(RubyArray.class)).
classIndex(ClassIndex.ARRAY).
include(context, Enumerable).
defineMethods(context, RubyArray.class);
}
@Override
public ClassIndex getNativeClassIndex() {
return ClassIndex.ARRAY;
}
@Deprecated(since = "10.0.0.0")
public static IRubyObject create(IRubyObject klass, IRubyObject[] args, Block block) {
return create(klass.getRuntime().getCurrentContext(), klass, args, block);
}
@JRubyMethod(name = "[]", rest = true, meta = true)
public static IRubyObject create(ThreadContext context, IRubyObject klass, IRubyObject[] args, Block block) {
return RubyArrayNative.create(context, klass, args, block);
}
protected RubyArray(Ruby runtime, RubyClass klass) {
super(runtime, klass);
}
protected RubyArray(RubyClass klass) {
super(klass.runtime, klass);
}
protected RubyArray(Ruby runtime, RubyClass klass, boolean objectSpace) {
super(runtime, klass, objectSpace);
}
public static RubyArray<?> newArray(final Ruby runtime, final int len) {
return RubyArrayNative.newArray(runtime, len);
}
public static RubyArray<?> newArray(ThreadContext context, final int len) {
return RubyArrayNative.newArray(context, len);
}
public static RubyArray<?> newArrayLight(final Ruby runtime, final int len) {
return RubyArrayNative.newArrayLight(runtime, len);
}
@Deprecated(since = "10.0.0.0")
public static final RubyArray<?> newArray(final Ruby runtime) {
return newArray(runtime.getCurrentContext());
}
public static RubyArray<?> newArray(ThreadContext context) {
return RubyArrayNative.newArray(context);
}
public static RubyArray<?> newArrayLight(final Ruby runtime) {
return RubyArrayNative.newArrayLight(runtime);
}
public static RubyArray<?> newArray(Ruby runtime, IRubyObject obj) {
return RubyArrayNative.newArray(runtime, obj);
}
public static RubyArray<?> newArrayLight(Ruby runtime, IRubyObject obj) {
return RubyArrayNative.newArrayLight(runtime, obj);
}
public static RubyArray<?> newArrayLight(RubyClass arrayClass, IRubyObject obj) {
return RubyArrayNative.newArrayLight(arrayClass, obj);
}
public static RubyArray<?> newArrayLight(Ruby runtime, IRubyObject car, IRubyObject cdr) {
return RubyArrayNative.newArrayLight(runtime, car, cdr);
}
public static RubyArray<?> newArrayLight(RubyClass arrayClass, IRubyObject car, IRubyObject cdr) {
return RubyArrayNative.newArrayLight(arrayClass, car, cdr);
}
public static RubyArray<?> newArrayLight(Ruby runtime, IRubyObject... objs) {
return RubyArrayNative.newArrayLight(runtime, objs);
}
public static RubyArray<?> newArray(Ruby runtime, IRubyObject car, IRubyObject cdr) {
return RubyArrayNative.newArray(runtime, car, cdr);
}
public static RubyArray<?> newArray(Ruby runtime, IRubyObject first, IRubyObject second, IRubyObject third) {
return RubyArrayNative.newArray(runtime, first, second, third);
}
public static RubyArray<?> newArray(Ruby runtime, IRubyObject first, IRubyObject second, IRubyObject third, IRubyObject fourth) {
return RubyArrayNative.newArray(runtime, first, second, third, fourth);
}
public static RubyArray<?> newEmptyArray(Ruby runtime) {
return RubyArrayNative.newEmptyArray(runtime);
}
public static RubyArray<?> newEmptyArray(Ruby runtime, RubyClass klass) {
return RubyArrayNative.newEmptyArray(runtime, klass);
}
public static RubyArray<?> newArray(Ruby runtime, IRubyObject[] args) {
return RubyArrayNative.newArray(runtime, args);
}
public static RubyArray<?> newArray(Ruby runtime, Collection<? extends IRubyObject> collection) {
return RubyArrayNative.newArray(runtime, collection);
}
public static RubyArray<?> newArray(Ruby runtime, List<? extends IRubyObject> list) {
return RubyArrayNative.newArray(runtime, list);
}
public static RubyArray<?> newSharedArray(RubyClass arrayClass, IRubyObject[] shared) {
return RubyArrayNative.newSharedArray(arrayClass, shared);
}
public static RubyArray newArrayMayCopy(Ruby runtime, IRubyObject... args) {
return RubyArrayNative.newArrayMayCopy(runtime, args);
}
public static RubyArray newArrayMayCopy(Ruby runtime, IRubyObject[] args, int start) {
return RubyArrayNative.newArrayMayCopy(runtime, args, start);
}
/**
* Construct a new RubyArray given the specified range of elements in the source array. The elements
* <i>may</i> be copied into a new backing store, and therefore you should not expect future changes to the
* source array to be reflected. Conversely, you should not modify the array after passing it, since
* the contents <i>may not</i> be copied.
*
* @param runtime the runtime
* @param args the args
* @param start start index
* @param length number of elements
* @return an array referencing the given elements
*/
public static RubyArray newArrayMayCopy(Ruby runtime, IRubyObject[] args, int start, int length) {
return RubyArrayNative.newArrayMayCopy(runtime, args, start, length);
}
public static RubyArray newArrayNoCopy(Ruby runtime, IRubyObject... args) {
return RubyArrayNative.newArrayNoCopy(runtime, args);
}
public static RubyArray newArrayNoCopy(Ruby runtime, IRubyObject[] args, int begin) {
return RubyArrayNative.newArrayNoCopy(runtime, args, begin);
}
public static RubyArray newArrayNoCopy(Ruby runtime, IRubyObject[] args, int begin, int length) {
return RubyArrayNative.newArrayNoCopy(runtime, args, begin, length);
}
public static RubyArray newArrayNoCopyLight(Ruby runtime, IRubyObject[] args) {
return RubyArrayNative.newArrayNoCopyLight(runtime, args);
}
@Deprecated(since = "10.0.0.0")
protected static final void checkLength(Ruby runtime, long length) {
checkLength(runtime.getCurrentContext(), length);
}
public static final int checkLength(ThreadContext context, long length) {
if (length < 0) throw argumentError(context, "negative array size (or size too big)");
if (length >= Integer.MAX_VALUE) throw argumentError(context, "array size too big");
return (int) length;
}
/**
* @deprecated RubyArray implements List, use it directly
* @return a read-only copy of this list
*/
@Deprecated(since = "9.4-")
public final List<IRubyObject> getList() {
return Arrays.asList(toJavaArray());
}
public abstract int getLength();
/**
* @return ""
* @deprecated Use {@link RubyArray#toJavaArray(ThreadContext)} instead.
*/
@Deprecated(since = "10.0.0.0")
public IRubyObject[] toJavaArray() {
return toJavaArray(getCurrentContext());
}
/**
* Return a Java array copy of the elements contained in this Array.
*
* This version always creates a new Java array that is exactly the length of the Array's elements.
*
* @return a Java array with exactly the size and contents of this RubyArray's elements
*/
public abstract IRubyObject[] toJavaArray(ThreadContext context);
/**
* Return a reference to this RubyArray's underlying Java array, if it is not shared with another RubyArray, or
* an exact copy of the relevant range otherwise.
*
* This method is typically used to work with the underlying array directly, knowing that it is not shared and that
* all accesses must consider the begin offset.
*
* @return The underlying Java array for this RubyArray, or a copy if that array is shared.
*/
public abstract IRubyObject[] toJavaArrayUnsafe();
/**
* Return a Java array of the elements contained in this array, possibly a new array object.
*
* Use this method to potentially avoid making a new array and copying elements when the Array does not view a
* subset of the underlying Java array.
*
* @return a Java array with exactly the size and contents of this RubyArray's elements, possibly the actual
* underlying array.
*/
public abstract IRubyObject[] toJavaArrayMaybeUnsafe();
public abstract boolean isSharedJavaArray(RubyArray other);
@JRubyMethod(visibility = PRIVATE)
public abstract IRubyObject initialize(ThreadContext context, Block block);
@JRubyMethod(visibility = PRIVATE)
public abstract IRubyObject initialize(ThreadContext context, IRubyObject arg0, Block block);
@JRubyMethod(visibility = PRIVATE)
public abstract IRubyObject initialize(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block);
@JRubyMethod(name = {"initialize_copy"}, visibility=PRIVATE)
public abstract IRubyObject initialize_copy(ThreadContext context, IRubyObject orig);
public abstract RubyArray aryDup();
@Deprecated(since = "10.0.0.0")
public IRubyObject replace(IRubyObject orig) {
return replace(getCurrentContext(), orig);
}
@JRubyMethod(name = {"replace"})
public abstract IRubyObject replace(ThreadContext context, IRubyObject orig);
@Override
public abstract RubyString to_s(ThreadContext context);
public abstract boolean includes(ThreadContext context, IRubyObject item);
protected abstract boolean includesByEql(ThreadContext context, IRubyObject item);
@JRubyMethod(name = "hash")
public abstract RubyFixnum hash(ThreadContext context);
public abstract IRubyObject store(long index, IRubyObject value);
/**
* Store an element at the specified index or throw if the index is invalid.
* @param context the current thread context
* @param index the offset to store the value
* @param value the value to be stored
* @return the value set
*/
@JRubyAPI
public abstract IRubyObject store(ThreadContext context, long index, IRubyObject value);
// note: packed arrays will unpack in overridden version of this
protected abstract void storeInternal(ThreadContext context, int index, IRubyObject value);
protected abstract IRubyObject elt(long offset);
public abstract T eltOk(long offset);
public abstract T eltSetOk(long offset, T value);
public abstract T eltSetOk(int offset, T value);
public abstract IRubyObject entry(long offset);
public abstract IRubyObject entry(int offset);
public abstract T eltInternal(int offset);
public abstract T eltInternalSet(int offset, T item);
/**
* Variable arity version for compatibility. Not bound to a Ruby method.
* @deprecated Use the versions with zero, one, or two args.
*/
@Deprecated(since = "9.4-")
public IRubyObject fetch(ThreadContext context, IRubyObject[] args, Block block) {
switch (args.length) {
case 1:
return fetch(context, args[0], block);
case 2:
return fetch(context, args[0], args[1], block);
default:
Arity.raiseArgumentError(context, args.length, 1, 2);
return null; // not reached
}
}
@JRubyMethod(rest = true)
public abstract IRubyObject fetch_values(ThreadContext context, IRubyObject[] args, Block block);
@JRubyMethod
public abstract IRubyObject fetch(ThreadContext context, IRubyObject arg0, Block block);
@JRubyMethod
public abstract IRubyObject fetch(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block);
public static RubyArray aryToAry(ThreadContext context, IRubyObject obj) {
IRubyObject tmp = TypeConverter.checkArrayType(context, obj);
return tmp != context.nil ? (RubyArray) tmp : RubyArray.newArray(context.runtime, obj);
}
@Deprecated(since = "10.0.0.0")
public IRubyObject insert(IRubyObject arg) {
return insert(getCurrentContext(), arg);
}
@JRubyMethod(name = "insert")
public abstract IRubyObject insert(ThreadContext context, IRubyObject arg);
@Deprecated(since = "10.0.0.0")
public IRubyObject insert(IRubyObject arg1, IRubyObject arg2) {
return insert(getCurrentContext(), arg1, arg2);
}
@JRubyMethod(name = "insert")
public abstract IRubyObject insert(ThreadContext context, IRubyObject arg1, IRubyObject arg2);
@Deprecated(since = "10.0.0.0")
public IRubyObject insert(IRubyObject[] args) {
return insert(getCurrentContext(), args);
}
@JRubyMethod(name = "insert", required = 1, rest = true, checkArity = false)
public abstract IRubyObject insert(ThreadContext context, IRubyObject[] args);
@Deprecated(since = "10.0.0.0")
public RubyArray transpose() {
return transpose(getCurrentContext());
}
@JRubyMethod(name = "transpose")
public abstract RubyArray transpose(ThreadContext context);
@Deprecated(since = "10.0.0.0")
public IRubyObject values_at(IRubyObject[] args) {
return values_at(getCurrentContext(), args);
}
@JRubyMethod(name = "values_at", rest = true)
public abstract IRubyObject values_at(ThreadContext context, IRubyObject[] args);
public abstract IRubyObject subseqLight(long beg, long len);
public abstract IRubyObject subseq(RubyClass metaClass, long beg, long len, boolean light);
@JRubyMethod(name = "length", alias = "size")
public abstract RubyFixnum length(ThreadContext context);
@Deprecated(since = "10.0.0.0")
public RubyFixnum length() {
return length(getCurrentContext());
}
/**
* A size method suitable for lambda method reference implementation of {@link SizeFn#size(ThreadContext, IRubyObject, IRubyObject[])}
*
* @see SizeFn#size(ThreadContext, IRubyObject, IRubyObject[])
*/
protected static IRubyObject size(ThreadContext context, RubyArray self, IRubyObject[] args) {
return self.length(context);
}
@Deprecated(since = "10.0.0.0")
public RubyArray<?> append(IRubyObject item) {
return append(getCurrentContext(), item);
}
@JRubyMethod(name = "<<")
public abstract RubyArray append(ThreadContext context, IRubyObject item);
@Deprecated(since = "10.0.3.0") // not-used
public RubyArray<?> push_m(IRubyObject[] items) {
return push(items);
}
@Deprecated(since = "10.0.0.0")
public RubyArray push(IRubyObject item) {
append(item);
return this;
}
@JRubyMethod(name = "push", alias = "append")
public abstract RubyArray push(ThreadContext context, IRubyObject item);
@Deprecated(since = "10.0.0.0")
public RubyArray<?> push(IRubyObject[] items) {
return push(getCurrentContext(), items);
}
@JRubyMethod(name = "push", alias = "append", rest = true)
public abstract RubyArray push(ThreadContext context, IRubyObject[] items);
@JRubyMethod
public abstract IRubyObject pop(ThreadContext context);
@JRubyMethod
public abstract IRubyObject pop(ThreadContext context, IRubyObject num);
@JRubyMethod(name = "shift")
public abstract IRubyObject shift(ThreadContext context);
@JRubyMethod(name = "shift")
public abstract IRubyObject shift(ThreadContext context, IRubyObject num);
@Deprecated(since = "10.0.0.0")
public IRubyObject unshift() {
return unshift(getCurrentContext());
}
@JRubyMethod(name = "unshift", alias = "prepend")
public abstract IRubyObject unshift(ThreadContext context);
@Deprecated(since = "10.0.0.0")
public IRubyObject unshift(IRubyObject item) {
return unshift(getCurrentContext(), item);
}
@JRubyMethod(name = "unshift", alias = "prepend")
public abstract IRubyObject unshift(ThreadContext context, IRubyObject item);
@Deprecated(since = "10.0.0.0")
public IRubyObject unshift(IRubyObject[] items) {
return unshift(getCurrentContext(), items);
}
@JRubyMethod(name = "unshift", alias = "prepend", rest = true)
public abstract IRubyObject unshift(ThreadContext context, IRubyObject[] items);
@JRubyMethod(name = "include?")
public abstract RubyBoolean include_p(ThreadContext context, IRubyObject item);
/**
* Variable arity version for compatibility. Not bound to a Ruby method.
* @deprecated Use the versions with zero, one, or two args.
*/
@Deprecated(since = "10.0.0.0")
public IRubyObject aref(IRubyObject[] args) {
ThreadContext context = getCurrentContext();
return switch (args.length) {
case 1 -> aref(context, args[0]);
case 2 -> aref(context, args[0], args[1]);
default -> {
Arity.raiseArgumentError(context, args.length, 1, 2);
yield null;
}
};
}
@JRubyMethod(name = {"[]", "slice"})
public abstract IRubyObject aref(ThreadContext context, IRubyObject arg0);
@Deprecated(since = "10.0.0.0")
public IRubyObject aref(IRubyObject arg0, IRubyObject arg1) {
return aref(getCurrentContext(), arg0, arg1);
}
@JRubyMethod(name = {"[]", "slice"})
public abstract IRubyObject aref(ThreadContext context, IRubyObject arg0, IRubyObject arg1);
/**
* Variable arity version for compatibility. Not bound to a Ruby method.
* @deprecated Use the versions with zero, one, or two args.
*/
@Deprecated(since = "9.4-")
public IRubyObject aset(IRubyObject[] args) {
return switch (args.length) {
case 2 -> aset(args[0], args[1]);
case 3 -> aset(args[0], args[1], args[2]);
default -> throw argumentError(getCurrentContext(), "wrong number of arguments (" + args.length + " for 2)");
};
}
@Deprecated(since = "10.0.0.0")
public IRubyObject aset(IRubyObject arg0, IRubyObject arg1) {
return aset(getCurrentContext(), arg0, arg1);
}
/**
* @param arg0
* @param arg1
* @param arg2
* @return ""
* @deprecated Use {@link RubyArray#aset(ThreadContext, IRubyObject, IRubyObject, IRubyObject)} instead.
*/
@Deprecated(since = "10.0.0.0")
public IRubyObject aset(IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
return aset(getCurrentContext(), arg0, arg1, arg2);
}
@JRubyMethod(name = "[]=")
public abstract IRubyObject aset(ThreadContext context, IRubyObject arg0, IRubyObject arg1);
@JRubyMethod(name = "[]=")
public abstract IRubyObject aset(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2);
/**
* @param pos
* @return ""
* @deprecated Use {@link RubyArray#at(ThreadContext, IRubyObject)} instead.
*/
@Deprecated(since = "10.0.0.0")
public IRubyObject at(IRubyObject pos) {
return at(getCurrentContext(), pos);
}
@JRubyMethod(name = "at")
public abstract IRubyObject at(ThreadContext context, IRubyObject pos);
@JRubyMethod(name = "concat")
public abstract RubyArray concat(ThreadContext context, IRubyObject obj);
@Deprecated(since = "10.0.0.0")
public RubyArray aryAppend(RubyArray y) {
return aryAppend(getCurrentContext(), y);
}
public abstract RubyArray aryAppend(ThreadContext context, RubyArray<?> y);
@JRubyMethod(name = "concat", rest = true)
public abstract RubyArray concat(ThreadContext context, IRubyObject[] objs);
public abstract RubyArray concat(IRubyObject obj);
@JRubyMethod(name = "inspect", alias = "to_s")
public abstract RubyString inspect(ThreadContext context);
@Deprecated(since = "9.4-")
public IRubyObject first(IRubyObject[] args) {
return switch (args.length) {
case 0 -> first(getCurrentContext());
case 1 -> first(getCurrentContext(), args[0]);
default -> {
Arity.raiseArgumentError(getCurrentContext(), args.length, 0, 1);
yield null;
}
};
}
@Deprecated(since = "10.0.0.0")
public IRubyObject first() {
return first(getCurrentContext());
}
@JRubyAPI
@JRubyMethod(name = "first")
public abstract IRubyObject first(ThreadContext context);
@Deprecated(since = "10.0.0.0")
public IRubyObject first(IRubyObject arg0) {
return first(getCurrentContext(), arg0);
}
@JRubyAPI
@JRubyMethod(name = "first")
public abstract IRubyObject first(ThreadContext context, IRubyObject arg0);
/**
* Variable arity version for compatibility. Not bound to a Ruby method.
* @deprecated Use the versions with zero, one, or two args.
*/
@Deprecated(since = "9.4-")
public IRubyObject last(IRubyObject[] args) {
return switch (args.length) {
case 0 -> last(getCurrentContext());
case 1 -> last(getCurrentContext(), args[0]);
default -> {
Arity.raiseArgumentError(getCurrentContext(), args.length, 0, 1);
yield null;
}
};
}
@Deprecated(since = "10.0.0.0")
public IRubyObject last() {
return last(getCurrentContext());
}
@JRubyAPI
@JRubyMethod(name = "last")
public abstract IRubyObject last(ThreadContext context);
@Deprecated(since = "10.0.0.0")
public IRubyObject last(IRubyObject arg0) {
return last(getCurrentContext(), arg0);
}
@JRubyMethod(name = "last")
public abstract IRubyObject last(ThreadContext context, IRubyObject arg0);
@JRubyMethod
public abstract IRubyObject each(ThreadContext context, Block block);
public abstract IRubyObject eachSlice(ThreadContext context, int size, Block block);
@JRubyMethod
public abstract IRubyObject each_slice(ThreadContext context, IRubyObject arg, Block block);
@JRubyMethod
public abstract IRubyObject each_index(ThreadContext context, Block block);
@JRubyMethod
public abstract IRubyObject reverse_each(ThreadContext context, Block block);
@Deprecated(since = "10.0.0.0")
public IRubyObject join19(final ThreadContext context, IRubyObject sep) {
return join(context, sep);
}
@JRubyMethod(name = "join")
public abstract IRubyObject join(final ThreadContext context, IRubyObject sep);
@Deprecated(since = "10.0.0.0")
public IRubyObject join19(ThreadContext context) {
return join(context);
}
@JRubyMethod(name = "join")
public abstract IRubyObject join(ThreadContext context);
@JRubyMethod(name = "to_a")
@Override
public abstract RubyArray to_a(ThreadContext context);
@Deprecated(since = "10.0.0.0")
public IRubyObject to_ary() {
return this;
}
@JRubyMethod(name = "to_ary")
public final IRubyObject to_ary(ThreadContext context) {
return this;
}
@JRubyMethod(name = "to_h")
public abstract IRubyObject to_h(ThreadContext context, Block block);
@Override
public final RubyArray convertToArray() {
return this;
}
@Override
public final IRubyObject checkArrayType(){
return this;
}
@JRubyMethod(name = "==")
@Override
public abstract IRubyObject op_equal(ThreadContext context, IRubyObject obj);
public abstract RubyBoolean compare(ThreadContext context, CallSite site, IRubyObject other);
@JRubyMethod(name = "eql?")
public abstract IRubyObject eql(ThreadContext context, IRubyObject obj);
/**
* @return ""
* @deprecated Use {@link RubyArray#compact_bang(ThreadContext)}
*/
@Deprecated(since = "10.0.0.0")
public IRubyObject compact_bang() {
return compact_bang(getCurrentContext());
}
@JRubyMethod(name = "compact!")
public abstract IRubyObject compact_bang(ThreadContext context);
@Deprecated(since = "10.0.0.0")
public IRubyObject compact() {
return compact(getCurrentContext());
}
@JRubyMethod(name = "compact")
public abstract IRubyObject compact(ThreadContext context);
@Deprecated(since = "10.0.0.0")
public IRubyObject empty_p() {
return empty_p(getCurrentContext());
}
@JRubyMethod(name = "empty?")
public abstract IRubyObject empty_p(ThreadContext context);
@Deprecated(since = "10.0.0.0")
public IRubyObject rb_clear() {
return rb_clear(getCurrentContext());
}
@JRubyMethod(name = "clear")
public abstract IRubyObject rb_clear(ThreadContext context);
@JRubyMethod
public abstract IRubyObject fill(ThreadContext context, Block block);
@JRubyMethod
public abstract IRubyObject fill(ThreadContext context, IRubyObject arg, Block block);
@JRubyMethod
public abstract IRubyObject fill(ThreadContext context, IRubyObject arg1, IRubyObject arg2, Block block);
@JRubyMethod
public abstract IRubyObject fill(ThreadContext context, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, Block block);
public abstract IRubyObject index(ThreadContext context, IRubyObject obj);
@JRubyMethod(name = {"index", "find_index"})
public abstract IRubyObject index(ThreadContext context, IRubyObject obj, Block unused);
@JRubyMethod(name = {"index", "find_index"})
public abstract IRubyObject index(ThreadContext context, Block block);
@JRubyMethod
public abstract IRubyObject bsearch(ThreadContext context, Block block);
@JRubyMethod
public abstract IRubyObject bsearch_index(ThreadContext context, Block block);
@JRubyMethod
public abstract IRubyObject rindex(ThreadContext context, IRubyObject obj, Block unused);
@JRubyMethod
public abstract IRubyObject rindex(ThreadContext context, Block block);
@Deprecated(since = "10.0.0.0")
public IRubyObject indexes(IRubyObject[] args) {
return indexes(getCurrentContext(), args);
}
@Deprecated(since = "10.0.0.0")
public IRubyObject indexes(ThreadContext context, IRubyObject[] args) {
int argc = Arity.checkArgumentCount(context, args, 1, -1);
warn(context, "Array#indexes is deprecated; use Array#values_at");
if (argc == 1) return Create.newArray(context, args[0]);
RubyArrayNative ary = RubyArrayNative.newBlankArrayInternal(context.runtime, argc);
for (int i = 0; i < argc; i++) {
ary.storeInternal(context, i, aref(context, args[i]));
}
ary.realLength = argc;
return ary;
}
@Deprecated(since = "10.0.0.0")
public IRubyObject reverse_bang() {
return reverse_bang(getCurrentContext());
}
@JRubyMethod(name = "reverse!")
public abstract IRubyObject reverse_bang(ThreadContext context);
@Deprecated(since = "10.0.0.0")
public IRubyObject reverse() {
return reverse(getCurrentContext());
}
@JRubyAPI
@JRubyMethod(name = "reverse")
public abstract IRubyObject reverse(ThreadContext context);
@JRubyMethod(name = {"collect"})
public abstract IRubyObject rbCollect(ThreadContext context, Block block);
@JRubyMethod(name = {"map"})
public abstract IRubyObject map(ThreadContext context, Block block);
@JRubyMethod(name = "collect!")
public abstract IRubyObject collect_bang(ThreadContext context, Block block);
@JRubyMethod(name = "map!")
public abstract IRubyObject map_bang(ThreadContext context, Block block);
@JRubyMethod(name = "select", alias = "filter")
public abstract IRubyObject select(ThreadContext context, Block block);
@JRubyMethod(name = "select!", alias = "filter!")
public abstract IRubyObject select_bang(ThreadContext context, Block block);
@JRubyMethod
public abstract IRubyObject keep_if(ThreadContext context, Block block);
@JRubyMethod
public final IRubyObject deconstruct(ThreadContext context) {
return this;
}
@JRubyMethod
public abstract IRubyObject delete(ThreadContext context, IRubyObject item, Block block);
@Deprecated(since = "10.0.0.0")
public IRubyObject delete_at(int pos) {
return delete_at(getCurrentContext(), pos);
}
public abstract IRubyObject delete_at(ThreadContext context, int pos);
@Deprecated(since = "10.0.0.0")
public IRubyObject delete_at(IRubyObject obj) {
return delete_at(getCurrentContext(), obj);
}
@JRubyMethod(name = "delete_at")
public abstract IRubyObject delete_at(ThreadContext context, IRubyObject obj);
@JRubyMethod
public abstract IRubyObject reject(ThreadContext context, Block block);
@JRubyMethod(name = "reject!")
public abstract IRubyObject reject_bang(ThreadContext context, Block block);
@JRubyMethod
public abstract IRubyObject delete_if(ThreadContext context, Block block);
@JRubyMethod(optional = 1, rest = true, checkArity = false)
public abstract IRubyObject zip(ThreadContext context, IRubyObject[] args, Block block);
// This can be shared with RubyEnumerable to clean #zipCommon{Enum,Arg} a little
public static interface ArgumentVisitor {
IRubyObject visit(ThreadContext ctx, IRubyObject arg, int i);
}
@JRubyMethod(name = "<=>")
public abstract IRubyObject op_cmp(ThreadContext context, IRubyObject obj);
/**
* Variable arity version for compatibility. Not bound to a Ruby method.
* @deprecated Use the versions with zero, one, or two args.
*/
@Deprecated(since = "9.4-")
public IRubyObject slice_bang(IRubyObject[] args) {
switch (args.length) {
case 1:
return slice_bang(args[0]);
case 2:
return slice_bang(args[0], args[1]);
default:
Arity.raiseArgumentError(getCurrentContext(), args.length, 1, 2);
return null; // not reached
}
}
@Deprecated(since = "10.0.0.0")
public IRubyObject slice_bang(IRubyObject arg0) {
return slice_bang(getCurrentContext(), arg0);
}
@JRubyMethod(name = "slice!")
public abstract IRubyObject slice_bang(ThreadContext context, IRubyObject arg0);
@Deprecated(since = "10.0.0.0")
public IRubyObject slice_bang(IRubyObject arg0, IRubyObject arg1) {
return slice_bang(getCurrentContext(), arg0, arg1);
}
@JRubyMethod(name = "slice!")
public abstract IRubyObject slice_bang(ThreadContext context, IRubyObject arg0, IRubyObject arg1);
@JRubyMethod(name = "assoc")
public abstract IRubyObject assoc(ThreadContext context, IRubyObject key);
@JRubyMethod(name = "rassoc")
public abstract IRubyObject rassoc(ThreadContext context, IRubyObject value);
@JRubyMethod(name = "flatten!")
public abstract IRubyObject flatten_bang(ThreadContext context);
@JRubyMethod(name = "flatten!")
public abstract IRubyObject flatten_bang(ThreadContext context, IRubyObject arg);
@JRubyMethod(name = "flatten")
public abstract IRubyObject flatten(ThreadContext context);
@JRubyMethod(name = "flatten")
public abstract IRubyObject flatten(ThreadContext context, IRubyObject arg);
@JRubyMethod(name = "count")