1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.commons.functor.core; 18 19 import org.apache.commons.functor.BinaryPredicate; 20 import org.apache.commons.functor.Predicate; 21 import org.apache.commons.functor.adapter.RightBoundPredicate; 22 23 /** 24 * {@link #test Tests} the reference (!=) inequality of its arguments. 25 * 26 * @param <L> the left argument type. 27 * @param <R> the right argument type. 28 * @version $Revision: 1537906 $ $Date: 2013-11-01 12:47:33 +0100 (Fr, 01 Nov 2013) $ 29 */ 30 public final class IsNotSame<L, R> implements BinaryPredicate<L, R> { 31 // static attributes 32 // ------------------------------------------------------------------------ 33 /** 34 * Basic IsNotSame<Object, Object> instance. 35 */ 36 public static final IsNotSame<Object, Object> INSTANCE = IsNotSame.<Object, Object>instance(); 37 38 // constructor 39 // ------------------------------------------------------------------------ 40 /** 41 * Create a new IsNotSame. 42 */ 43 public IsNotSame() { 44 } 45 46 // predicate interface 47 // ------------------------------------------------------------------------ 48 /** 49 * {@inheritDoc} 50 */ 51 public boolean test(L left, R right) { 52 return left != right; 53 } 54 55 /** 56 * {@inheritDoc} 57 */ 58 @Override 59 public boolean equals(Object that) { 60 return that instanceof IsNotSame<?, ?>; 61 } 62 63 /** 64 * {@inheritDoc} 65 */ 66 @Override 67 public int hashCode() { 68 return "IsNotSame".hashCode(); 69 } 70 71 /** 72 * {@inheritDoc} 73 */ 74 @Override 75 public String toString() { 76 return "IsNotSame"; 77 } 78 79 // static methods 80 // ------------------------------------------------------------------------ 81 /** 82 * Get an IsNotSame instance. 83 * @param <L> the left argument type. 84 * @param <R> the right argument type. 85 * @return IsNotSame 86 */ 87 public static <L, R> IsNotSame<L, R> instance() { 88 return new IsNotSame<L, R>(); 89 } 90 91 /** 92 * Get an IsNotSame Predicate. 93 * @param <L> the left argument type. 94 * @param <R> the right argument type. 95 * @param object bound comparison object 96 * @return Predicate<L> 97 */ 98 public static <L, R> Predicate<L> as(R object) { 99 return new RightBoundPredicate<L>(new IsNotSame<L, R>(), object); 100 } 101 }