2 * Copyright (c) 2018 Amartus and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.unimgr.utils;
10 import java.util.function.Predicate;
12 import org.hamcrest.BaseMatcher;
13 import org.hamcrest.Description;
16 public class PredicateMatcher<T> extends BaseMatcher<T> {
18 private final Predicate<T> predicate;
20 public PredicateMatcher(Predicate<T> predicate) {
21 this.predicate = predicate;
24 @SuppressWarnings("unchecked")
26 public boolean matches(Object item) {
27 return predicate.test((T) item);
31 public void describeTo(Description description) {
32 description.appendText("Predicate not fulfilled");
35 public static <U> PredicateMatcher<U> fromPredicate(Predicate<U> predicate) {
36 return new PredicateMatcher<>(predicate);