functionalj.promise.PromiseStatusAddOn Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of functionalj-core Show documentation
Show all versions of functionalj-core Show documentation
The module for FunctionalJ Core.
// ============================================================================
// Copyright (c) 2017-2021 Nawapunth Manusitthipol (NawaMan - http://nawaman.net).
// ----------------------------------------------------------------------------
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// ============================================================================
package functionalj.promise;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import functionalj.function.Func1;
import functionalj.function.Func2;
import functionalj.function.FuncUnit1;
import functionalj.function.FuncUnit2;
import functionalj.result.Result;
@SuppressWarnings({ "unchecked", "rawtypes" })
public interface PromiseStatusAddOn {
public Promise mapResult(Function, Result extends TARGET>> mapper);
public default Promise useData(FuncUnit2 processor) {
return (Promise)mapResult(result -> result.useData((FuncUnit2)processor));
}
public default Promise whenComplete(FuncUnit2 processor) {
return (Promise)mapResult(result -> result.useData((FuncUnit2)processor));
}
public default Promise whenComplete(FuncUnit1> processor) {
return (Promise)mapResult(result -> {
processor.accept((Result)result);
return null;
});
}
//== Present ==
public default Promise ifPresent(Runnable runnable) {
return (Promise)mapResult(result -> result.ifPresent(runnable));
}
public default Promise ifPresent(Consumer super DATA> consumer) {
return (Promise)mapResult(result -> result.ifPresent((Consumer)consumer));
}
//== Absent ==
public default Promise ifAbsent(Runnable runnable) {
return (Promise)mapResult(result -> result.ifAbsent(runnable));
}
public default Promise ifAbsent(Consumer super DATA> consumer) {
return (Promise)mapResult(result -> result.ifAbsent((Consumer)consumer));
}
public default Promise ifAbsent(BiConsumer super DATA, ? super Exception> consumer) {
return (Promise)mapResult(result -> result.ifAbsent((BiConsumer)consumer));
}
public default Promise whenAbsentUse(DATA fallbackValue) {
return (Promise)mapResult(result -> result.whenAbsentUse(fallbackValue));
}
public default Promise whenAbsentGet(Supplier extends DATA> fallbackSupplier) {
return (Promise)mapResult(result -> result.whenAbsentGet(fallbackSupplier));
}
public default Promise whenAbsentApply(BiFunction recoverFunction) {
return (Promise)mapResult(result -> result.whenAbsentApply((Func2)recoverFunction));
}
//== Null ==
public default Promise ifNull(Runnable runnable) {
return (Promise)mapResult(result -> result.ifNull(runnable));
}
public default Promise whenNullUse(DATA fallbackValue) {
return (Promise)mapResult(result -> result.whenNullUse(fallbackValue));
}
public default Promise whenNullGet(Supplier extends DATA> fallbackSupplier) {
return (Promise)mapResult(result -> result.whenNullGet(fallbackSupplier));
}
//== Value ==
public default Promise ifValue(Runnable runnable) {
return (Promise)mapResult(result -> result.ifValue(runnable));
}
public default Promise ifValue(Consumer super DATA> consumer) {
return (Promise)mapResult(result -> result.ifValue((Consumer)consumer));
}
//== NotValue ==
public default Promise ifNotValue(Runnable runnable) {
return (Promise)mapResult(result -> result.ifNotValue(runnable));
}
public default Promise ifNotValue(Consumer super DATA> consumer) {
return (Promise)mapResult(result -> result.ifNotValue((Consumer)consumer));
}
public default Promise ifNotValue(BiConsumer super DATA, ? super Exception> consumer) {
return (Promise)mapResult(result -> result.ifNotValue((BiConsumer)consumer));
}
public default Promise whenNotValueUse(DATA fallbackValue) {
return (Promise)mapResult(result -> result.whenNotValueUse(fallbackValue));
}
public default Promise whenNotValueGet(Supplier extends DATA> fallbackSupplier) {
return (Promise)mapResult(result -> result.whenNotValueGet(fallbackSupplier));
}
public default Promise whenNotValueApply(BiFunction recoverFunction) {
return (Promise)mapResult(result -> result.whenNotValueApply((Func2)recoverFunction));
}
//== Valid ==
public default Promise ifValid(Consumer super DATA> consumer) {
return (Promise)mapResult(result -> result.ifValid((Consumer)consumer));
}
//== Invalid ==
public default Promise ifInvalid(Runnable runnable) {
return (Promise)mapResult(result -> result.ifInvalid(runnable));
}
public default Promise ifInvalid(Consumer super Exception> consumer) {
return (Promise)mapResult(result -> result.ifInvalid((Consumer)consumer));
}
public default Promise whenInvalidUse(DATA fallbackValue) {
return (Promise)mapResult(result -> result.whenInvalidUse(fallbackValue));
}
public default Promise whenInvalidGet(Supplier extends DATA> fallbackSupplier) {
return (Promise)mapResult(result -> result.whenInvalidGet((Supplier)fallbackSupplier));
}
public default Promise whenInvalidApply(Function super Exception,? extends DATA> recoverFunction) {
return (Promise)mapResult(result -> result.whenInvalidApply((Func1)recoverFunction));
}
//== NotExist ==
public default Promise ifNotExist(Runnable runnable) {
return (Promise)mapResult(result -> result.ifNotExist(runnable));
}
public default Promise ifNotExist(Consumer super Exception> consumer) {
return (Promise)mapResult(result -> result.ifNotExist((Consumer)consumer));
}
public default Promise whenNotExistUse(DATA fallbackValue) {
return (Promise)mapResult(result -> result.whenNotExistUse(fallbackValue));
}
public default Promise whenNotExistGet(Supplier extends DATA> fallbackSupplier) {
return (Promise)mapResult(result -> result.whenNotExistGet(fallbackSupplier));
}
public default Promise whenNotExistApply(Function super Exception,? extends DATA> recoverFunction) {
return (Promise)mapResult(result -> result.whenNotExistApply(recoverFunction));
}
//== Exception ==
public default Promise ifException(Runnable runnable) {
return (Promise)mapResult(result -> result.ifException(runnable));
}
public default Promise ifException(Consumer super Exception> consumer) {
return (Promise)mapResult(result -> result.ifException(consumer));
}
public default Promise ifExceptionThenPrint() {
return (Promise)mapResult(result -> result.ifExceptionThenPrint());
}
public default Promise ifExceptionThenPrint(PrintStream printStream) {
return (Promise)mapResult(result -> result.ifExceptionThenPrint(printStream));
}
public default Promise ifExceptionThenPrint(PrintWriter printWriter) {
return (Promise)mapResult(result -> result.ifExceptionThenPrint(printWriter));
}
public default Promise whenExceptionUse(DATA fallbackValue) {
return (Promise)mapResult(result -> result.whenExceptionUse(fallbackValue));
}
public default Promise whenExceptionGet(Supplier extends DATA> fallbackSupplier) {
return (Promise)mapResult(result -> result.whenExceptionGet(fallbackSupplier));
}
public default Promise whenExceptionApply(Function super Exception,? extends DATA> recoverFunction) {
return (Promise)mapResult(result -> result.whenExceptionApply(recoverFunction));
}
public default Promise recover(Class extends Throwable> problemClass, DATA fallbackValue) {
return (Promise)mapResult(result -> result.recover(problemClass, fallbackValue));
}
public default Promise recover(Class extends Throwable> problemClass, Supplier extends DATA> fallbackSupplier) {
return (Promise)mapResult(result -> result.recover(problemClass, fallbackSupplier));
}
public default Promise recover(Class extends Throwable> problemClass, Func1 super Exception,? extends DATA> recoverFunction) {
return (Promise)mapResult(result -> result.recover(problemClass, recoverFunction));
}
//== Cancelled ==
public default Promise ifCancelled(Runnable runnable) {
return (Promise)mapResult(result -> result.ifCancelled(runnable));
}
public default Promise whenCancelledUse(DATA fallbackValue) {
return (Promise)mapResult(result -> result.whenCancelledUse(fallbackValue));
}
public default Promise whenCancelledGet(Supplier extends DATA> fallbackSupplier) {
return (Promise)mapResult(result -> result.whenCancelledGet(fallbackSupplier));
}
public default Promise whenCancelledApply(Function super Exception,? extends DATA> recoverFunction) {
return (Promise)mapResult(result -> result.whenCancelledApply(recoverFunction));
}
//== Ready ==
public default Promise ifReady(Runnable runnable) {
return (Promise)mapResult(result -> result.ifReady(runnable));
}
public default Promise ifReady(Consumer super DATA> consumer) {
return (Promise)mapResult(result -> result.ifReady((Consumer)consumer));
}
public default Promise ifReady(BiConsumer super DATA, ? super Exception> consumer) {
return (Promise)mapResult(result -> result.ifReady((BiConsumer)consumer));
}
public default Promise whenReadyUse(DATA fallbackValue) {
return (Promise)mapResult(result -> result.whenReadyUse(fallbackValue));
}
public default Promise whenReadyGet(Supplier extends DATA> fallbackSupplier) {
return (Promise)mapResult(result -> result.whenReadyGet(fallbackSupplier));
}
public default Promise whenNotReadyApply(BiFunction recoverFunction) {
return (Promise)mapResult(result -> result.whenNotReadyApply((Func2)recoverFunction));
}
//== Not Ready ==
public default Promise ifNotReady(Runnable runnable) {
return (Promise)mapResult(result -> result.ifNotReady(runnable));
}
public default Promise ifNotReady(Consumer super Exception> consumer) {
return (Promise)mapResult(result -> result.ifNotReady((Consumer)consumer));
}
public default Promise whenNotReadyUse(DATA fallbackValue) {
return (Promise)mapResult(result -> result.whenNotReadyUse(fallbackValue));
}
public default Promise whenNotReadyGet(Supplier extends DATA> fallbackSupplier) {
return (Promise)mapResult(result -> result.whenNotReadyGet(fallbackSupplier));
}
public default Promise whenNotReadyApply(Function super Exception,? extends DATA> recoverFunction) {
return (Promise)mapResult(result -> result.whenNotReadyApply(recoverFunction));
}
//== No More Result ==
public default Promise ifNoMore(Runnable runnable) {
return (Promise)mapResult(result -> result.ifNoMore(runnable));
}
public default Promise ifNoMore(Consumer super Exception> consumer) {
return (Promise)mapResult(result -> result.ifNoMore(consumer));
}
public default Promise whenNoMoreUse(DATA fallbackValue) {
return (Promise)mapResult(result -> result.whenNoMoreUse(fallbackValue));
}
public default Promise whenNoMoreGet(Supplier extends DATA> fallbackSupplier) {
return (Promise)mapResult(result -> result.whenNoMoreGet(fallbackSupplier));
}
public default Promise whenNoMoreApply(Function super Exception,? extends DATA> recoverFunction) {
return (Promise)mapResult(result -> result.whenNoMoreApply(recoverFunction));
}
}