blob: 6aad8f5e32540771a7ece99423a921024a99154d [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2005, 2013 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0, which accompanies this distribution
* and is available at https://www.eclipse.org/legal/epl-2.0/.
*
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.common.utility.internal.predicate;
import java.io.Serializable;
import org.eclipse.jpt.common.utility.predicate.Predicate;
/**
* Singleton predicate that evaluates whether an object is
* <code>null</code>.
*
* @param <V> the type of objects to be evaluated by the predicate
*/
public final class IsNull<V>
implements Predicate<V>, Serializable
{
@SuppressWarnings("rawtypes")
public static final Predicate INSTANCE = new IsNull();
@SuppressWarnings("unchecked")
public static <V> Predicate<V> instance() {
return INSTANCE;
}
// ensure single instance
private IsNull() {
super();
}
/**
* Return whether the variable is <code>null</code>.
*/
public boolean evaluate(V variable) {
return variable == null;
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
private static final long serialVersionUID = 1L;
private Object readResolve() {
// replace this object with the singleton
return INSTANCE;
}
}