]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.api.uuid/src/org/argeo/api/uuid/UuidIdentified.java
Merge remote-tracking branch 'origin/unstable' into testing
[lgpl/argeo-commons.git] / org.argeo.api.uuid / src / org / argeo / api / uuid / UuidIdentified.java
1 package org.argeo.api.uuid;
2
3 import java.util.UUID;
4
5 /**
6 * An object identified by a {@link UUID}. Typically used to fasten indexing and
7 * comparisons of objects or records. THe method to implement is {@link #uuid()}
8 * so that any record with an <code>uuid</code> field can easily be enriched
9 * with this interface.
10 */
11 public interface UuidIdentified {
12 /** The UUID identifier. */
13 UUID uuid();
14
15 /** The UUID identifier, for compatibility with beans accessors. */
16 default UUID getUuid() {
17 return uuid();
18 }
19
20 /**
21 * Helper to implement the equals method of an {@link UuidIdentified}.<br/>
22 *
23 * <pre>
24 * &#64;Override
25 * public boolean equals(Object o) {
26 * return UuidIdentified.equals(this, o);
27 * }
28 * </pre>
29 */
30 static boolean equals(UuidIdentified uuidIdentified, Object o) {
31 assert uuidIdentified != null;
32 if (o == null)
33 return false;
34 if (uuidIdentified == o)
35 return true;
36 if (o instanceof UuidIdentified u)
37 return uuidIdentified.uuid().equals(u.uuid());
38 else
39 return false;
40 }
41
42 /**
43 * Helper to implement the hash code method of an {@link UuidIdentified}.<br/>
44 *
45 * <pre>
46 * &#64;Override
47 * public int hashCode() {
48 * return UuidIdentified.hashCode(this);
49 * }
50 * </pre>
51 */
52 static int hashCode(UuidIdentified uuidIdentified) {
53 assert uuidIdentified != null;
54 return uuidIdentified.getUuid().hashCode();
55 }
56
57 }