001    /*
002     *  JOSMng - a Java Open Street Map editor, the next generation.
003     *
004     *  Copyright (C) 2008 Petr Nejedly <P.Nejedly@sh.cvut.cz>
005     *
006     *  This program is free software; you can redistribute it and/or modify
007     *  it under the terms of the GNU General Public License as published by
008     *  the Free Software Foundation; either version 2 of the License, or
009     *  (at your option) any later version.
010     *
011     *  This program is distributed in the hope that it will be useful,
012     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014     *  GNU General Public License for more details.
015    
016     *  You should have received a copy of the GNU General Public License along
017     *  with this program; if not, write to the Free Software Foundation, Inc.,
018     *  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
019     */
020    
021    package org.openstreetmap.josm.data.osm;
022    
023    /**
024     * An interface allowing injection of hashcode and equality implementation
025     * based on some inner state of an object for a set.
026     * It supports two type parameters to implement effective foreign key implementation
027     * inside (@link Storage}, but for basic use, both type parameters are the same.
028     *
029     * For use cases, see {@link Storage}.
030     * @author nenik
031     */
032    public interface Hash<K,T> {
033    
034        /**
035         * Get hashcode for given instance, based on some inner state of the
036         * instance. The returned hashcode should remain constant over the time,
037         * so it should be based on some instance invariant.
038         *
039         * @param k the object to compute hashcode for
040         * @return computed hashcode
041         */
042        public int getHashCode(K k);
043    
044        /**
045         * Compare two instances for semantic or lookup equality. For use cases
046         * where it compares different types, refer to {@link Storage}.
047         *
048         * @param k the object to compare
049         * @param t the object to compare
050         * @return true if the objects are semantically equivalent, or if k
051         * uniquely identifies t in given class.
052         */
053        public boolean equals(K k, T t);
054    }