forked from Speiger/Primitive-Collections
79 lines
2.3 KiB
Plaintext
79 lines
2.3 KiB
Plaintext
package speiger.src.collections.PACKAGE.functions.function;
|
|
|
|
#if JDK_FUNCTION && VALUE_BOOLEAN
|
|
import java.util.Objects;
|
|
#endif
|
|
|
|
/**
|
|
* A Type Specific Function interface that reduces boxing/unboxing and fills the gaps of interfaces that are missing.
|
|
* @Type(T)
|
|
* @ValueType(V)
|
|
*/
|
|
@FunctionalInterface
|
|
#if JDK_FUNCTION
|
|
public interface FUNCTION KEY_VALUE_GENERIC_TYPE extends JAVA_FUNCTION KEY_VALUE_GENERIC_TYPE
|
|
#else
|
|
public interface FUNCTION KEY_VALUE_GENERIC_TYPE
|
|
#endif
|
|
{
|
|
/**
|
|
* Type Specific get function to reduce boxing/unboxing
|
|
* @param k the value that should be processed
|
|
* @return the result of the function
|
|
*/
|
|
public VALUE_TYPE GET_VALUE(KEY_TYPE k);
|
|
|
|
#if JDK_FUNCTION
|
|
#if VALUE_BOOLEAN
|
|
@Override
|
|
public default VALUE_TYPE test(KEY_TYPE k) { return GET_VALUE(k); }
|
|
|
|
/**
|
|
* A Type specific and-function helper function that reduces boxing/unboxing
|
|
* @param other the other function that should be merged with.
|
|
* @return a function that compares values in a and comparason
|
|
*/
|
|
public default FUNCTION KEY_VALUE_GENERIC_TYPE andType(FUNCTION KEY_VALUE_GENERIC_TYPE other) {
|
|
Objects.requireNonNull(other);
|
|
return T -> GET_VALUE(T) && other.GET_VALUE(T);
|
|
}
|
|
|
|
@Override
|
|
@Deprecated
|
|
public default FUNCTION KEY_VALUE_GENERIC_TYPE and(JAVA_FUNCTION KEY_VALUE_SUPER_GENERIC_TYPE other) {
|
|
Objects.requireNonNull(other);
|
|
return T -> GET_VALUE(T) && other.test(T);
|
|
}
|
|
|
|
@Override
|
|
public default FUNCTION KEY_VALUE_GENERIC_TYPE negate() {
|
|
return T -> !GET_VALUE(T);
|
|
}
|
|
|
|
/**
|
|
* A Type specific or-function helper function that reduces boxing/unboxing
|
|
* @param other the other function that should be merged with.
|
|
* @return a function that compares values in a or comparason
|
|
*/
|
|
public default FUNCTION KEY_VALUE_GENERIC_TYPE orType(FUNCTION KEY_VALUE_GENERIC_TYPE other) {
|
|
Objects.requireNonNull(other);
|
|
return T -> GET_VALUE(T) || other.GET_VALUE(T);
|
|
}
|
|
|
|
@Override
|
|
@Deprecated
|
|
public default FUNCTION KEY_VALUE_GENERIC_TYPE or(JAVA_FUNCTION KEY_VALUE_SUPER_GENERIC_TYPE other) {
|
|
Objects.requireNonNull(other);
|
|
return T -> GET_VALUE(T) || other.test(T);
|
|
}
|
|
#else if VALUE_OBJECT
|
|
|
|
@Override
|
|
public default VALUE_TYPE apply(KEY_TYPE k) { return GET_VALUE(k); }
|
|
#else
|
|
|
|
@Override
|
|
public default VALUE_TYPE APPLY_VALUE(KEY_TYPE k) { return GET_VALUE(k); }
|
|
#endif
|
|
#endif
|
|
} |