it.auties.protobuf.builtin.ProtobufFutureMixin Maven / Gradle / Ivy
The newest version!
package it.auties.protobuf.builtin;
import it.auties.protobuf.annotation.ProtobufDefaultValue;
import it.auties.protobuf.annotation.ProtobufDeserializer;
import it.auties.protobuf.annotation.ProtobufMixin;
import it.auties.protobuf.annotation.ProtobufSerializer;
import java.util.concurrent.CompletableFuture;
import static it.auties.protobuf.annotation.ProtobufDeserializer.BuilderBehaviour.OVERRIDE;
@SuppressWarnings("unused")
@ProtobufMixin
public class ProtobufFutureMixin {
@ProtobufDefaultValue
public static CompletableFuture newCompletableFuture() {
return CompletableFuture.completedFuture(null);
}
@ProtobufDeserializer(builderBehaviour = OVERRIDE)
public static CompletableFuture ofNullable(T value) {
return CompletableFuture.completedFuture(value);
}
@ProtobufSerializer
public static T toValue(CompletableFuture future) {
return future == null ? null : future.getNow(null);
}
}