001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.commons.functor.core;
018
019 import java.io.Serializable;
020
021 import org.apache.commons.functor.BinaryPredicate;
022 import org.apache.commons.functor.UnaryPredicate;
023 import org.apache.commons.functor.adapter.RightBoundPredicate;
024
025 /**
026 * {@link #test Tests} the reference (!=) inequality of its arguments.
027 *
028 * @param <L> the left argument type.
029 * @param <R> the right argument type.
030 * @version $Revision: 1160404 $ $Date: 2011-08-22 21:49:40 +0200 (Mon, 22 Aug 2011) $
031 * @author Matt Benson
032 */
033 public final class IsNotSame<L, R> implements BinaryPredicate<L, R>, Serializable {
034 // static attributes
035 // ------------------------------------------------------------------------
036 /**
037 * Basic IsNotSame<Object, Object> instance.
038 */
039 public static final IsNotSame<Object, Object> INSTANCE = IsNotSame.<Object, Object>instance();
040 /**
041 * serialVersionUID declaration.
042 */
043 private static final long serialVersionUID = 5566555980860979281L;
044
045 // constructor
046 // ------------------------------------------------------------------------
047 /**
048 * Create a new IsNotSame.
049 */
050 public IsNotSame() {
051 }
052
053 // predicate interface
054 // ------------------------------------------------------------------------
055 /**
056 * {@inheritDoc}
057 */
058 public boolean test(L left, R right) {
059 return left != right;
060 }
061
062 /**
063 * {@inheritDoc}
064 */
065 public boolean equals(Object that) {
066 return that instanceof IsNotSame<?, ?>;
067 }
068
069 /**
070 * {@inheritDoc}
071 */
072 public int hashCode() {
073 return "IsNotSame".hashCode();
074 }
075
076 /**
077 * {@inheritDoc}
078 */
079 public String toString() {
080 return "IsNotSame";
081 }
082
083 // static methods
084 // ------------------------------------------------------------------------
085 /**
086 * Get an IsNotSame instance.
087 * @param <L> the left argument type.
088 * @param <R> the right argument type.
089 * @return IsNotSame
090 */
091 public static <L, R> IsNotSame<L, R> instance() {
092 return new IsNotSame<L, R>();
093 }
094
095 /**
096 * Get an IsNotSame UnaryPredicate.
097 * @param <L> the left argument type.
098 * @param <R> the right argument type.
099 * @param object bound comparison object
100 * @return UnaryPredicate<L>
101 */
102 public static <L, R> UnaryPredicate<L> as(R object) {
103 return new RightBoundPredicate<L>(new IsNotSame<L, R>(), object);
104 }
105 }