Skip to content

Commit

Permalink
perf(core): Remove deprecated API (#228)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Deprecated API has been removed in favor of the new API
  • Loading branch information
JoseLion authored Feb 3, 2024
1 parent c04a6b2 commit d4329e7
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 730 deletions.
49 changes: 0 additions & 49 deletions src/main/java/io/github/joselion/maybe/CloseableHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,31 +115,6 @@ public <S, X extends Throwable> SolveHandler<S, X> solve(
);
}

/**
* If the resource is present, solves the value of a throwing operation
* using a {@link ThrowingFunction} expression which has the previously
* prepared resource in the argument. The resource is automatically closed
* after the operation finishes, just like a common try-with-resources
* statement.
* <p>
* Returs a {@link SolveHandler} which allows to handle the possible error
* and return a safe value. The returned handler is {@code empty} if neither
* the resource nor the error is present.
*
* @param <S> the type of the value returned by the {@code solver}
* @param <X> the type of exception the {@code solver} may throw
* @param solver the checked function operation to solve
* @return a {@link SolveHandler} with either the value solved or the thrown
* exception to be handled
* @deprecated in favor of {@link #solve(ThrowingFunction)}
*/
@Deprecated(forRemoval = true, since = "3.4.0")
public <S, X extends Throwable> SolveHandler<S, X> resolveClosing(// NOSONAR
final ThrowingFunction<? super T, ? extends S, ? extends X> solver
) {
return this.solve(solver);
}

/**
* If the resource is present, runs an effect that may throw an exception
* using a {@link ThrowingConsumer} expression which has the previously
Expand Down Expand Up @@ -174,28 +149,4 @@ public <X extends Throwable> EffectHandler<X> effect(
}
);
}

/**
* If the resource is present, runs an effect that may throw an exception
* using a {@link ThrowingConsumer} expression which has the previously
* prepared resource in the argument. The resource is automatically closed
* after the operation finishes, just like a common try-with-resources
* statement.
* <p>
* Returning then an {@link EffectHandler} which allows to handle the
* possible error. The returned handler is {@code empty} if neither the
* resource nor the error is present.
*
* @param <X> the type of exception the {@code effect} may throw
* @param effect the checked consumer operation to execute
* @return an {@link EffectHandler} with either the thrown exception to be
* handled or empty
* @deprecated in favor of {@link #effect(ThrowingConsumer)}
*/
@Deprecated(forRemoval = true, since = "3.4.0")
public <X extends Throwable> EffectHandler<X> runEffectClosing(// NOSONAR
final ThrowingConsumer<? super T, ? extends X> effect
) {
return this.effect(effect);
}
}
37 changes: 0 additions & 37 deletions src/main/java/io/github/joselion/maybe/EffectHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,25 +172,6 @@ public <X extends Throwable> EffectHandler<X> effect(
.orElseGet(() -> Maybe.from(onSuccess));
}

/**
* Chain another effect covering both cases of success or error of the
* previous effect in two different callbacks.
*
* @param <X> the type of the error the new effect may throw
* @param onSuccess a runnable checked function to run in case of succeess
* @param onError a runnable checked function to run in case of error
* @return a new {@link EffectHandler} representing the result of one of the
* invoked callback
* @deprecated in favor of {@link #effect(ThrowingRunnable, ThrowingConsumer)}
*/
@Deprecated(forRemoval = true, since = "3.4.0")
public <X extends Throwable> EffectHandler<X> runEffect(// NOSONAR
final ThrowingRunnable<? extends X> onSuccess,
final ThrowingConsumer<? super E, ? extends X> onError
) {
return this.effect(onSuccess, onError);
}

/**
* Chain another effect if the previous completed with no error. Otherwise,
* ignores the current error and return a new {@link EffectHandler} that is
Expand All @@ -205,24 +186,6 @@ public <X extends Throwable> EffectHandler<X> effect(final ThrowingRunnable<? ex
return this.effect(effect, err -> { });
}

/**
* Chain another effect if the previous completed with no error. Otherwise,
* ignores the current error and return a new {@link EffectHandler} that is
* either empty or has a different error cause by the next effect.
*
* @param <X> the type of the error the new effect may throw
* @param effect a runnable checked function to run in case of succeess
* @return a new {@link EffectHandler} that is either empty or with the
* thrown error
* @deprecated in favor of {@link #effect(ThrowingRunnable)}
*/
@Deprecated(forRemoval = true, since = "3.4.0")
public <X extends Throwable> EffectHandler<X> runEffect(// NOSONAR
final ThrowingRunnable<? extends X> effect
) {
return this.effect(effect);
}

