[6380] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[2399] | 2 | package org.openstreetmap.josm.data.osm;
|
---|
| 3 |
|
---|
| 4 | /**
|
---|
| 5 | * An interface allowing injection of hashcode and equality implementation
|
---|
| 6 | * based on some inner state of an object for a set.
|
---|
| 7 | * It supports two type parameters to implement effective foreign key implementation
|
---|
| 8 | * inside (@link Storage}, but for basic use, both type parameters are the same.
|
---|
[2512] | 9 | *
|
---|
[2399] | 10 | * For use cases, see {@link Storage}.
|
---|
| 11 | * @author nenik
|
---|
[9243] | 12 | * @param <K> type for hashCode and first equals parameter
|
---|
| 13 | * @param <T> type for second equals parameter
|
---|
[2399] | 14 | */
|
---|
[8510] | 15 | public interface Hash<K, T> {
|
---|
[2512] | 16 |
|
---|
[2399] | 17 | /**
|
---|
| 18 | * Get hashcode for given instance, based on some inner state of the
|
---|
| 19 | * instance. The returned hashcode should remain constant over the time,
|
---|
| 20 | * so it should be based on some instance invariant.
|
---|
[2512] | 21 | *
|
---|
[2399] | 22 | * @param k the object to compute hashcode for
|
---|
| 23 | * @return computed hashcode
|
---|
| 24 | */
|
---|
[8512] | 25 | int getHashCode(K k);
|
---|
[2512] | 26 |
|
---|
[2399] | 27 | /**
|
---|
| 28 | * Compare two instances for semantic or lookup equality. For use cases
|
---|
| 29 | * where it compares different types, refer to {@link Storage}.
|
---|
[2512] | 30 | *
|
---|
[2399] | 31 | * @param k the object to compare
|
---|
| 32 | * @param t the object to compare
|
---|
| 33 | * @return true if the objects are semantically equivalent, or if k
|
---|
| 34 | * uniquely identifies t in given class.
|
---|
| 35 | */
|
---|
[8512] | 36 | boolean equals(K k, T t);
|
---|
[2399] | 37 | }
|
---|