Skip to content

Commit 6ebebcc

Browse files
Merge pull request #1296 from SpineEventEngine/pair-on-optional
Pair on `Optional`
2 parents 56204a2 + 95a75a1 commit 6ebebcc

File tree

16 files changed

+181
-57
lines changed

16 files changed

+181
-57
lines changed

buildSrc/src/main/kotlin/io/spine/gradle/internal/deps.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ object Versions {
9898
val animalSniffer = "1.18"
9999
val apiguardian = "1.1.0"
100100
val javaxAnnotation = "1.3.2"
101+
val klaxon = "5.4"
102+
val ouathJwt = "3.10.3"
103+
val bouncyCastlePkcs = "1.66"
104+
val assertK = "0.22"
101105

102106
/**
103107
* Version of the SLF4J library.
@@ -159,7 +163,7 @@ object Build {
159163

160164
object AutoService {
161165
val annotations = "com.google.auto.service:auto-service-annotations:${Versions.autoService}"
162-
val processor = "com.google.auto.service:auto-service:${Versions.autoService}"
166+
val processor = "com.google.auto.service:auto-service:${Versions.autoService}"
163167
}
164168
}
165169

@@ -168,6 +172,13 @@ object Gen {
168172
val javaxAnnotation = "javax.annotation:javax.annotation-api:${Versions.javaxAnnotation}"
169173
}
170174

175+
object Publishing {
176+
val klaxon = "com.beust:klaxon:${Versions.klaxon}"
177+
val oauthJwt = "com.auth0:java-jwt:${Versions.ouathJwt}"
178+
val bouncyCastlePkcs = "org.bouncycastle:bcpkix-jdk15on:${Versions.bouncyCastlePkcs}"
179+
val assertK = "com.willowtreeapps.assertk:assertk-jvm:${Versions.assertK}"
180+
}
181+
171182
object Grpc {
172183
val core = "io.grpc:grpc-core:${Versions.grpc}"
173184
val stub = "io.grpc:grpc-stub:${Versions.grpc}"
@@ -275,6 +286,7 @@ object Deps {
275286
val test = Test
276287
val versions = Versions
277288
val scripts = Scripts
289+
val publishing = Publishing
278290
}
279291

280292
object DependencyResolution {

gradle/wrapper/gradle-wrapper.jar

216 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

gradlew

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ esac
8282

8383
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
8484

85+
8586
# Determine the Java command to use to start the JVM.
8687
if [ -n "$JAVA_HOME" ] ; then
8788
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@@ -129,6 +130,7 @@ fi
129130
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
130131
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
131132
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133+
132134
JAVACMD=`cygpath --unix "$JAVACMD"`
133135

134136
# We build the pattern for arguments to be converted via cygpath

gradlew.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ set CMD_LINE_ARGS=%*
8484

8585
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
8686

87+
8788
@rem Execute Gradle
8889
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
8990

license-report.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

3-
# Dependencies of `io.spine:spine-client:1.5.27`
3+
# Dependencies of `io.spine:spine-client:1.5.28`
44

55
## Runtime
66
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -406,12 +406,12 @@
406406
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
407407

408408

409-
This report was generated on **Mon Aug 31 12:45:57 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
409+
This report was generated on **Tue Sep 01 23:59:03 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
410410

411411

412412

413413

414-
# Dependencies of `io.spine:spine-core:1.5.27`
414+
# Dependencies of `io.spine:spine-core:1.5.28`
415415

416416
## Runtime
417417
1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2
@@ -777,12 +777,12 @@ This report was generated on **Mon Aug 31 12:45:57 EEST 2020** using [Gradle-Lic
777777
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
778778

779779

780-
This report was generated on **Mon Aug 31 12:45:57 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
780+
This report was generated on **Tue Sep 01 23:59:03 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
781781

782782

783783

784784

785-
# Dependencies of `io.spine.tools:spine-model-assembler:1.5.27`
785+
# Dependencies of `io.spine.tools:spine-model-assembler:1.5.28`
786786

787787
## Runtime
788788
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -1183,12 +1183,12 @@ This report was generated on **Mon Aug 31 12:45:57 EEST 2020** using [Gradle-Lic
11831183
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
11841184

11851185

1186-
This report was generated on **Mon Aug 31 12:45:58 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
1186+
This report was generated on **Tue Sep 01 23:59:04 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
11871187

11881188

11891189

11901190

1191-
# Dependencies of `io.spine.tools:spine-model-verifier:1.5.27`
1191+
# Dependencies of `io.spine.tools:spine-model-verifier:1.5.28`
11921192

11931193
## Runtime
11941194
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -1659,12 +1659,12 @@ This report was generated on **Mon Aug 31 12:45:58 EEST 2020** using [Gradle-Lic
16591659
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
16601660

16611661

1662-
This report was generated on **Mon Aug 31 12:45:59 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
1662+
This report was generated on **Tue Sep 01 23:59:04 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
16631663

16641664

16651665

16661666

1667-
# Dependencies of `io.spine:spine-server:1.5.27`
1667+
# Dependencies of `io.spine:spine-server:1.5.28`
16681668

16691669
## Runtime
16701670
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -2082,12 +2082,12 @@ This report was generated on **Mon Aug 31 12:45:59 EEST 2020** using [Gradle-Lic
20822082
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
20832083

20842084

2085-
This report was generated on **Mon Aug 31 12:45:59 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
2085+
This report was generated on **Tue Sep 01 23:59:04 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
20862086

20872087

20882088

20892089

2090-
# Dependencies of `io.spine:spine-testutil-client:1.5.27`
2090+
# Dependencies of `io.spine:spine-testutil-client:1.5.28`
20912091

20922092
## Runtime
20932093
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -2542,12 +2542,12 @@ This report was generated on **Mon Aug 31 12:45:59 EEST 2020** using [Gradle-Lic
25422542
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
25432543

25442544

2545-
This report was generated on **Mon Aug 31 12:46:01 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
2545+
This report was generated on **Tue Sep 01 23:59:06 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
25462546

25472547

25482548

25492549

2550-
# Dependencies of `io.spine:spine-testutil-core:1.5.27`
2550+
# Dependencies of `io.spine:spine-testutil-core:1.5.28`
25512551

25522552
## Runtime
25532553
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -3010,12 +3010,12 @@ This report was generated on **Mon Aug 31 12:46:01 EEST 2020** using [Gradle-Lic
30103010
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
30113011

30123012

3013-
This report was generated on **Mon Aug 31 12:46:02 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
3013+
This report was generated on **Tue Sep 01 23:59:07 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
30143014

30153015

30163016

30173017

3018-
# Dependencies of `io.spine:spine-testutil-server:1.5.27`
3018+
# Dependencies of `io.spine:spine-testutil-server:1.5.28`
30193019

30203020
## Runtime
30213021
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -3514,4 +3514,4 @@ This report was generated on **Mon Aug 31 12:46:02 EEST 2020** using [Gradle-Lic
35143514
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
35153515

35163516

3517-
This report was generated on **Mon Aug 31 12:46:05 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
3517+
This report was generated on **Tue Sep 01 23:59:08 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ all modules and does not describe the project structure per-subproject.
1212

1313
<groupId>io.spine</groupId>
1414
<artifactId>spine-core-java</artifactId>
15-
<version>1.5.27</version>
15+
<version>1.5.28</version>
1616

1717
<inceptionYear>2015</inceptionYear>
1818

server/src/main/java/io/spine/server/tuple/Pair.java

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
package io.spine.server.tuple;
2222

23+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
2324
import com.google.protobuf.Message;
2425
import io.spine.server.tuple.Element.AValue;
2526
import io.spine.server.tuple.Element.BValue;
@@ -59,27 +60,50 @@ private Pair(A a, B b) {
5960
* Creates a new pair of values.
6061
*/
6162
public static <A extends Message, B extends Message> Pair<A, B> of(A a, B b) {
62-
Pair<A, B> result = new Pair<>(checkNotNullOrEmpty(Pair.class, a),
63-
checkNotNullOrEmpty(Pair.class, b));
63+
A safeA = checkNotNullOrEmpty(a);
64+
B safeB = checkNotNullOrEmpty(b);
65+
Pair<A, B> result = new Pair<>(safeA, safeB);
6466
return result;
6567
}
6668

6769
/**
6870
* Creates a pair with optionally present second value.
71+
*
72+
* @see #withOptional(Message, Optional)
6973
*/
7074
public static <A extends Message, B extends Message>
7175
Pair<A, Optional<B>> withNullable(A a, @Nullable B b) {
72-
checkNotNullOrEmpty(Pair.class, a);
73-
checkNotEmpty(Pair.class, b);
76+
checkNotNullOrEmpty(a);
77+
checkNotEmpty(b);
7478
Pair<A, Optional<B>> result = new Pair<>(a, ofNullable(b));
7579
return result;
7680
}
7781

82+
/**
83+
* Creates a pair with optionally present second value.
84+
*
85+
* @see #withNullable(Message, Message)
86+
* @apiNote This method treats a special case of construction using already available
87+
* instance of {@code Optional}. This avoids unwrapping of {@code Optional} which would
88+
* have been required for passing an optional value to
89+
* {@link #withNullable(Message, Message)}.
90+
*/
91+
public static <A extends Message, B extends Message>
92+
Pair<A, Optional<B>> withOptional(
93+
A a,
94+
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") /* see @apiNote */ Optional<B> b
95+
) {
96+
checkNotNullOrEmpty(a);
97+
checkNotNull(b);
98+
Pair<A, Optional<B>> result = new Pair<>(a, b);
99+
return result;
100+
}
101+
78102
/**
79103
* Creates a pair with the second element of a type descending from {@link Either}.
80104
*/
81105
public static <A extends Message, B extends Either> Pair<A, B> withEither(A a, B b) {
82-
checkNotNullOrEmpty(Pair.class, a);
106+
checkNotNullOrEmpty(a);
83107
checkNotNull(b);
84108
Pair<A, B> result = new Pair<>(a, b);
85109
return result;
@@ -94,4 +118,14 @@ public A getA() {
94118
public B getB() {
95119
return value(this, 1);
96120
}
121+
122+
@CanIgnoreReturnValue
123+
private static <M extends Message> M checkNotNullOrEmpty(M value) {
124+
return checkNotNullOrEmpty(Pair.class, value);
125+
}
126+
127+
@CanIgnoreReturnValue
128+
private static <M extends Message> @Nullable M checkNotEmpty(@Nullable M value) {
129+
return checkNotEmpty(Pair.class, value);
130+
}
97131
}

server/src/main/java/io/spine/server/tuple/Quartet.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
package io.spine.server.tuple;
2222

23+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
2324
import com.google.protobuf.Message;
2425
import io.spine.server.tuple.Element.AValue;
2526
import io.spine.server.tuple.Element.BValue;
@@ -65,7 +66,7 @@ private Quartet(A a, B b, C c, D d) {
6566
*/
6667
public static <A extends Message, B extends Message, C extends Message, D extends Message>
6768
Quartet<A, B, C, D> of(A a, B b, C c, D d) {
68-
checkAllNotNullOrEmpty(Quartet.class, a, b, c, d);
69+
checkAllNotNullOrEmpty(a, b, c, d);
6970
Quartet<A, B, C, D> result = new Quartet<>(a, b, c, d);
7071
return result;
7172
}
@@ -75,8 +76,8 @@ Quartet<A, B, C, D> of(A a, B b, C c, D d) {
7576
*/
7677
public static <A extends Message, B extends Message, C extends Message, D extends Message>
7778
Quartet<A, B, C, Optional<D>> withNullable(A a, B b, C c, @Nullable D d) {
78-
checkAllNotNullOrEmpty(Quartet.class, a, b, c);
79-
checkNotEmpty(Quartet.class, d);
79+
checkAllNotNullOrEmpty(a, b, c);
80+
checkNotEmpty(d);
8081
Quartet<A, B, C, Optional<D>> result = new Quartet<>(a, b, c, ofNullable(d));
8182
return result;
8283
}
@@ -86,8 +87,8 @@ Quartet<A, B, C, Optional<D>> withNullable(A a, B b, C c, @Nullable D d) {
8687
*/
8788
public static <A extends Message, B extends Message, C extends Message, D extends Message>
8889
Quartet<A, B, Optional<C>, Optional<D>> withNullable2(A a, B b, @Nullable C c, @Nullable D d) {
89-
checkAllNotNullOrEmpty(Quartet.class, a, b);
90-
checkAllNotEmpty(Quartet.class, c, d);
90+
checkAllNotNullOrEmpty(a, b);
91+
checkAllNotEmpty(c, d);
9192
Quartet<A, B, Optional<C>, Optional<D>> result =
9293
new Quartet<>(a, b, ofNullable(c), ofNullable(d));
9394
return result;
@@ -99,8 +100,8 @@ Quartet<A, B, Optional<C>, Optional<D>> withNullable2(A a, B b, @Nullable C c, @
99100
public static <A extends Message, B extends Message, C extends Message, D extends Message>
100101
Quartet<A, Optional<B>, Optional<C>, Optional<D>>
101102
withNullable3(A a, @Nullable B b, @Nullable C c, @Nullable D d) {
102-
checkNotNullOrEmpty(Quartet.class, a);
103-
checkAllNotEmpty(Quartet.class, b, c, d);
103+
checkNotNullOrEmpty(a);
104+
checkAllNotEmpty(b, c, d);
104105
Quartet<A, Optional<B>, Optional<C>, Optional<D>> result =
105106
new Quartet<>(a, ofNullable(b), ofNullable(c), ofNullable(d));
106107
return result;
@@ -125,4 +126,24 @@ public C getC() {
125126
public D getD() {
126127
return value(this, 3);
127128
}
129+
130+
@CanIgnoreReturnValue
131+
private static <M extends Message> M checkNotNullOrEmpty(M value) {
132+
return checkNotNullOrEmpty(Quartet.class, value);
133+
}
134+
135+
@CanIgnoreReturnValue
136+
private static <M extends Message> @Nullable M checkNotEmpty(@Nullable M value) {
137+
return checkNotEmpty(Quartet.class, value);
138+
}
139+
140+
@SuppressWarnings("OverloadedVarargsMethod") // to avoid repeated usage of this class name.
141+
private static void checkAllNotNullOrEmpty(Message... values) {
142+
checkAllNotNullOrEmpty(Quartet.class, values);
143+
}
144+
145+
@SuppressWarnings("OverloadedVarargsMethod") // to avoid repeated usage of this class name.
146+
private static void checkAllNotEmpty(Message... values) {
147+
checkAllNotEmpty(Quartet.class, values);
148+
}
128149
}

0 commit comments

Comments
 (0)