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