/**
* Terminal operation to handle the error if present. The error is passed in
* the argument of the {@code effect} consumer.
Expand Down
200 changes: 0 additions & 200 deletions src/main/java/io/github/joselion/maybe/Maybe.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,6 @@ public static <T> Maybe<T> of(final @Nullable Optional<T> value) { // NOSONAR
return new Maybe<>(null);
}

/**
* Creates a {@link Maybe} wrapper of the given value. If the value is
* {@code null}, it returns a {@link #empty()}.
*
* @param <T> the type of the value
* @param value the value be wrapped
* @return a {@code Maybe} wrapping the value if it's non-{@code null},
* {@link #empty()} otherwise
* @deprecated in favor of {@link #of(Object)}
*/
@Deprecated(forRemoval = true, since = "3.4.0")
public static <T> Maybe<T> just(final @Nullable T value) { // NOSONAR
return Maybe.of(value);
}

/**
* Creates an empty {@link Maybe} instance.
*
Expand All @@ -108,40 +93,6 @@ public static <T> Maybe<T> empty() {
return Maybe.of(null);
}

/**
* Creates an empty {@link Maybe} instance.
*
* @param <T> the type of the value
* @return an empty {@code Maybe}
* @deprecated in favor of {@link #empty()}
*/
@Deprecated(forRemoval = true, since = "3.4.0")
public static <T> Maybe<T> nothing() { // NOSONAR
return Maybe.empty();
}

/**
* Creates a {@link Maybe} wrapper of the given value if the optional is not
* empty. Returns a {@link #empty()} otherwise.
* <p>
* This is a convenience creator that would be equivalent to:
* <pre>
* Maybe.of(opt)
* .solve(Optional::get)
* .toMaybe();
* </pre>
*
* @param <T> the type of the value
* @param value an optional value to create the wrapper from
* @return a {@code Maybe} wrapping the value if it's not empty.
* {@link #empty()} otherwise
* @deprecated in favor of {@link #of(Optional)}
*/
@Deprecated(forRemoval = true, since = "3.4.0")
public static <T> Maybe<T> fromOptional(final Optional<T> value) { // NOSONAR
return Maybe.of(value);
}

/**
* Solves the value of a throwing operation using a {@link ThrowingSupplier}
* expression. Returning then a {@link SolveHandler} which allows to handle
Expand All @@ -164,25 +115,6 @@ public static <T, E extends Throwable> SolveHandler<T, E> from(
}
}

/**
* Solves the value of a throwing operation using a {@link ThrowingSupplier}
* expression. Returning then a {@link SolveHandler} which allows to handle
* the possible error and return a safe value.
*
* @param <T> the type of the value returned by the {@code solver}
* @param <E> the type of exception the {@code solver} may throw
* @param solver the checked supplier operation to solve
* @return a {@link SolveHandler} with either the value solved or the thrown
* exception to be handled
* @deprecated in favor of {@link #from(ThrowingSupplier)}
*/
@Deprecated(forRemoval = true, since = "3.4.0")
public static <T, E extends Throwable> SolveHandler<T, E> fromResolver(// NOSONAR
final ThrowingSupplier<? extends T, ? extends E> solver
) {
return Maybe.from(solver);
}

/**
* Runs an effect that may throw an exception using a {@link ThrowingRunnable}
* expression. Returning then an {@link EffectHandler} which allows to handle
Expand All @@ -203,24 +135,6 @@ public static <E extends Throwable> EffectHandler<E> from(final ThrowingRunnable
}
}

/**
* Runs an effect that may throw an exception using a {@link ThrowingRunnable}
* expression. Returning then an {@link EffectHandler} which allows to handle
* the possible error.
*
* @param <E> the type of exception the {@code effect} may throw
* @param effect the checked runnable operation to execute
* @return an {@link EffectHandler} with either the thrown exception to be
* handled or empty
* @deprecated in favor of {@link #from(ThrowingRunnable)}
*/
@Deprecated(forRemoval = true, since = "3.4.0")
public static <E extends Throwable> EffectHandler<E> fromEffect(// NOSONAR
final ThrowingRunnable<? extends E> effect
) {
return Maybe.from(effect);
}

/**
* Convenience partial application of a {@code solver}. This method creates
* a function that receives an {@code S} value which can be used to produce a
Expand Down Expand Up @@ -253,40 +167,6 @@ public static <S, T, E extends Throwable> Function<S, SolveHandler<T, E>> partia
return value -> Maybe.from(() -> solver.apply(value));
}

/**
* Convenience partial application of a {@code solver}. This method creates
* a function that receives an {@code S} value which can be used to produce a
* {@link SolveHandler} once applied. This is specially useful when we want
* to create a {@link Maybe} from a callback argument, like on a
* {@link Optional#map(Function)} for instance.
* <p>
* In other words, the following code
* <pre>
* Optional.of(value)
* .map(str -&gt; Maybe.from(() -&gt; decode(str)));
* </pre>
* Is equivalent to
* <pre>
* Optional.of(value)
* .map(Maybe.partialResolver(this::decode));
* </pre>
*
* @param <S> the type of the value the returned function receives
* @param <T> the type of the value to be solved
* @param <E> the type of the error the solver may throw
* @param solver a checked function that receives an {@code S} value and
* returns a {@code T} value
* @return a partially applied {@link SolveHandler}. This means, a function
* that receives an {@code S} value, and produces a {@code SolveHandler<T, E>}
* @deprecated in favor of {@link #partial(ThrowingFunction)}
*/
@Deprecated(forRemoval = true, since = "3.4.0")
public static <S, T, E extends Throwable> Function<S, SolveHandler<T, E>> partialResolver(// NOSONAR
final ThrowingFunction<? super S, ? extends T, ? extends E> solver
) {
return Maybe.partial(solver);
}

