]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.api.uuid/src/org/argeo/api/uuid/UuidHolder.java
1 package org
.argeo
.api
.uuid
;
3 import java
.io
.Serializable
;
4 import java
.util
.Objects
;
6 import java
.util
.function
.Supplier
;
9 * An immutable wrapper for an {@link UUID}, which can be used as a base for a
10 * derivation hierarchy, while strongly enforcing semantic equality with the
11 * underlying {@link UUID}. It is therefore immutable, and all base methods are
12 * directly and trivially based on {@link UUID} methods; they do represent the
13 * same unique "thing" (be it an entity, a point in time, etc.), consistently
14 * with the fundamental concept of uuid.
16 public class UuidHolder
implements Supplier
<UUID
>, Serializable
{
17 private static final long serialVersionUID
= APM
.SERIAL
;
20 * The wrapped {@link UUID}. Protected rather than private, since it is
21 * immutable and a {@link UUID} is itself immutable.
23 protected final UUID uuid
;
26 * Constructs a new {@link UuidHolder} based on this uuid.
28 * @param uuid the UUID to wrap, cannot be null.
29 * @throws NullPointerException if the provided uuid is null.
31 protected UuidHolder(UUID uuid
) {
32 Objects
.requireNonNull(uuid
, "UUID cannot be null");
36 /** The wrapped {@link UUID}. */
37 public final UUID
getUuid() {
41 /** The wrapped {@link UUID}. */
43 public final UUID
get() {
47 /** Calls {@link UUID#hashCode()} on the wrapped {@link UUID}. */
49 public final int hashCode() {
50 return uuid
.hashCode();
54 * Equals only with non-null {@link UuidHolder} if and only if their wrapped
55 * uuid are equals by calling {@link UUID#equals(Object)}.
58 public final boolean equals(Object obj
) {
59 if (obj
== null || !(obj
instanceof UuidHolder
))
61 UuidHolder typedUuid
= (UuidHolder
) obj
;
62 return uuid
.equals(typedUuid
.uuid
);
65 /** Calls {@link UUID#toString()} on the wrapped {@link UUID}. */
67 public final String
toString() {
68 return uuid
.toString();