Skip to content

Commit

Permalink
Merge pull request #1542 from SpineEventEngine/relax-policy-whenever-…
Browse files Browse the repository at this point in the history
…back

Make `whenever()` return `Iterable<Message>` again
  • Loading branch information
alexander-yevsyukov authored Nov 3, 2023
2 parents 3b74ac8 + 3109413 commit 4a61ccc
Show file tree
Hide file tree
Showing 15 changed files with 258 additions and 88 deletions.
24 changes: 12 additions & 12 deletions license-report.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


# Dependencies of `io.spine:spine-client:2.0.0-SNAPSHOT.170`
# Dependencies of `io.spine:spine-client:2.0.0-SNAPSHOT.171`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -798,12 +798,12 @@

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Wed Nov 01 15:46:08 WET 2023** 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).
This report was generated on **Fri Nov 03 00:38:26 WET 2023** 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).




# Dependencies of `io.spine:spine-core:2.0.0-SNAPSHOT.170`
# Dependencies of `io.spine:spine-core:2.0.0-SNAPSHOT.171`

## Runtime
1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2.
Expand Down Expand Up @@ -1561,12 +1561,12 @@ This report was generated on **Wed Nov 01 15:46:08 WET 2023** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Wed Nov 01 15:46:08 WET 2023** 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).
This report was generated on **Fri Nov 03 00:38:27 WET 2023** 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).




# Dependencies of `io.spine:spine-server:2.0.0-SNAPSHOT.170`
# Dependencies of `io.spine:spine-server:2.0.0-SNAPSHOT.171`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -2372,12 +2372,12 @@ This report was generated on **Wed Nov 01 15:46:08 WET 2023** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Wed Nov 01 15:46:09 WET 2023** 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).
This report was generated on **Fri Nov 03 00:38:27 WET 2023** 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).




# Dependencies of `io.spine.tools:spine-testutil-client:2.0.0-SNAPSHOT.170`
# Dependencies of `io.spine.tools:spine-testutil-client:2.0.0-SNAPSHOT.171`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -3303,12 +3303,12 @@ This report was generated on **Wed Nov 01 15:46:09 WET 2023** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Wed Nov 01 15:46:09 WET 2023** 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).
This report was generated on **Fri Nov 03 00:38:28 WET 2023** 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).




# Dependencies of `io.spine.tools:spine-testutil-core:2.0.0-SNAPSHOT.170`
# Dependencies of `io.spine.tools:spine-testutil-core:2.0.0-SNAPSHOT.171`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -4234,12 +4234,12 @@ This report was generated on **Wed Nov 01 15:46:09 WET 2023** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Wed Nov 01 15:46:10 WET 2023** 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).
This report was generated on **Fri Nov 03 00:38:28 WET 2023** 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).




# Dependencies of `io.spine.tools:spine-testutil-server:2.0.0-SNAPSHOT.170`
# Dependencies of `io.spine.tools:spine-testutil-server:2.0.0-SNAPSHOT.171`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -5213,4 +5213,4 @@ This report was generated on **Wed Nov 01 15:46:10 WET 2023** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Wed Nov 01 15:46:10 WET 2023** 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).
This report was generated on **Fri Nov 03 00:38:29 WET 2023** 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).
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ all modules and does not describe the project structure per-subproject.
-->
<groupId>io.spine</groupId>
<artifactId>spine-core-java</artifactId>
<version>2.0.0-SNAPSHOT.170</version>
<version>2.0.0-SNAPSHOT.171</version>

