From c6557f0a86929a1d73a75e7ca442cda9baad4569 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin <eclipse.sprigogin@gmail.com> Date: Thu, 6 Mar 2014 11:37:28 -0800 Subject: [PATCH] Added InstanceOfPredicate. --- .../core/parser/util/InstanceOfPredicate.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/InstanceOfPredicate.java diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/InstanceOfPredicate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/InstanceOfPredicate.java new file mode 100644 index 00000000000..bc5f5c99147 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/InstanceOfPredicate.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2014 Google, Inc and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sergey Prigogin (Google) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.parser.util; + +/** + * Unary predicate returning {@code true} if the object is an instance of the given class. + * @since 5.7 + */ +public class InstanceOfPredicate<T> implements IUnaryPredicate<T> { + private Class<T> type; + + public InstanceOfPredicate(Class<T> type) { + this.type = type; + } + + @Override + public boolean apply(T obj) { + return type.isInstance(obj); + } +}