/**
* Convenience partial application of an {@code effect}. This method creates
* a function that receives an {@code S} value which can be used to produce
Expand Down Expand Up @@ -317,38 +197,6 @@ public static <S, E extends Throwable> Function<S, EffectHandler<E>> partial(
return value -> Maybe.from(() -> effect.accept(value));
}

/**
* Convenience partial application of an {@code effect}. This method creates
* a function that receives an {@code S} value which can be used to produce
* an {@link EffectHandler} once applied. This is specially useful when we
* want to create a {@link Maybe} from a callback argument, like on a
* {@link Optional#map(Function)} for instance.
* <p>
* In other words, the following code
* <pre>
* Optional.of(value)
* .map(msg -&gt; Maybe.from(() -&gt; sendMessage(msg)));
* </pre>
* Is equivalent to
* <pre>
* Optional.of(value)
* .map(Maybe.partialEffect(this::sendMessage));
* </pre>
*
* @param <S> the type of the value the returned function receives
* @param <E> the type of the error the effect may throw
* @param effect a checked consumer that receives an {@code S} value
* @return a partially applied {@link EffectHandler}. This means, a function
* that receives an {@code S} value, and produces an {@code EffectHandler<E>}
* @deprecated in favor of {@link #partial(ThrowingConsumer)}
*/
@Deprecated(forRemoval = true, since = "3.4.0")
public static <S, E extends Throwable> Function<S, EffectHandler<E>> partialEffect(// NOSONAR
final ThrowingConsumer<? super S, ? extends E> effect
) {
return Maybe.partial(effect);
}

/**
* Prepare an {@link AutoCloseable} resource to use in a solver or effect.
* The resource will be automatically closed after the operation is finished,
Expand Down Expand Up @@ -447,26 +295,6 @@ public <U, E extends Throwable> SolveHandler<U, E> solve(
}
}

/**
* Chain the {@code Maybe} with another solver, if and only if the previous
* operation was handled with no errors. The value of the previous operation
* is passed as argument of the {@link ThrowingFunction}.
*
* @param <U> the type of value returned by the next operation
* @param <E> the type of exception the new solver may throw
* @param solver a checked function that receives the current value and
* solves another
* @return a {@link SolveHandler} with either the solved value, or the
* thrown exception to be handled
* @deprecated in favor of {@link #solve(ThrowingFunction)}
*/
@Deprecated(forRemoval = true, since = "3.4.0")
public <U, E extends Throwable> SolveHandler<U, E> resolve(// NOSONAR
final ThrowingFunction<? super T, ? extends U, ? extends E> solver
) {
return this.solve(solver);
}

/**
* Chain the {@code Maybe} with another effect, if and only if the previous
* operation was handled with no errors.
Expand All @@ -487,23 +315,6 @@ public <E extends Throwable> EffectHandler<E> effect(final ThrowingConsumer<? su
}
}

/**
* Chain the {@code Maybe} with another effect, if and only if the previous
* operation was handled with no errors.
*
* @param <E> the type of exception the new effect may throw
* @param effect the checked runnable operation to execute next
* @return an {@link EffectHandler} with either the thrown exception to be
* handled or nothing
* @deprecated in favor of {@link #effect(ThrowingConsumer)}
*/
@Deprecated(forRemoval = true, since = "3.4.0")
public <E extends Throwable> EffectHandler<E> runEffect(// NOSONAR
final ThrowingConsumer<? super T, ? extends E> effect
) {
return this.effect(effect);
}

/**
* If the value is present, cast the value to another type. In case of an
* exception during the cast, a Maybe with {@link #empty()} is returned.
Expand Down Expand Up @@ -537,17 +348,6 @@ public boolean isEmpty() {
return this.value.isEmpty();
}

/**
* Checks if the {@code Maybe} is empty. That is, when no value is present.
*
* @return true if the value is not present, false otherwise
* @deprecated in favor of {@link #isEmpty()}
*/
@Deprecated(forRemoval = true, since = "3.4.0")
public boolean hasNothing() { // NOSONAR
return this.isEmpty();
}

/**
* Safely unbox the value as an {@link Optional} which may or may not contain
* a value.
Expand Down
Loading

0 comments on commit d4329e7

Please sign in to comment.