se.litsec.opensaml.utils.PredicateWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opensaml3-ext Show documentation
Show all versions of opensaml3-ext Show documentation
OpenSAML 3.X utility extension library
/*
* Copyright 2016-2018 Litsec AB
*
* 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 se.litsec.opensaml.utils;
import java.util.function.Predicate;
/**
* OpenSAML uses {@code com.google.common.base.Predicate} but we want to use {@link java.util.function.Predicate}. This
* wrapper class encapsulates a {@code java.util.function.Predicate} into a {@code com.google.common.base.Predicate}
* instance.
*
* @author Martin Lindström ([email protected])
*
* @param
* the type
*/
public class PredicateWrapper implements com.google.common.base.Predicate {
/** The wrapped {@code java.util.function.Predicate}. */
private Predicate predicate;
/**
* Constructor assigning the {@code java.util.function.Predicate} to wrap.
*
* @param predicate
* the predicate
*/
public PredicateWrapper(Predicate predicate) {
this.predicate = predicate;
}
/** {@inheritDoc} */
@Override
public boolean apply(T input) {
return this.predicate.test(input);
}
/**
* Utility method that wraps a {@link java.util.function.Predicate} into a {@code com.google.common.base.Predicate}.
*
* @param predicate
* the predicate to wrap
* @param
* the type contained in the predicate
* @return a {@code com.google.common.base.Predicate} instance
*/
public static com.google.common.base.Predicate wrap(Predicate predicate) {
return new PredicateWrapper<>(predicate);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy