1 package org
.asamk
.signal
.manager
.storage
.recipients
;
3 import org
.whispersystems
.signalservice
.api
.push
.SignalServiceAddress
;
5 import java
.util
.Optional
;
8 public class RecipientAddress
{
10 public static final UUID UNKNOWN_UUID
= new UUID(0, 0);
12 private final Optional
<UUID
> uuid
;
13 private final Optional
<String
> e164
;
16 * Construct a RecipientAddress.
18 * @param uuid The UUID of the user, if available.
19 * @param e164 The phone number of the user, if available.
21 public RecipientAddress(Optional
<UUID
> uuid
, Optional
<String
> e164
) {
22 uuid
= uuid
.isPresent() && uuid
.get().equals(UNKNOWN_UUID
) ? Optional
.empty() : uuid
;
23 if (uuid
.isEmpty() && e164
.isEmpty()) {
24 throw new AssertionError("Must have either a UUID or E164 number!");
31 public RecipientAddress(UUID uuid
, String e164
) {
32 this(Optional
.ofNullable(uuid
), Optional
.ofNullable(e164
));
35 public RecipientAddress(SignalServiceAddress address
) {
36 this(Optional
.of(address
.getUuid()), Optional
.ofNullable(address
.getNumber().orNull()));
39 public RecipientAddress(UUID uuid
) {
40 this(Optional
.of(uuid
), Optional
.empty());
43 public Optional
<String
> getNumber() {
47 public Optional
<UUID
> getUuid() {
51 public String
getIdentifier() {
52 if (uuid
.isPresent()) {
53 return uuid
.get().toString();
54 } else if (e164
.isPresent()) {
57 throw new AssertionError("Given the checks in the constructor, this should not be possible.");
61 public String
getLegacyIdentifier() {
62 if (e164
.isPresent()) {
64 } else if (uuid
.isPresent()) {
65 return uuid
.get().toString();
67 throw new AssertionError("Given the checks in the constructor, this should not be possible.");
71 public boolean matches(RecipientAddress other
) {
72 return (uuid
.isPresent() && other
.uuid
.isPresent() && uuid
.get().equals(other
.uuid
.get())) || (
73 e164
.isPresent() && other
.e164
.isPresent() && e164
.get().equals(other
.e164
.get())
77 public SignalServiceAddress
toSignalServiceAddress() {
78 return new SignalServiceAddress(uuid
.orElse(UNKNOWN_UUID
),
79 org
.whispersystems
.libsignal
.util
.guava
.Optional
.fromNullable(e164
.orElse(null)));
83 public boolean equals(final Object o
) {
84 if (this == o
) return true;
85 if (o
== null || getClass() != o
.getClass()) return false;
87 final RecipientAddress that
= (RecipientAddress
) o
;
89 if (!uuid
.equals(that
.uuid
)) return false;
90 return e164
.equals(that
.e164
);
94 public int hashCode() {
95 int result
= uuid
.hashCode();
96 result
= 31 * result
+ e164
.hashCode();