Skip to content

Commit c5cd317

Browse files
committed
Finish 9.6.0
2 parents 4002d74 + d4dbb01 commit c5cd317

File tree

8 files changed

+268
-18
lines changed

8 files changed

+268
-18
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ repositories {
1616
}
1717
1818
dependencies {
19-
compile 'com.spaceshift:rlib.common:9.5.0'
20-
compile 'com.spaceshift:rlib.fx:9.5.0'
21-
compile 'com.spaceshift:rlib.network:9.5.0'
22-
compile 'com.spaceshift:rlib.mail:9.5.0'
23-
compile 'com.spaceshift:rlib.testcontainers:9.5.0'
19+
compile 'com.spaceshift:rlib.common:9.6.0'
20+
compile 'com.spaceshift:rlib.fx:9.6.0'
21+
compile 'com.spaceshift:rlib.network:9.6.0'
22+
compile 'com.spaceshift:rlib.mail:9.6.0'
23+
compile 'com.spaceshift:rlib.testcontainers:9.6.0'
2424
}
2525
```
2626

@@ -41,27 +41,27 @@ dependencies {
4141
<dependency>
4242
<groupId>com.spaceshift</groupId>
4343
<artifactId>rlib.common</artifactId>
44-
<version>9.5.0</version>
44+
<version>9.6.0</version>
4545
</dependency>
4646
<dependency>
4747
<groupId>com.spaceshift</groupId>
4848
<artifactId>rlib.fx</artifactId>
49-
<version>9.5.0</version>
49+
<version>9.6.0</version>
5050
</dependency>
5151
<dependency>
5252
<groupId>com.spaceshift</groupId>
5353
<artifactId>rlib.network</artifactId>
54-
<version>9.5.0</version>
54+
<version>9.6.0</version>
5555
</dependency>
5656
<dependency>
5757
<groupId>com.spaceshift</groupId>
5858
<artifactId>rlib.mail</artifactId>
59-
<version>9.5.0</version>
59+
<version>9.6.0</version>
6060
</dependency>
6161
<dependency>
6262
<groupId>com.spaceshift</groupId>
6363
<artifactId>rlib.testcontainers</artifactId>
64-
<version>9.5.0</version>
64+
<version>9.6.0</version>
6565
</dependency>
6666

6767
```

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
}
99
}
1010

11-
rootProject.version = '9.5.0'
11+
rootProject.version = '9.6.0'
1212
group = 'com.spaceshift'
1313

1414
allprojects {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.ss.rlib.common.function;
2+
3+
/**
4+
* @author JavaSaBr
5+
*/
6+
@FunctionalInterface
7+
public interface BiIntPredicate {
8+
9+
boolean test(int first, int second);
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.ss.rlib.common.function;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
5+
@FunctionalInterface
6+
public interface NotNullFunctionInt<T> extends FunctionInt<T> {
7+
8+
int apply(@NotNull T object);
9+
}

rlib-common/src/main/java/com/ss/rlib/common/util/array/Array.java

Lines changed: 113 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import java.util.function.Consumer;
1616
import java.util.function.Function;
1717
import java.util.function.Predicate;
18-
import java.util.function.Supplier;
1918
import 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
*

rlib-common/src/main/java/com/ss/rlib/common/util/array/ConcurrentArray.java

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.jetbrains.annotations.Nullable;
77

88
import java.util.function.Function;
9-
import java.util.function.Supplier;
109

1110
/**
1211
* The interface with methods to manage thread-safe access with arrays.
@@ -416,6 +415,31 @@ default void writeUnlock(long stamp) {
416415
}
417416
}
418417

418+
/**
419+
* Search an element using the condition under {@link #readLock()} block.
420+
*
421+
* @param argument the argument.
422+
* @param filter the condition.
423+
* @return the found element or null.
424+
* @since 9.6.0
425+
*/
426+
default @Nullable E findAnyConvertedToIntInReadLock(
427+
int argument,
428+
@NotNull NotNullFunctionInt<? super E> converter,
429+
@NotNull BiIntPredicate filter
430+
) {
431+
if (isEmpty()) {
432+
return null;
433+
}
434+
435+
var stamp = readLock();
436+
try {
437+
return findAnyConvertedToInt(argument, converter, filter);
438+
} finally {
439+
readUnlock(stamp);
440+
}
441+
}
442+
419443
/**
420444
* Search an element by condition under {@link #readLock()} block.
421445
*
@@ -513,4 +537,28 @@ default <A, B> boolean removeIfInWriteLock(
513537
writeUnlock(stamp);
514538
}
515539
}
540+
541+
/**
542+
* Removes all of the elements of this collection that satisfy the given predicate.
543+
*
544+
* @param argument the additional argument.
545+
* @param converter the converter of the elements.
546+
* @param filter the predicate which returns {@code true} for elements to be removed.
547+
* @param <A> the argument's type.
548+
* @param <B> the element converted type.
549+
* @return {@code true} if any elements were removed.
550+
* @since 9.6.0
551+
*/
552+
default <A, B> boolean removeConvertedIfInWriteLock(
553+
@NotNull A argument,
554+
@NotNull NotNullFunction<? super E, B> converter,
555+
@NotNull NotNullBiPredicate<A, B> filter
556+
) {
557+
var stamp = writeLock();
558+
try {
559+
return removeConvertedIf(argument, converter, filter);
560+
} finally {
561+
writeUnlock(stamp);
562+
}
563+
}
516564
}

0 commit comments

Comments
 (0)