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 * @param <K> type for hashCode and first equals parameter 013 * @param <T> type for second equals parameter 014 */ 015public interface Hash<K, T> { 016 017 /** 018 * Get hashcode for given instance, based on some inner state of the 019 * instance. The returned hashcode should remain constant over the time, 020 * so it should be based on some instance invariant. 021 * 022 * @param k the object to compute hashcode for 023 * @return computed hashcode 024 */ 025 int getHashCode(K k); 026 027 /** 028 * Compare two instances for semantic or lookup equality. For use cases 029 * where it compares different types, refer to {@link Storage}. 030 * 031 * @param k the object to compare 032 * @param t the object to compare 033 * @return true if the objects are semantically equivalent, or if k 034 * uniquely identifies t in given class. 035 */ 036 boolean equals(K k, T t); 037}