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 * https://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 */ 017package org.apache.commons.collections4; 018 019import java.util.Comparator; 020 021import org.apache.commons.collections4.map.HashedMap; 022/** 023 * An equation function, which determines equality between objects of type T. 024 * <p> 025 * It is the functional sibling of {@link Comparator}; {@link Equator} is to 026 * {@link Object} as {@link Comparator} is to {@link Comparable}. 027 * </p> 028 * 029 * @param <T> The types of object this {@link Equator} can evaluate. 030 * @since 4.0 031 */ 032public interface Equator<T> { 033 034 /** 035 * Evaluates the two arguments for their equality. 036 * 037 * @param o1 The first object to be equated. 038 * @param o2 The second object to be equated. 039 * @return whether the two objects are equal. 040 */ 041 boolean equate(T o1, T o2); 042 043 /** 044 * Calculates the hash for the object, based on the method of equality used in the equate 045 * method. This is used for classes that delegate their {@link Object#equals(Object) equals(Object)} method to an 046 * Equator (and so must also delegate their {@link Object#hashCode() hashCode()} method), or for implementations 047 * of {@link HashedMap} that use an Equator for the key objects. 048 * 049 * @param o The object to calculate the hash for. 050 * @return The hash of the object. 051 */ 052 int hash(T o); 053}