1515import java .util .function .Consumer ;
1616import java .util .function .Function ;
1717import java .util .function .Predicate ;
18- import java .util .function .Supplier ;
1918import java .util .stream .Stream ;
2019
2120/**
@@ -56,7 +55,7 @@ public interface Array<E> extends Collection<E>, Serializable, Reusable, Cloneab
5655 * @return the new read only array.
5756 */
5857 static <T > @ NotNull ReadOnlyArray <T > of (@ NotNull Array <T > another ) {
59- return ArrayFactory .newReadOnlyArray (ArrayUtils .copyOf (another .array (), 0 , another .size ()));
58+ return ArrayFactory .newReadOnlyArray (Arrays .copyOf (another .array (), another .size ()));
6059 }
6160
6261 /**
@@ -125,6 +124,15 @@ public interface Array<E> extends Collection<E>, Serializable, Reusable, Cloneab
125124 return ArrayFactory ::newConcurrentStampedLockArray ;
126125 }
127126
127+ /**
128+ * Copy all elements from this array to a target array.
129+ *
130+ * @param target the target array.
131+ */
132+ default void copyTo (@ NotNull Array <? super E > target ) {
133+ target .addAll (this );
134+ }
135+
128136 /**
129137 * Adds all elements from the array to this array.
130138 *
@@ -419,8 +427,7 @@ default int lastIndexOf(@NotNull Object object) {
419427 }
420428
421429 /**
422- * Removes all of this target's elements that are also contained in the specified array (optional operation). After
423- * this call returns, this array will contain no elements in common with the specified array.
430+ * Removes all of this target's elements that are also contained in the specified array (optional operation).
424431 *
425432 * @param target array containing elements to be removed from this array.
426433 * @return true if this array changed as a result of the call.
@@ -433,15 +440,48 @@ default boolean removeAll(@NotNull Array<?> target) {
433440
434441 int count = 0 ;
435442
436- for (Object element : target .array ()) {
443+ for (var element : target .array ()) {
437444 if (element == null ) {
438445 break ;
439446 } else if (slowRemove (element )) {
440447 count ++;
441448 }
442449 }
443450
444- return count == target .size ();
451+ return count > 0 ;
452+ }
453+
454+ /**
455+ * Removes all of this target's elements that are also contained in the specified array (optional operation)
456+ * with reordering.
457+ *
458+ * @param target array containing elements to be removed from this array.
459+ * @return true if this array changed as a result of the call.
460+ */
461+ default boolean fastRemoveAll (@ NotNull Array <?> target ) {
462+
463+ if (target .isEmpty ()) {
464+ return false ;
465+ }
466+
467+ var count = 0 ;
468+ var array = array ();
469+
470+ for (int i = 0 , length = size (); i < length ; i ++) {
471+
472+ var element = array [i ];
473+
474+ if (!target .contains (element )) {
475+ continue ;
476+ }
477+
478+ fastRemove (i );
479+ i --;
480+ length --;
481+ count ++;
482+ }
483+
484+ return count > 0 ;
445485 }
446486
447487 @ Override
@@ -723,6 +763,41 @@ default <A, B> boolean removeIf(
723763 return removed > 0 ;
724764 }
725765
766+ /**
767+ * Removes all of the elements of this collection that satisfy the given predicate.
768+ *
769+ * @param argument the additional argument.
770+ * @param converter the converter of the elements.
771+ * @param filter the predicate which returns {@code true} for elements to be removed.
772+ * @param <A> the argument's type.
773+ * @param <B> the element converted type.
774+ * @return {@code true} if any elements were removed.
775+ * @since 9.6.0
776+ */
777+ default <A , B > boolean removeConvertedIf (
778+ @ NotNull A argument ,
779+ @ NotNull NotNullFunction <? super E , B > converter ,
780+ @ NotNull NotNullBiPredicate <A , B > filter
781+ ) {
782+
783+ var array = array ();
784+ var removed = 0 ;
785+
786+ for (int i = 0 , length = size (); i < length ; i ++) {
787+
788+ var element = array [i ];
789+
790+ if (filter .test (argument , converter .apply (element ))) {
791+ remove (i );
792+ i --;
793+ length --;
794+ removed ++;
795+ }
796+ }
797+
798+ return removed > 0 ;
799+ }
800+
726801 /**
727802 * Return true if there is at least an element for the condition.
728803 *
@@ -929,6 +1004,38 @@ default <T> boolean anyMatchR(@NotNull T argument, @NotNull NotNullBiPredicate<?
9291004 return null ;
9301005 }
9311006
1007+ /**
1008+ * Search an element using the condition.
1009+ *
1010+ * @param argument the argument.
1011+ * @param filter the condition.
1012+ * @return the found element or null.
1013+ * @since 9.6.0
1014+ */
1015+ default @ Nullable E findAnyConvertedToInt (
1016+ int argument ,
1017+ @ NotNull NotNullFunctionInt <? super E > converter ,
1018+ @ NotNull BiIntPredicate filter
1019+ ) {
1020+
1021+ if (isEmpty ()) {
1022+ return null ;
1023+ }
1024+
1025+ var array = array ();
1026+
1027+ for (int i = 0 , length = size (); i < length ; i ++) {
1028+
1029+ var element = array [i ];
1030+
1031+ if (filter .test (argument , converter .apply (element ))) {
1032+ return element ;
1033+ }
1034+ }
1035+
1036+ return null ;
1037+ }
1038+
9321039 /**
9331040 * Calculate a count of matched elements.
9341041 *
0 commit comments