1 | // License: GPL. For details, see LICENSE file.
|
---|
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.
|
---|
9 | *
|
---|
10 | * For use cases, see {@link Storage}.
|
---|
11 | * @author nenik
|
---|
12 | */
|
---|
13 | public interface Hash<K,T> {
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Get hashcode for given instance, based on some inner state of the
|
---|
17 | * instance. The returned hashcode should remain constant over the time,
|
---|
18 | * so it should be based on some instance invariant.
|
---|
19 | *
|
---|
20 | * @param k the object to compute hashcode for
|
---|
21 | * @return computed hashcode
|
---|
22 | */
|
---|
23 | public int getHashCode(K k);
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Compare two instances for semantic or lookup equality. For use cases
|
---|
27 | * where it compares different types, refer to {@link Storage}.
|
---|
28 | *
|
---|
29 | * @param k the object to compare
|
---|
30 | * @param t the object to compare
|
---|
31 | * @return true if the objects are semantically equivalent, or if k
|
---|
32 | * uniquely identifies t in given class.
|
---|
33 | */
|
---|
34 | public boolean equals(K k, T t);
|
---|
35 | }
|
---|