2020-11-12 02:13:54 +01:00
|
|
|
package speiger.src.collections.PACKAGE.functions;
|
2020-11-11 21:33:59 +01:00
|
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.function.Consumer;
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* Type-Specific Consumer interface that reduces (un)boxing and allows to merge other consumer types into this interface
|
|
|
|
*/
|
2021-01-21 21:35:23 +01:00
|
|
|
@FunctionalInterface
|
|
|
|
#if JDK_TYPE && !TYPE_BOOLEAN
|
2020-11-11 21:33:59 +01:00
|
|
|
public interface CONSUMER extends Consumer<CLASS_TYPE>, JAVA_CONSUMER
|
2020-11-12 02:13:54 +01:00
|
|
|
#else
|
|
|
|
public interface CONSUMER extends Consumer<CLASS_TYPE>
|
|
|
|
#endif
|
|
|
|
{
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
2020-12-07 08:55:22 +01:00
|
|
|
* Type-Specific function to reduce (un)boxing.
|
2020-12-06 09:32:22 +01:00
|
|
|
* Performs this operation on the given argument.
|
|
|
|
*
|
|
|
|
* @param t the input argument
|
|
|
|
*/
|
2020-11-11 21:33:59 +01:00
|
|
|
void accept(KEY_TYPE t);
|
|
|
|
|
2021-04-25 21:37:22 +02:00
|
|
|
/**
|
|
|
|
* Type Specific sequencing method to reduce boxing/unboxing.
|
|
|
|
* @param after a operation that should be performed afterwards
|
|
|
|
* @return a sequenced consumer that does 2 operations
|
|
|
|
* @throws NullPointerException if after is null
|
|
|
|
*/
|
2020-12-06 09:32:22 +01:00
|
|
|
public default CONSUMER andThen(CONSUMER after) {
|
|
|
|
Objects.requireNonNull(after);
|
|
|
|
return T -> {accept(T); after.accept(T);};
|
|
|
|
}
|
2020-11-12 02:13:54 +01:00
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/** {@inheritDoc}
|
2020-12-07 08:55:22 +01:00
|
|
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
|
|
|
* @deprecated Please use the corresponding type-specific function instead.
|
2020-12-06 09:32:22 +01:00
|
|
|
*/
|
2020-11-12 02:13:54 +01:00
|
|
|
@Override
|
2020-12-06 09:32:22 +01:00
|
|
|
@Deprecated
|
2020-11-11 21:33:59 +01:00
|
|
|
default void accept(CLASS_TYPE t) { accept(OBJ_TO_KEY(t)); }
|
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/** {@inheritDoc}
|
2020-12-07 08:55:22 +01:00
|
|
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
|
|
|
* @deprecated Please use the corresponding type-specific function instead.
|
2020-12-06 09:32:22 +01:00
|
|
|
*/
|
2020-11-11 21:33:59 +01:00
|
|
|
@Override
|
2020-12-06 09:32:22 +01:00
|
|
|
@Deprecated
|
2020-11-11 21:33:59 +01:00
|
|
|
default CONSUMER andThen(Consumer<? super CLASS_TYPE> after) {
|
2020-11-12 02:13:54 +01:00
|
|
|
Objects.requireNonNull(after);
|
|
|
|
return T -> {accept(T); after.accept(KEY_TO_OBJ(T));};
|
|
|
|
}
|
2021-01-21 21:35:23 +01:00
|
|
|
#if JDK_TYPE && PRIMITIVES
|
2020-11-12 02:13:54 +01:00
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/** {@inheritDoc}
|
2020-12-07 08:55:22 +01:00
|
|
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
|
|
|
* @deprecated Please use the corresponding type-specific function instead.
|
2020-12-06 09:32:22 +01:00
|
|
|
*/
|
2020-11-12 02:13:54 +01:00
|
|
|
@Override
|
2020-12-06 09:32:22 +01:00
|
|
|
@Deprecated
|
2020-11-12 02:13:54 +01:00
|
|
|
default CONSUMER andThen(JAVA_CONSUMER after) {
|
2020-11-11 21:33:59 +01:00
|
|
|
Objects.requireNonNull(after);
|
|
|
|
return T -> {accept(T); after.accept(T);};
|
|
|
|
}
|
2020-11-12 02:13:54 +01:00
|
|
|
#endif
|
2020-11-11 21:33:59 +01:00
|
|
|
}
|