Skip to content

Commit 2b2d238

Browse files
committed
Finish 9.9.0
2 parents 9a42e02 + fce7e23 commit 2b2d238

File tree

51 files changed

+2344
-391
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2344
-391
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.8.0'
20-
compile 'com.spaceshift:rlib.fx:9.8.0'
21-
compile 'com.spaceshift:rlib.network:9.8.0'
22-
compile 'com.spaceshift:rlib.mail:9.8.0'
23-
compile 'com.spaceshift:rlib.testcontainers:9.8.0'
19+
compile 'com.spaceshift:rlib.common:9.9.0'
20+
compile 'com.spaceshift:rlib.fx:9.9.0'
21+
compile 'com.spaceshift:rlib.network:9.9.0'
22+
compile 'com.spaceshift:rlib.mail:9.9.0'
23+
compile 'com.spaceshift:rlib.testcontainers:9.9.0'
2424
}
2525
```
2626

@@ -41,27 +41,27 @@ dependencies {
4141
<dependency>
4242
<groupId>com.spaceshift</groupId>
4343
<artifactId>rlib.common</artifactId>
44-
<version>9.8.0</version>
44+
<version>9.9.0</version>
4545
</dependency>
4646
<dependency>
4747
<groupId>com.spaceshift</groupId>
4848
<artifactId>rlib.fx</artifactId>
49-
<version>9.8.0</version>
49+
<version>9.9.0</version>
5050
</dependency>
5151
<dependency>
5252
<groupId>com.spaceshift</groupId>
5353
<artifactId>rlib.network</artifactId>
54-
<version>9.8.0</version>
54+
<version>9.9.0</version>
5555
</dependency>
5656
<dependency>
5757
<groupId>com.spaceshift</groupId>
5858
<artifactId>rlib.mail</artifactId>
59-
<version>9.8.0</version>
59+
<version>9.9.0</version>
6060
</dependency>
6161
<dependency>
6262
<groupId>com.spaceshift</groupId>
6363
<artifactId>rlib.testcontainers</artifactId>
64-
<version>9.8.0</version>
64+
<version>9.9.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.8.0'
11+
rootProject.version = '9.9.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+
import org.jetbrains.annotations.NotNull;
4+
5+
@FunctionalInterface
6+
public interface NotNullSafeTriFunction<F, S, T, R> extends SafeTriFunction<F, S, T, R> {
7+
8+
@Override
9+
@NotNull R apply(@NotNull F first, @NotNull S second, @NotNull T third) throws Exception;
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.ss.rlib.common.function;
2+
3+
import org.jetbrains.annotations.Nullable;
4+
5+
import java.util.function.Supplier;
6+
7+
@FunctionalInterface
8+
public interface NullableSupplier<T> extends Supplier<T> {
9+
10+
@Override
11+
@Nullable T get();
12+
}
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.Nullable;
4+
5+
@FunctionalInterface
6+
public interface SafeTriFunction<F, S, T, R> {
7+
8+
@Nullable R apply(@Nullable F first, @Nullable S second, @Nullable T third) throws Exception;
9+
}

rlib-common/src/main/java/com/ss/rlib/common/util/ReflectionUtils.java

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.ss.rlib.common.util;
22

3+
import static com.ss.rlib.common.util.ArrayUtils.contains;
34
import com.ss.rlib.common.util.array.Array;
4-
import com.ss.rlib.common.util.array.ArrayFactory;
55
import org.jetbrains.annotations.NotNull;
66
import org.jetbrains.annotations.Nullable;
77

@@ -20,41 +20,53 @@ public final class ReflectionUtils {
2020
* Get all fields of the class.
2121
*
2222
* @param container the field container.
23-
* @param cs the class.
24-
* @param last the last class.
25-
* @param declared the flag of getting private fields.
23+
* @param startClass the class.
24+
* @param lastClass the last class.
25+
* @param declared the flag to get private fields as well.
2626
* @param exceptions exception fields.
2727
*/
2828
public static void addAllFields(
29-
@NotNull Array<Field> container,
30-
@NotNull Class<?> cs,
31-
@NotNull Class<?> last,
32-
boolean declared,
33-
@Nullable String... exceptions
29+
@NotNull Array<Field> container,
30+
@NotNull Class<?> startClass,
31+
@NotNull Class<?> lastClass,
32+
boolean declared,
33+
@NotNull String... exceptions
3434
) {
3535

36-
Class<?> next = cs;
36+
var next = startClass;
3737

38-
while (next != null && next != last) {
38+
while (next != null && next != lastClass) {
3939

40-
Field[] fields = declared ? next.getDeclaredFields() : next.getFields();
40+
var fields = declared ? next.getDeclaredFields() : next.getFields();
4141

4242
next = next.getSuperclass();
4343

4444
if (fields.length < 1) {
4545
continue;
4646
}
4747

48-
if (exceptions == null || exceptions.length < 1) {
48+
if (exceptions.length < 1) {
4949
container.addAll(fields);
5050
} else {
51-
ArrayUtils.forEach(fields, toCheck ->
52-
!ArrayUtils.contains(exceptions, toCheck.getName()),
53-
container::add);
51+
ArrayUtils.forEach(fields, toCheck -> !contains(exceptions, toCheck.getName()), container::add);
5452
}
5553
}
5654
}
5755

56+
/**
57+
* Get all fields of a class.
58+
*
59+
* @param cs the class.
60+
* @param exceptions exception fields.
61+
* @return the all declared fields.
62+
* @since 9.9.0
63+
*/
64+
public static @NotNull Array<Field> getAllDeclaredFields(@NotNull Class<?> cs, @NotNull String... exceptions) {
65+
var container = Array.ofType(Field.class);
66+
addAllFields(container, cs, Object.class, true, exceptions);
67+
return container;
68+
}
69+
5870
/**
5971
* Get all fields of the class.
6072
*
@@ -65,12 +77,12 @@ public static void addAllFields(
6577
* @return the all fields
6678
*/
6779
public static @NotNull Array<Field> getAllFields(
68-
@NotNull Class<?> cs,
69-
@NotNull Class<?> last,
70-
boolean declared,
71-
@Nullable String... exceptions
80+
@NotNull Class<?> cs,
81+
@NotNull Class<?> last,
82+
boolean declared,
83+
@NotNull String... exceptions
7284
) {
73-
Array<Field> container = ArrayFactory.newArray(Field.class);
85+
var container = Array.ofType(Field.class);
7486
addAllFields(container, cs, last, declared, exceptions);
7587
return container;
7688
}

rlib-common/src/main/java/com/ss/rlib/common/util/Utils.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,34 @@ public static <F, S> void unchecked(
264264
}
265265
}
266266

267+
/**
268+
* Execute the function with auto-converting a checked exception to an unchecked.
269+
*
270+
* @param first the first argument.
271+
* @param second the second argument.
272+
* @param function the function.
273+
* @param <F> the first's type.
274+
* @param <S> the second's type.
275+
* @param <T> the third's type.
276+
* @param <R> the result's type.
277+
* @return the result.
278+
* @since 9.9.0
279+
*/
280+
public static <F, S, T, R> @NotNull R uncheckedGet(
281+
@NotNull F first,
282+
@NotNull S second,
283+
@NotNull T third,
284+
@NotNull NotNullSafeTriFunction<F, S, T, R> function
285+
) {
286+
try {
287+
return function.apply(first, second, third);
288+
} catch (IOException e) {
289+
throw new UncheckedIOException(e);
290+
} catch (Exception e) {
291+
throw new RuntimeException(e);
292+
}
293+
}
294+
267295
/**
268296
* Try to execute a function with some result.
269297
*

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

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,31 @@ default void writeUnlock(long stamp) {
353353
}
354354
}
355355

356+
/**
357+
* Execute a function to get some result under {@link #readLock()} block.
358+
*
359+
* @param first the first argument for the function.
360+
* @param second the second argument for the function.
361+
* @param function the function.
362+
* @param <A> the first argument's type.
363+
* @param <T> the second argument's type.
364+
* @param <R> the result's type.
365+
* @return the result from the function.
366+
* @since 9.9.0
367+
*/
368+
default <A, T, R> @Nullable R getInReadLock(
369+
@NotNull A first,
370+
@NotNull T second,
371+
@NotNull NotNullNullableTripleFunction<ConcurrentArray<E>, A, T, R> function
372+
) {
373+
var stamp = readLock();
374+
try {
375+
return function.apply(this, first, second);
376+
} finally {
377+
readUnlock(stamp);
378+
}
379+
}
380+
356381
/**
357382
* Execute a function to get some result under {@link #writeLock()} block.
358383
*
@@ -391,6 +416,31 @@ default void writeUnlock(long stamp) {
391416
}
392417
}
393418

419+
/**
420+
* Execute a function to get some result under {@link #writeLock()} block.
421+
*
422+
* @param first the first argument for the function.
423+
* @param second the second argument for the function.
424+
* @param function the function.
425+
* @param <A> the first argument's type.
426+
* @param <T> the second argument's type.
427+
* @param <R> the result's type.
428+
* @return the result from the function.
429+
* @since 9.9.0
430+
*/
431+
default <A, T, R> @Nullable R getInWriteLock(
432+
@NotNull A first,
433+
@NotNull T second,
434+
@NotNull NotNullNullableTripleFunction<ConcurrentArray<E>, A, T, R> function
435+
) {
436+
var stamp = writeLock();
437+
try {
438+
return function.apply(this, first, second);
439+
} finally {
440+
writeUnlock(stamp);
441+
}
442+
}
443+
394444
/**
395445
* Execute a function under {@link #readLock()} block.
396446
*
@@ -433,6 +483,33 @@ default void writeUnlock(long stamp) {
433483
return this;
434484
}
435485

486+
/**
487+
* Execute a function under {@link #readLock()} block.
488+
*
489+
* @param <A> the first argument's type.
490+
* @param <T> the second argument's type.
491+
* @param first the first argument.
492+
* @param second the second argument.
493+
* @param function the function.
494+
* @return this array.
495+
* @since 9.9.0
496+
*/
497+
default <A, T> @NotNull ConcurrentArray<E> runInReadLock(
498+
@NotNull A first,
499+
@NotNull T second,
500+
@NotNull NotNullTripleConsumer<ConcurrentArray<E>, A, T> function
501+
) {
502+
503+
var stamp = readLock();
504+
try {
505+
function.accept(this, first, second);
506+
} finally {
507+
readUnlock(stamp);
508+
}
509+
510+
return this;
511+
}
512+
436513
/**
437514
* Execute a function under {@link #writeLock()} block.
438515
*
@@ -474,6 +551,31 @@ default void writeUnlock(long stamp) {
474551
return this;
475552
}
476553

554+
/**
555+
* Execute a function under {@link #writeLock()} block.
556+
*
557+
* @param first the first argument for the function.
558+
* @param second the second argument for the function.
559+
* @param function the function.
560+
* @param <A> the first argument's type.
561+
* @param <T> the second argument's type.
562+
* @return this array.
563+
* @since 9.9.0
564+
*/
565+
default <A, T> @NotNull ConcurrentArray<E> runInWriteLock(
566+
@NotNull A first,
567+
@NotNull T second,
568+
@NotNull NotNullTripleConsumer<ConcurrentArray<E>, A, T> function
569+
) {
570+
var stamp = writeLock();
571+
try {
572+
function.accept(this, first, second);
573+
} finally {
574+
writeUnlock(stamp);
575+
}
576+
return this;
577+
}
578+
477579
/**
478580
* Search an element using the condition under {@link #readLock()} block.
479581
*

0 commit comments

Comments
 (0)