Primitive-Collections/src/main/resources/speiger/assets/collections/templates/functions/Consumer.template

77 lines
2.2 KiB
Plaintext

package speiger.src.collections.PACKAGE.functions;
import java.util.Objects;
import java.util.function.Consumer;
#if !TYPE_BOOLEAN
#if !JDK_CONSUMER
import speiger.src.collections.utils.SanityChecks;
#endif
/**
* Type-Specific Consumer interface that reduces (un)boxing and allows to merge other consumer types into this interface
*/
public interface CONSUMER extends Consumer<CLASS_TYPE>, JAVA_CONSUMER
#else
/**
* Type-Specific Consumer interface that reduces (un)boxing and allows to merge other consumer types into this interface
*/
public interface CONSUMER extends Consumer<CLASS_TYPE>
#endif
{
/**
* Type-Specific method to reduce (un)boxing.
* Performs this operation on the given argument.
*
* @param t the input argument
*/
void accept(KEY_TYPE t);
#if !JDK_CONSUMER
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method.
* @deprecated Please use the corresponding type-specific method instead.
*/
@Override
@Deprecated
default void accept(JAVA_TYPE t) { accept(SanityChecks.SANITY_CAST(t)); }
#endif
public default CONSUMER andThen(CONSUMER after) {
Objects.requireNonNull(after);
return T -> {accept(T); after.accept(T);};
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method.
* @deprecated Please use the corresponding type-specific method instead.
*/
@Override
@Deprecated
default void accept(CLASS_TYPE t) { accept(OBJ_TO_KEY(t)); }
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method.
* @deprecated Please use the corresponding type-specific method instead.
*/
@Override
@Deprecated
default CONSUMER andThen(Consumer<? super CLASS_TYPE> after) {
Objects.requireNonNull(after);
return T -> {accept(T); after.accept(KEY_TO_OBJ(T));};
}
#if PRIMITIVES
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method.
* @deprecated Please use the corresponding type-specific method instead.
*/
@Override
@Deprecated
default CONSUMER andThen(JAVA_CONSUMER after) {
Objects.requireNonNull(after);
return T -> {accept(T); after.accept(T);};
}
#endif
}