01: /*
02: * Copyright 2001-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.apache.commons.collections.functors;
17:
18: import java.io.Serializable;
19:
20: import org.apache.commons.collections.Predicate;
21:
22: /**
23: * Predicate implementation that returns true if the input is the same object
24: * as the one stored in this predicate by equals.
25: *
26: * @since Commons Collections 3.0
27: * @version $Revision: 348444 $ $Date: 2005-11-23 14:06:56 +0000 (Wed, 23 Nov 2005) $
28: *
29: * @author Stephen Colebourne
30: */
31: public final class EqualPredicate implements Predicate, Serializable {
32:
33: /** Serial version UID */
34: private static final long serialVersionUID = 5633766978029907089L;
35:
36: /** The value to compare to */
37: private final Object iValue;
38:
39: /**
40: * Factory to create the identity predicate.
41: *
42: * @param object the object to compare to
43: * @return the predicate
44: * @throws IllegalArgumentException if the predicate is null
45: */
46: public static Predicate getInstance(Object object) {
47: if (object == null) {
48: return NullPredicate.INSTANCE;
49: }
50: return new EqualPredicate(object);
51: }
52:
53: /**
54: * Constructor that performs no validation.
55: * Use <code>getInstance</code> if you want that.
56: *
57: * @param object the object to compare to
58: */
59: public EqualPredicate(Object object) {
60: super ();
61: iValue = object;
62: }
63:
64: /**
65: * Evaluates the predicate returning true if the input equals the stored value.
66: *
67: * @param object the input object
68: * @return true if input object equals stored value
69: */
70: public boolean evaluate(Object object) {
71: return (iValue.equals(object));
72: }
73:
74: /**
75: * Gets the value.
76: *
77: * @return the value
78: * @since Commons Collections 3.1
79: */
80: public Object getValue() {
81: return iValue;
82: }
83:
84: }
|