001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.data.osm;
003
004/**
005 * An interface allowing injection of hashcode and equality implementation
006 * based on some inner state of an object for a set.
007 * It supports two type parameters to implement effective foreign key implementation
008 * inside (@link Storage}, but for basic use, both type parameters are the same.
009 *
010 * For use cases, see {@link Storage}.
011 * @author nenik
012 */
013public interface Hash<K,T> {
014
015    /**
016     * Get hashcode for given instance, based on some inner state of the
017     * instance. The returned hashcode should remain constant over the time,
018     * so it should be based on some instance invariant.
019     *
020     * @param k the object to compute hashcode for
021     * @return computed hashcode
022     */
023    public int getHashCode(K k);
024
025    /**
026     * Compare two instances for semantic or lookup equality. For use cases
027     * where it compares different types, refer to {@link Storage}.
028     *
029     * @param k the object to compare
030     * @param t the object to compare
031     * @return true if the objects are semantically equivalent, or if k
032     * uniquely identifies t in given class.
033     */
034    public boolean equals(K k, T t);
035}