| 1 | /* |
|---|
| 2 | * JOSMng - a Java Open Street Map editor, the next generation. |
|---|
| 3 | * |
|---|
| 4 | * Copyright (C) 2008 Petr Nejedly <P.Nejedly@sh.cvut.cz> |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | |
|---|
| 16 | * You should have received a copy of the GNU General Public License along |
|---|
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
|---|
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | package org.openstreetmap.josm.data.osm; |
|---|
| 22 | |
|---|
| 23 | /** |
|---|
| 24 | * An interface allowing injection of hashcode and equality implementation |
|---|
| 25 | * based on some inner state of an object for a set. |
|---|
| 26 | * It supports two type parameters to implement effective foreign key implementation |
|---|
| 27 | * inside (@link Storage}, but for basic use, both type parameters are the same. |
|---|
| 28 | * |
|---|
| 29 | * For use cases, see {@link Storage}. |
|---|
| 30 | * @author nenik |
|---|
| 31 | */ |
|---|
| 32 | public interface Hash<K,T> { |
|---|
| 33 | |
|---|
| 34 | /** |
|---|
| 35 | * Get hashcode for given instance, based on some inner state of the |
|---|
| 36 | * instance. The returned hashcode should remain constant over the time, |
|---|
| 37 | * so it should be based on some instance invariant. |
|---|
| 38 | * |
|---|
| 39 | * @param k the object to compute hashcode for |
|---|
| 40 | * @return computed hashcode |
|---|
| 41 | */ |
|---|
| 42 | public int getHashCode(K k); |
|---|
| 43 | |
|---|
| 44 | /** |
|---|
| 45 | * Compare two instances for semantic or lookup equality. For use cases |
|---|
| 46 | * where it compares different types, refer to {@link Storage}. |
|---|
| 47 | * |
|---|
| 48 | * @param k the object to compare |
|---|
| 49 | * @param t the object to compare |
|---|
| 50 | * @return true if the objects are semantically equivalent, or if k |
|---|
| 51 | * uniquely identifies t in given class. |
|---|
| 52 | */ |
|---|
| 53 | public boolean equals(K k, T t); |
|---|
| 54 | } |
|---|