|
15 | 15 | import java.util.function.Consumer; |
16 | 16 | import java.util.function.Function; |
17 | 17 | import java.util.function.Predicate; |
18 | | -import java.util.function.Supplier; |
19 | 18 | import java.util.stream.Stream; |
20 | 19 |
|
21 | 20 | /** |
@@ -56,7 +55,7 @@ public interface Array<E> extends Collection<E>, Serializable, Reusable, Cloneab |
56 | 55 | * @return the new read only array. |
57 | 56 | */ |
58 | 57 | 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())); |
60 | 59 | } |
61 | 60 |
|
62 | 61 | /** |
@@ -723,6 +722,40 @@ default <A, B> boolean removeIf( |
723 | 722 | return removed > 0; |
724 | 723 | } |
725 | 724 |
|
| 725 | + /** |
| 726 | + * Removes all of the elements of this collection that satisfy the given predicate. |
| 727 | + * |
| 728 | + * @param argument the additional argument. |
| 729 | + * @param converter the converter of the elements. |
| 730 | + * @param filter the predicate which returns {@code true} for elements to be removed. |
| 731 | + * @param <A> the argument's type. |
| 732 | + * @param <B> the element converted type. |
| 733 | + * @return {@code true} if any elements were removed. |
| 734 | + */ |
| 735 | + default <A, B> boolean removeConvertedIf( |
| 736 | + @NotNull A argument, |
| 737 | + @NotNull NotNullFunction<? super E, B> converter, |
| 738 | + @NotNull NotNullBiPredicate<A, B> filter |
| 739 | + ) { |
| 740 | + |
| 741 | + var array = array(); |
| 742 | + var removed = 0; |
| 743 | + |
| 744 | + for (int i = 0, length = size(); i < length; i++) { |
| 745 | + |
| 746 | + var element = array[i]; |
| 747 | + |
| 748 | + if (filter.test(argument, converter.apply(element))) { |
| 749 | + remove(i); |
| 750 | + i--; |
| 751 | + length--; |
| 752 | + removed++; |
| 753 | + } |
| 754 | + } |
| 755 | + |
| 756 | + return removed > 0; |
| 757 | + } |
| 758 | + |
726 | 759 | /** |
727 | 760 | * Return true if there is at least an element for the condition. |
728 | 761 | * |
|
0 commit comments