Skip to content

Commit

Permalink
Remove Tuple generic parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-yevsyukov committed Nov 3, 2023
1 parent 790e87b commit 3109413
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 26 deletions.
2 changes: 1 addition & 1 deletion server/src/main/java/io/spine/server/tuple/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,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 <M extends Message, T> T value(Tuple<M> 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
2 changes: 1 addition & 1 deletion server/src/main/java/io/spine/server/tuple/Pair.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
* the type of the second element
*/
public final class Pair<A extends Message, B>
extends Tuple<A>
extends Tuple
implements AValue<A>, BValue<B> {

private static final long serialVersionUID = 0L;
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/io/spine/server/tuple/Quartet.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
* the type of the fourth element
*/
public final class Quartet<A extends Message, B, C, D>
extends Tuple<A>
extends Tuple
implements AValue<A>, BValue<B>, CValue<C>, DValue<D> {

private static final long serialVersionUID = 0L;
Expand Down
4 changes: 2 additions & 2 deletions server/src/main/java/io/spine/server/tuple/Quintet.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
* the type of the fifth element
*/
public final class Quintet<A extends Message, B, C, D, E>
extends Tuple<A>
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
2 changes: 1 addition & 1 deletion server/src/main/java/io/spine/server/tuple/Triplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
* the type of the third element
*/
public final class Triplet<A extends Message, B, C>
extends Tuple<A>
extends Tuple
implements AValue<A>, BValue<B>, CValue<C> {

private static final long serialVersionUID = 0L;
Expand Down
30 changes: 11 additions & 19 deletions server/src/main/java/io/spine/server/tuple/Tuple.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,8 @@

/**
* Abstract base for tuple classes.
*
* @param <M>
* the type of the tuple first element
*/
public abstract class Tuple<M extends Message> implements Iterable<M>, Serializable {
public abstract class Tuple implements Iterable<Message>, Serializable {

private static final long serialVersionUID = 0L;

Expand Down Expand Up @@ -86,7 +83,7 @@ protected Tuple(Object... values) {
* @throws IllegalArgumentException if the passed value is {@link Empty}
*/
@CanIgnoreReturnValue
static <M extends Message, T extends Tuple<?>>
static <M extends Message, T extends Tuple>
@Nullable M checkNotEmpty(Class<T> checkingClass, @Nullable M value) {
if (value == null) {
return null;
Expand All @@ -103,32 +100,32 @@ protected Tuple(Object... values) {

@CanIgnoreReturnValue
@SuppressWarnings("ConstantConditions") /* `checkNotNull` is used by design. */
static <M extends Message, T extends Tuple<?>>
static <M extends Message, T extends Tuple>
M checkNotNullOrEmpty(Class<T> checkingClass, M value) {
var result = checkNotEmpty(checkingClass, value);
checkNotNull(result);
return result;
}

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

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

@Override
public final @NonNull Iterator<M> iterator() {
Iterator<M> result = new ExtractingIterator<>(values);
public final @NonNull Iterator<Message> iterator() {
Iterator<Message> result = new ExtractingIterator(values);
return result;
}

Expand Down Expand Up @@ -158,7 +155,7 @@ public final boolean equals(Object obj) {
if (!(obj instanceof Tuple)) {
return false;
}
var other = (Tuple<?>) obj;
var other = (Tuple) obj;
return Objects.equals(this.values, other.values);
}

Expand All @@ -178,12 +175,8 @@ static boolean isOptionalPresent(Object value) {

/**
* Traverses through elements obtaining a message value from them.
*
* @param <M>
* the type of the messages extracted by the iterator
*/
private static final class ExtractingIterator<M extends Message>
extends UnmodifiableIterator<M> {
private static final class ExtractingIterator extends UnmodifiableIterator<Message> {

private final Iterator<Element> source;

Expand All @@ -198,10 +191,9 @@ public boolean hasNext() {
}

@Override
public M next() {
public Message next() {
var next = source.next();
@SuppressWarnings("unchecked")
var result = (M) next.toMessage();
var result = next.toMessage();
return result;
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/kotlin/io/spine/server/event/Just.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import io.spine.server.tuple.Tuple
*
* @param E the type of the event.
*/
public class Just<E : EventMessage>(event: E) : Tuple<E>(event) {
public class Just<E : EventMessage>(event: E) : Tuple(event) {

public companion object {

Expand Down

0 comments on commit 3109413

Please sign in to comment.