/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ratpack.func;
/**
* A function that returns {@code true} or {@code false} for a value.
*
* This type serves the same purpose as the JDK's {@link java.util.function.Predicate}, but allows throwing checked exceptions.
* It contains methods for bridging to and from the JDK type.
*
* @param the type of object "tested" by the predicate
*/
@FunctionalInterface
public interface Predicate {
/**
* Tests the given value.
*
* @param t the value to "test"
* @return {@code true} if the predicate applied, otherwise {@code false}
* @throws Exception any
*/
boolean apply(T t) throws Exception;
/**
* Creates a predicate from a JDK predicate.
*
* @param predicate the JDK predicate
* @param the type of object this predicate tests
* @return the given JDK predicate as a predicate
*/
static Predicate from(java.util.function.Predicate predicate) {
return null;
}
/**
* Creates a predicate from a Guava predicate.
*
* @param predicate the Guava predicate
* @param the type of object this predicate tests
* @return the given Guava predicate as a predicate
*/
static Predicate fromGuava(com.google.common.base.Predicate predicate) {
return null;
}
/**
* A predicate that always returns {@code true}, regardless of the input object.
*
* @param the type of input object
* @return a predicate that always returns {@code true}
* @since 1.1
*/
static Predicate alwaysTrue() {
return null;
}
/**
* A predicate that always returns {@code false}, regardless of the input object.
*
* @param the type of input object
* @return a predicate that always returns {@code false}
* @since 1.1
*/
static Predicate alwaysFalse() {
return null;
}
/**
* Creates a function the returns one of the given values.
*
* @param onTrue the value to return if the predicate applies
* @param onFalse the value to return if the predicate does not apply
* @param the output value
* @return a function
* @since 1.5
*/
default Function function(O onTrue, O onFalse) {
return null;
}
}