blob: 9f33c79cc4ded794e5c1461bf131b21f1c0c3b30 [file] [log] [blame]
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* 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 org.apache.commons.functor.core;
import java.io.Serializable;
import org.apache.commons.functor.BinaryFunction;
import org.apache.commons.functor.BinaryPredicate;
/**
* {@link #evaluate Evaluates} to its first argument.
*
* {@link #test Tests} to the <code>boolean</code>
* value of the <code>Boolean</code>-valued first
* argument. The {@link #test test} method
* throws an exception if the parameter isn't a
* non-<code>null</code> <code>Boolean</code>.
*
* @version $Revision$ $Date$
* @author Rodney Waldhoff
*/
public final class LeftIdentity implements BinaryPredicate, BinaryFunction, Serializable {
// constructor
// ------------------------------------------------------------------------
public LeftIdentity() {
}
// functor interface
// ------------------------------------------------------------------------
public Object evaluate(Object left, Object right) {
return left;
}
public boolean test(Object left, Object right) {
return test((Boolean)left);
}
private boolean test(Boolean bool) {
return bool.booleanValue();
}
public boolean equals(Object that) {
return (that instanceof LeftIdentity);
}
public int hashCode() {
return "LeftIdentity".hashCode();
}
public String toString() {
return "LeftIdentity";
}
// static methods
// ------------------------------------------------------------------------
public static LeftIdentity instance() {
return INSTANCE;
}
// static attributes
// ------------------------------------------------------------------------
private static final LeftIdentity INSTANCE = new LeftIdentity();
}