<inceptionYear>2015</inceptionYear>

Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/io/spine/server/tuple/Either.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public abstract class Either implements Iterable<Message>, Serializable {
protected Either(Message value, int index) {
/* We need instances of GeneratedMessageV3 as they are Serializable.
The only known case of message class which does not descend from
GeneratedMessageV3 is DynamicMessage, and Spine does not support it. */
GeneratedMessageV3 is DynamicMessage, and Spine SDK does not support it. */
this.value = (GeneratedMessageV3) checkNotNull(value);
checkArgument(index >= 0, "Index must be greater or equal zero");
this.index = index;
Expand Down
11 changes: 8 additions & 3 deletions server/src/main/java/io/spine/server/tuple/Element.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022, TeamDev. All rights reserved.
* Copyright 2023, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,6 +30,7 @@
import com.google.protobuf.GeneratedMessageV3;
import com.google.protobuf.Message;
import io.spine.base.EventMessage;
import io.spine.server.model.Nothing;

import java.io.IOException;
import java.io.ObjectInputStream;
Expand Down Expand Up @@ -67,7 +68,11 @@ final class Element implements Serializable {
this.type = Type.OPTIONAL;
} else if (value instanceof GeneratedMessageV3) {
var messageV3 = (GeneratedMessageV3) value;
checkNotDefault(messageV3);
// Treat `Nothing` as a special case, allowing its default instance
// so that `Just<Nothing>` is possible.
if (!(value instanceof Nothing)) {
checkNotDefault(messageV3);
}
this.type = Type.MESSAGE;
} else {
throw newIllegalArgumentException(
Expand All @@ -82,7 +87,7 @@ final class Element implements Serializable {
* Obtains the value of the element by its index and casts it to the type {@code <T>}.
*/
@SuppressWarnings("TypeParameterUnusedInFormals") // See Javadoc.
static <T> T value(Tuple tuple, IndexOf index) {
static <M extends Message, T> T value(Tuple tuple, IndexOf index) {
@SuppressWarnings("unchecked") // The caller is responsible for the correct type.
var value = (T) tuple.get(index.value());
return value;
Expand Down
3 changes: 1 addition & 2 deletions server/src/main/java/io/spine/server/tuple/Pair.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022, TeamDev. All rights reserved.
* Copyright 2023, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,7 +36,6 @@

import static com.google.common.base.Preconditions.checkNotNull;
import static io.spine.server.tuple.Element.value;
import static io.spine.server.tuple.Values.isOptionalPresent;
import static java.util.Optional.ofNullable;

/**
Expand Down
11 changes: 5 additions & 6 deletions server/src/main/java/io/spine/server/tuple/Quartet.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022, TeamDev. All rights reserved.
* Copyright 2023, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,7 +37,6 @@
import java.util.Optional;

import static io.spine.server.tuple.Element.value;
import static io.spine.server.tuple.Values.isOptionalPresent;
import static java.util.Optional.ofNullable;

/**
Expand Down Expand Up @@ -170,13 +169,13 @@ private static <M extends Message> M checkNotNullOrEmpty(M value) {
return checkNotEmpty(Quartet.class, value);
}

@SuppressWarnings("OverloadedVarargsMethod") // to avoid repeated usage of this class name.
private static void checkAllNotNullOrEmpty(Message... values) {
@SafeVarargs
private static <M extends Message> void checkAllNotNullOrEmpty(M... values) {
checkAllNotNullOrEmpty(Quartet.class, values);
}

@SuppressWarnings("OverloadedVarargsMethod") // to avoid repeated usage of this class name.
private static void checkAllNotEmpty(Message... values) {
@SafeVarargs
private static <M extends Message> void checkAllNotEmpty(M... values) {
checkAllNotEmpty(Quartet.class, values);
}
}
15 changes: 7 additions & 8 deletions server/src/main/java/io/spine/server/tuple/Quintet.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022, TeamDev. All rights reserved.
* Copyright 2023, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,7 +38,6 @@
import java.util.Optional;

import static io.spine.server.tuple.Element.value;
import static io.spine.server.tuple.Values.isOptionalPresent;
import static java.util.Optional.ofNullable;

/**
Expand All @@ -62,8 +61,8 @@
* the type of the fifth element
*/
public final class Quintet<A extends Message, B, C, D, E>
extends Tuple
implements AValue<A>, BValue<B>, CValue<C>, DValue<D>, EValue<E> {
extends Tuple
implements AValue<A>, BValue<B>, CValue<C>, DValue<D>, EValue<E> {

private static final long serialVersionUID = 0L;

Expand Down Expand Up @@ -203,13 +202,13 @@ private static <M extends Message> M checkNotNullOrEmpty(M value) {
return checkNotEmpty(Quintet.class, value);
}

@SuppressWarnings("OverloadedVarargsMethod") // to avoid repeated usage of this class name.
private static void checkAllNotNullOrEmpty(Message... values) {
@SafeVarargs
private static <M extends Message> void checkAllNotNullOrEmpty(M... values) {
checkAllNotNullOrEmpty(Quintet.class, values);
}

@SuppressWarnings("OverloadedVarargsMethod") // to avoid repeated usage of this class name.
private static void checkAllNotEmpty(Message... values) {
@SafeVarargs
private static <M extends Message> void checkAllNotEmpty(M... values) {
checkAllNotEmpty(Quintet.class, values);
}
}
11 changes: 5 additions & 6 deletions server/src/main/java/io/spine/server/tuple/Triplet.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022, TeamDev. All rights reserved.
* Copyright 2023, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,7 +36,6 @@
import java.util.Optional;

import static io.spine.server.tuple.Element.value;
import static io.spine.server.tuple.Values.isOptionalPresent;
import static java.util.Optional.ofNullable;

/**
Expand Down Expand Up @@ -144,13 +143,13 @@ private static <M extends Message> M checkNotNullOrEmpty(M value) {
return checkNotEmpty(Triplet.class, value);
}

@SuppressWarnings("OverloadedVarargsMethod") // to avoid repeated usage of this class name.
private static void checkAllNotNullOrEmpty(Message... values) {
@SafeVarargs
private static <M extends Message> void checkAllNotNullOrEmpty(M... values) {
checkAllNotNullOrEmpty(Triplet.class, values);
}

@SuppressWarnings("OverloadedVarargsMethod") // to avoid repeated usage of this class name.
private static void checkAllNotEmpty(Message... values) {
@SafeVarargs
private static <M extends Message> void checkAllNotEmpty(M... values) {
checkAllNotEmpty(Triplet.class, values);
}
}
26 changes: 21 additions & 5 deletions server/src/main/java/io/spine/server/tuple/Tuple.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022, TeamDev. All rights reserved.
* Copyright 2023, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -107,15 +107,17 @@ M checkNotNullOrEmpty(Class<T> checkingClass, M value) {
return result;
}

static <T extends Tuple>
void checkAllNotNullOrEmpty(Class<T> checkingClass, Message... values) {
@SafeVarargs
static <M extends Message, T extends Tuple>
void checkAllNotNullOrEmpty(Class<T> checkingClass, M... values) {
for (var value : values) {
checkNotNullOrEmpty(checkingClass, value);
}
}

static <T extends Tuple>
void checkAllNotEmpty(Class<T> checkingClass, Message... values) {
@SafeVarargs
static <M extends Message, T extends Tuple>
void checkAllNotEmpty(Class<T> checkingClass, M... values) {
for (var value : values) {
checkNotEmpty(checkingClass, value);
}
Expand Down Expand Up @@ -157,6 +159,20 @@ public final boolean equals(Object obj) {
return Objects.equals(this.values, other.values);
}

/**
* If the passed {@code value} is an {@code Optional}, tells if its value is present.
*
* <p>Otherwise, returns {@code true}.
*/
static boolean isOptionalPresent(Object value) {
checkNotNull(value);
if(!(value instanceof Optional)) {
return true;
}
var asOptional = (Optional<?>) value;
return asOptional.isPresent();
}

/**
* Traverses through elements obtaining a message value from them.
*/
Expand Down
22 changes: 20 additions & 2 deletions server/src/main/kotlin/io/spine/server/event/Just.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022, TeamDev. All rights reserved.
* Copyright 2023, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,21 +27,31 @@
package io.spine.server.event

import io.spine.base.EventMessage
import io.spine.server.model.Nothing
import io.spine.server.tuple.Tuple

/**
* A tuple of one event.
*
* Used when returning an iterable from a handler method for better readability over `List<E>`.
* Used when returning an `Iterable` from a handler method for better readability over
* `Iterable<E>` or `List<E>`.
*
* @param E the type of the event.
*/
public class Just<E : EventMessage>(event: E) : Tuple(event) {

public companion object {

@Suppress("ConstPropertyName") // Following Java conventions.
private const val serialVersionUID: Long = 0L

/**
* The instance of `Just<Nothing>`.
*/
public val nothing: Just<Nothing> by lazy {
Just(Nothing.getDefaultInstance())
}

/**
* A factory method for Java.
*
Expand All @@ -51,5 +61,13 @@ public class Just<E : EventMessage>(event: E) : Tuple(event) {
*/
@JvmStatic
public fun <E : EventMessage> just(event: E): Just<E> = Just(event)

/**
* Obtains the instance of `Just<Noting>` for Java code.
*
* Prefer the [nothing] property of the companion object in Kotlin.
*/
@JvmStatic
public fun nothing(): Just<Nothing> = nothing
}
}
Loading

0 comments on commit 4a61ccc

Please sign in to comment.