Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
junit = "5.10.0"

[libraries]
jspecify-annotations = { group = "org.jspecify", name = "jspecify", version = "1.0.0" }
junit-jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit" }
junit-jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit" }
junit-jupiter-params = { group = "org.junit.jupiter", name = "junit-jupiter-params", version.ref = "junit" }
2 changes: 2 additions & 0 deletions helios/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ plugins {
}

dependencies {
compileOnly(libs.jspecify.annotations)

testImplementation(libs.junit.jupiter.api)
testImplementation(libs.junit.jupiter.params)
testRuntimeOnly(libs.junit.jupiter.engine)
Expand Down
8 changes: 4 additions & 4 deletions helios/src/main/java/me/sparky983/helios/Absent.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import me.sparky983.helios.annotations.Nullable;
import org.jspecify.annotations.Nullable;

/**
* An {@code Optional} that contains no value.
Expand All @@ -14,7 +14,7 @@
* @since 0.1.0
* @helios.apiNote This class should not be constructed directly. Use {@link #absent()} instead.
*/
public record Absent<T extends Object>() implements Optional<T> {
public record Absent<T>() implements Optional<T> {
static final Absent<?> ABSENT = new Absent<>();

@Override
Expand Down Expand Up @@ -85,14 +85,14 @@ public T expect(final String message) {
}

@Override
public <M extends Object> Optional<M> map(final Function<? super T, ? extends M> mapper) {
public <M> Optional<M> map(final Function<? super T, ? extends M> mapper) {
Objects.requireNonNull(mapper, "mapper cannot be null");

return Optional.absent();
}

@Override
public <M extends Object> Optional<M> flatMap(
public <M> Optional<M> flatMap(
final Function<? super T, ? extends Optional<? extends M>> mapper) {
Objects.requireNonNull(mapper, "mapper cannot be null");

Expand Down
17 changes: 8 additions & 9 deletions helios/src/main/java/me/sparky983/helios/Optional.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.function.Predicate;
import java.util.function.Supplier;
import me.sparky983.helios.annotations.Experimental;
import me.sparky983.helios.annotations.Nullable;
import org.jspecify.annotations.Nullable;

/**
* An immutable container which may contain a non-null value.
Expand Down Expand Up @@ -231,7 +231,7 @@
* }
* }
*/
public sealed interface Optional<T extends Object> permits Present, Absent {
public sealed interface Optional<T> permits Present, Absent {
/**
* Returns a present {@code Optional} containing the given value.
*
Expand All @@ -240,7 +240,7 @@ public sealed interface Optional<T extends Object> permits Present, Absent {
* @param <T> the type of the value
* @throws NullPointerException if the value is {@code null}.
*/
static <T extends Object> Optional<T> present(final T value) {
static <T> Optional<T> present(final T value) {
return new Present<>(value);
}

Expand All @@ -254,7 +254,7 @@ static <T extends Object> Optional<T> present(final T value) {
* @helios.implNote This method returns a singleton instance of {@link Absent}.
*/
@SuppressWarnings("unchecked")
static <T extends Object> Optional<T> absent() {
static <T> Optional<T> absent() {
return (Absent<T>) Absent.ABSENT;
}

Expand All @@ -275,7 +275,7 @@ static <T extends Object> Optional<T> absent() {
* Optional<String> optional = Optional.fromNullable(map.get("key"));
* }
*/
static <T extends Object> Optional<T> fromNullable(final @Nullable T value) {
static <T> Optional<T> fromNullable(final @Nullable T value) {
if (value != null) {
return present(value);
} else {
Expand Down Expand Up @@ -303,7 +303,7 @@ static <T extends Object> Optional<T> fromNullable(final @Nullable T value) {
* }
*/
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
static <T extends Object> Optional<T> from(final java.util.Optional<T> optional) {
static <T> Optional<T> from(final java.util.Optional<T> optional) {
return optional.map(Optional::present).orElse(Optional.absent());
}

Expand Down Expand Up @@ -485,7 +485,7 @@ static <T extends Object> Optional<T> from(final java.util.Optional<T> optional)
* assert absent.map(n -> n * 2).isAbsent();
* }
*/
<M extends Object> Optional<M> map(Function<? super T, ? extends M> mapper);
<M> Optional<M> map(Function<? super T, ? extends M> mapper);

/**
* If this {@code Optional} is present, returns the result of applying the given mapper to the
Expand All @@ -508,8 +508,7 @@ static <T extends Object> Optional<T> from(final java.util.Optional<T> optional)
* .flatMap(user -> user.findRepository("helios"));
* }
*/
<M extends Object> Optional<M> flatMap(
Function<? super T, ? extends Optional<? extends M>> mapper);
<M> Optional<M> flatMap(Function<? super T, ? extends Optional<? extends M>> mapper);

/**
* If this {@code Optional} is present and the value matches the given predicate, returns this
Expand Down
6 changes: 3 additions & 3 deletions helios/src/main/java/me/sparky983/helios/Present.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @helios.apiNote This class should not be constructed directly and is only public for pattern
* matching. Use {@link #present(Object)} instead.
*/
public record Present<T extends Object>(T value) implements Optional<T> {
public record Present<T>(T value) implements Optional<T> {
/**
* Constructs a new {@code Present} {@code Optional} with the given value.
*
Expand Down Expand Up @@ -83,7 +83,7 @@ public T expect(final String message) {
}

@Override
public <M extends Object> Optional<M> map(final Function<? super T, ? extends M> mapper) {
public <M> Optional<M> map(final Function<? super T, ? extends M> mapper) {
Objects.requireNonNull(mapper, "mapper cannot be null");

final var mappedValue =
Expand All @@ -94,7 +94,7 @@ public <M extends Object> Optional<M> map(final Function<? super T, ? extends M>

@SuppressWarnings("unchecked")
@Override
public <M extends Object> Optional<M> flatMap(
public <M> Optional<M> flatMap(
final Function<? super T, ? extends Optional<? extends M>> mapper) {
Objects.requireNonNull(mapper, "mapper cannot be null");

Expand Down
23 changes: 0 additions & 23 deletions helios/src/main/java/me/sparky983/helios/annotations/Nullable.java

This file was deleted.

1 change: 1 addition & 0 deletions helios/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@Experimental // 0.x.y
module me.sparky983.helios {
requires static java.compiler; // for Javadocs
requires static org.jspecify;

exports me.sparky983.helios;
}