Skip to content
Merged
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
8 changes: 4 additions & 4 deletions tasks-jvm/src/main/java/org/funfix/tasks/jvm/Cancellable.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void complete() {
}
}

public @Nullable Cancellable register(Cancellable token) {
public @Nullable Cancellable register(final Cancellable token) {
Objects.requireNonNull(token, "token");
while (true) {
final var current = ref.get();
Expand Down Expand Up @@ -214,7 +214,7 @@ private void unregister(final long order) {
}
}

private static void invoke(Cancellable token) {
private static void invoke(final Cancellable token) {
try {
token.cancel();
} catch (Throwable e) {
Expand All @@ -228,7 +228,7 @@ record Active(
long order,
@Nullable Active rest
) implements State {
Active register(Cancellable token) {
Active register(final Cancellable token) {
final var newOrder = order + 1;
return new State.Active(token, newOrder, this);
}
Expand All @@ -237,7 +237,7 @@ Active register(Cancellable token) {
record Cancelling(
@Nullable Active toCancel
) implements State {
Cancelling register(Cancellable token) {
Cancelling register(final Cancellable token) {
final var newOrder = toCancel != null ? toCancel.order + 1 : 1;
return new State.Cancelling(
new State.Active(token, newOrder, toCancel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public record CancellableFuture<T extends @Nullable Object>(
Cancellable cancellable
) {
public <U extends @Nullable Object> CancellableFuture<U> transform(
Function<? super CompletableFuture<? extends T>, ? extends CompletableFuture<? extends U>> fn
final Function<? super CompletableFuture<? extends T>, ? extends CompletableFuture<? extends U>> fn
) {
return new CancellableFuture<>(fn.apply(future), cancellable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ default void close() throws Exception {
close(ExitCase.succeeded());
}

static CloseableFun fromAutoCloseable(AutoCloseable resource) {
static CloseableFun fromAutoCloseable(final AutoCloseable resource) {
return ignored -> resource.close();
}

Expand Down
18 changes: 9 additions & 9 deletions tasks-jvm/src/main/java/org/funfix/tasks/jvm/Collections.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
sealed abstract class ImmutableStack<T extends @Nullable Object> implements Iterable<T>
permits ImmutableStack.Cons, ImmutableStack.Nil {

final ImmutableStack<T> prepend(T value) {
final ImmutableStack<T> prepend(final T value) {
return new Cons<>(value, this);
}

final ImmutableStack<T> prependAll(Iterable<? extends T> values) {
final ImmutableStack<T> prependAll(final Iterable<? extends T> values) {
ImmutableStack<T> result = this;
for (T t : values) {
result = result.prepend(t);
Expand Down Expand Up @@ -56,13 +56,13 @@ static final class Cons<T extends @Nullable Object> extends ImmutableStack<T> {
final T head;
final ImmutableStack<T> tail;

Cons(T head, ImmutableStack<T> tail) {
Cons(final T head, final ImmutableStack<T> tail) {
this.head = head;
this.tail = tail;
}

@Override
public boolean equals(Object o) {
public boolean equals(final Object o) {
if (!(o instanceof Cons<?> cons)) return false;
return Objects.equals(head, cons.head) && Objects.equals(tail, cons.tail);
}
Expand All @@ -82,7 +82,7 @@ public int hashCode() {
}

@Override
public boolean equals(Object obj) {
public boolean equals(final Object obj) {
return obj instanceof Nil<?>;
}
}
Expand Down Expand Up @@ -137,12 +137,12 @@ final class ImmutableQueue<T extends @Nullable Object> implements Iterable<T> {
private final ImmutableStack<T> toEnqueue;
private final ImmutableStack<T> toDequeue;

private ImmutableQueue(ImmutableStack<T> toEnqueue, ImmutableStack<T> toDequeue) {
private ImmutableQueue(final ImmutableStack<T> toEnqueue, final ImmutableStack<T> toDequeue) {
this.toEnqueue = toEnqueue;
this.toDequeue = toDequeue;
}

ImmutableQueue<T> enqueue(T value) {
ImmutableQueue<T> enqueue(final T value) {
return new ImmutableQueue<>(toEnqueue.prepend(value), toDequeue);
}

Expand Down Expand Up @@ -184,7 +184,7 @@ boolean isEmpty() {
return toEnqueue.isEmpty() && toDequeue.isEmpty();
}

ImmutableQueue<T> filter(Predicate<? super T> predicate) {
ImmutableQueue<T> filter(final Predicate<? super T> predicate) {
ImmutableQueue<T> result = empty();
for (T t : this) {
if (predicate.test(t)) {
Expand Down Expand Up @@ -236,7 +236,7 @@ public String toString() {
}

@Override
public boolean equals(Object obj) {
public boolean equals(final Object obj) {
if (obj instanceof ImmutableQueue<?> that) {
return toList().equals(that.toList());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public interface CompletionCallback<
*
* @param value is the successful result of the task, to be signaled
*/
default void onSuccess(T value) {
default void onSuccess(final T value) {
onOutcome(Outcome.success(value));
}

Expand All @@ -44,7 +44,7 @@ default void onSuccess(T value) {
*
* @param e is the exception that the task failed with
*/
default void onFailure(Throwable e) {
default void onFailure(final Throwable e) {
onOutcome(Outcome.failure(e));
}

Expand Down Expand Up @@ -93,37 +93,37 @@ private ManyCompletionCallback(
}

ManyCompletionCallback<T> withExtraListener(
CompletionCallback<T> extraListener
final CompletionCallback<T> extraListener
) {
Objects.requireNonNull(extraListener, "extraListener");
final var newListeners = this.listeners.prepend(extraListener);
return new ManyCompletionCallback<>(newListeners);
}

@Override
public void onOutcome(Outcome<? extends T> outcome) {
public void onOutcome(final Outcome<? extends T> outcome) {
for (final CompletionCallback<T> listener : listeners) {
try {
listener.onOutcome(outcome);
} catch (Throwable e) {
} catch (final Throwable e) {
UncaughtExceptionHandler.logOrRethrow(e);
}
}
}

@Override
public void onSuccess(T value) {
public void onSuccess(final T value) {
for (final CompletionCallback<T> listener : listeners) {
try {
listener.onSuccess(value);
} catch (Throwable e) {
} catch (final Throwable e) {
UncaughtExceptionHandler.logOrRethrow(e);
}
}
}

@Override
public void onFailure(Throwable e) {
public void onFailure(final Throwable e) {
Objects.requireNonNull(e, "e");
for (final CompletionCallback<T> listener : listeners) {
try {
Expand Down Expand Up @@ -249,7 +249,7 @@ public void onCancellation() {

// NullAway treats AtomicReference.get() as nullable between the read and compare-and-set.
@SuppressWarnings("NullAway")
public void registerExtraCallback(CompletionCallback<T> extraCallback) {
public void registerExtraCallback(final CompletionCallback<T> extraCallback) {
while (true) {
final var current = listenerRef.get();
if (current instanceof ManyCompletionCallback<T> many) {
Expand Down Expand Up @@ -338,7 +338,7 @@ public void onCancellation() {
}

@Override
public void onOutcome(Outcome<? extends T> outcome) {
public void onOutcome(final Outcome<? extends T> outcome) {
if (outcome instanceof Outcome.Success<? extends T> success) {
onSuccess(success.value());
} else if (outcome instanceof Outcome.Failure<?> failure) {
Expand All @@ -361,7 +361,7 @@ protected boolean tryReleaseShared(final int arg) {

@FunctionalInterface
interface AwaitFunction {
void apply(boolean isCancelled)
void apply(final boolean isCancelled)
throws InterruptedException, TimeoutException;
}

Expand Down Expand Up @@ -427,7 +427,7 @@ public T await(final Cancellable cancelToken, final Duration timeout)
}

@Override
public void registerExtraCallback(CompletionCallback<T> extraCallback) {
public void registerExtraCallback(final CompletionCallback<T> extraCallback) {
while (true) {
final var current = extraCallbackRef.get();
if (current == null) {
Expand Down
12 changes: 6 additions & 6 deletions tasks-jvm/src/main/java/org/funfix/tasks/jvm/Continuation.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,24 @@ public void cancel() {
}

@Override
public @Nullable Cancellable invokeOnCancellation(Cancellable finalizer) {
public @Nullable Cancellable invokeOnCancellation(final Cancellable finalizer) {
return cancellableRef.register(finalizer);
}

@Override
public void onOutcome(Outcome<? extends T> outcome) {
public void onOutcome(final Outcome<? extends T> outcome) {
cancellableRef.complete();
callback.onOutcome(outcome);
}

@Override
public void onSuccess(T value) {
public void onSuccess(final T value) {
cancellableRef.complete();
callback.onSuccess(value);
}

@Override
public void onFailure(Throwable e) {
public void onFailure(final Throwable e) {
cancellableRef.complete();
callback.onFailure(e);
}
Expand All @@ -143,7 +143,7 @@ public void onCancellation() {
}

@Override
public InternalContinuation<T> withExecutorOverride(TaskExecutor executor) {
public InternalContinuation<T> withExecutorOverride(final TaskExecutor executor) {
return new CancellableContinuation<>(
executor,
callback,
Expand All @@ -152,7 +152,7 @@ public InternalContinuation<T> withExecutorOverride(TaskExecutor executor) {
}

@Override
public void registerExtraCallback(CompletionCallback<T> extraCallback) {
public void registerExtraCallback(final CompletionCallback<T> extraCallback) {
callback.registerExtraCallback(extraCallback);
}
}
2 changes: 1 addition & 1 deletion tasks-jvm/src/main/java/org/funfix/tasks/jvm/ExitCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static ExitCase succeeded() {
return Completed.INSTANCE;
}

static ExitCase failed(Throwable error) {
static ExitCase failed(final Throwable error) {
return new Failed(error);
}

Expand Down
10 changes: 5 additions & 5 deletions tasks-jvm/src/main/java/org/funfix/tasks/jvm/Fiber.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public interface Fiber<T extends @Nullable Object> extends Cancellable {
* does not cancel the fiber itself.
*/
@NonBlocking
default Cancellable awaitAsync(CompletionCallback<? super T> callback) {
default Cancellable awaitAsync(final CompletionCallback<? super T> callback) {
return joinAsync(() -> {
try {
final var result = getResultOrThrow();
Expand Down Expand Up @@ -392,7 +392,7 @@ record Completed<T extends @Nullable Object>(
Outcome<? extends T> outcome
) implements State<T> {}

default void triggerListeners(TaskExecutor executor) {
default void triggerListeners(final TaskExecutor executor) {
if (this instanceof Active<T> ref) {
for (final var listener : ref.listeners) {
executor.resumeOnExecutor(listener);
Expand Down Expand Up @@ -463,12 +463,12 @@ static final class FiberCallback<T extends @Nullable Object> implements Completi
}

@Override
public void onSuccess(T value) {
public void onSuccess(final T value) {
onOutcome(Outcome.success(value));
}

@Override
public void onFailure(Throwable e) {
public void onFailure(final Throwable e) {
onOutcome(Outcome.failure(e));
}

Expand All @@ -478,7 +478,7 @@ public void onCancellation() {
}

@Override
public void onOutcome(Outcome<? extends T> outcome) {
public void onOutcome(final Outcome<? extends T> outcome) {
while (true) {
State<T> current = stateRef.get();
if (current instanceof State.Active) {
Expand Down
10 changes: 5 additions & 5 deletions tasks-jvm/src/main/java/org/funfix/tasks/jvm/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public Acquired<T> acquireBlocking(@Nullable final Executor executor)
@Blocking
@SuppressWarnings("ConstantValue")
public <R extends @Nullable Object> R useBlocking(
@Nullable Executor executor,
final @Nullable Executor executor,
final ProcessFun<? super T, ? extends R> process
) throws InterruptedException, ExecutionException {
Objects.requireNonNull(process, "use");
Expand Down Expand Up @@ -268,7 +268,7 @@ public static <T extends AutoCloseable> Resource<T> fromAutoCloseable(
* <p>
* @see Task#pure(Object)
*/
public static <T extends @Nullable Object> Resource<T> pure(T value) {
public static <T extends @Nullable Object> Resource<T> pure(final T value) {
return Resource.fromAsync(Task.pure(Acquired.pure(value)));
}

Expand Down Expand Up @@ -338,7 +338,7 @@ public void close() throws Exception {
* Creates a "pure" {@code Acquired} instance with the given value —
* i.e., it just wraps a value with the release function being a no-op.
*/
public static <T extends @Nullable Object> Acquired<T> pure(T value) {
public static <T extends @Nullable Object> Acquired<T> pure(final T value) {
return new Acquired<>(value, NOOP);
}

Expand All @@ -349,8 +349,8 @@ public void close() throws Exception {
* @see Resource#fromBlockingIO(DelayedFun)
*/
public static <T extends @Nullable Object> Acquired<T> fromBlockingIO(
T resource,
CloseableFun release
final T resource,
final CloseableFun release
) {
Objects.requireNonNull(resource, "resource");
Objects.requireNonNull(release, "release");
Expand Down
8 changes: 4 additions & 4 deletions tasks-jvm/src/main/java/org/funfix/tasks/jvm/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -487,12 +487,12 @@ final class TaskFromCancellableFuture<T extends @Nullable Object>

private final DelayedFun<CancellableFuture<? extends T>> builder;

public TaskFromCancellableFuture(DelayedFun<CancellableFuture<? extends T>> builder) {
public TaskFromCancellableFuture(final DelayedFun<CancellableFuture<? extends T>> builder) {
this.builder = builder;
}

@Override
public void invoke(InternalContinuation<T> continuation) {
public void invoke(final InternalContinuation<T> continuation) {
try {
final var cancellableFuture = Objects.requireNonNull(builder.invoke());
final CompletableFuture<? extends T> future =
Expand All @@ -513,8 +513,8 @@ public void invoke(InternalContinuation<T> continuation) {
}

private static <T extends @Nullable Object> CompletableFuture<? extends T> getCompletableFuture(
CancellableFuture<? extends T> cancellableFuture,
CompletionCallback<? super T> callback
final CancellableFuture<? extends T> cancellableFuture,
final CompletionCallback<? super T> callback
) {
CompletableFuture<? extends T> future = cancellableFuture.future();
future.whenComplete((value, error) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public TaskCancellationException() {
super();
}

public TaskCancellationException(@Nullable String message) {
public TaskCancellationException(final @Nullable String message) {
super(message);
}
}
Loading
Loading