1 package org
.asamk
.signal
.manager
.storage
.recipients
;
3 import org
.whispersystems
.signalservice
.api
.push
.SignalServiceAddress
;
4 import org
.whispersystems
.signalservice
.api
.util
.UuidUtil
;
6 import java
.util
.Optional
;
9 public class RecipientAddress
{
11 private final Optional
<UUID
> uuid
;
12 private final Optional
<String
> e164
;
15 * Construct a RecipientAddress.
17 * @param uuid The UUID of the user, if available.
18 * @param e164 The phone number of the user, if available.
20 public RecipientAddress(Optional
<UUID
> uuid
, Optional
<String
> e164
) {
21 uuid
= uuid
.isPresent() && uuid
.get().equals(UuidUtil
.UNKNOWN_UUID
) ? Optional
.empty() : uuid
;
22 if (!uuid
.isPresent() && !e164
.isPresent()) {
23 throw new AssertionError("Must have either a UUID or E164 number!");
30 public RecipientAddress(UUID uuid
, String e164
) {
31 this(Optional
.ofNullable(uuid
), Optional
.ofNullable(e164
));
34 public RecipientAddress(SignalServiceAddress address
) {
35 this(Optional
.of(address
.getUuid()), Optional
.ofNullable(address
.getNumber().orNull()));
38 public RecipientAddress(UUID uuid
) {
39 this(Optional
.of(uuid
), Optional
.empty());
42 public Optional
<String
> getNumber() {
46 public Optional
<UUID
> getUuid() {
50 public String
getIdentifier() {
51 if (uuid
.isPresent()) {
52 return uuid
.get().toString();
53 } else if (e164
.isPresent()) {
56 throw new AssertionError("Given the checks in the constructor, this should not be possible.");
60 public String
getLegacyIdentifier() {
61 if (e164
.isPresent()) {
63 } else if (uuid
.isPresent()) {
64 return uuid
.get().toString();
66 throw new AssertionError("Given the checks in the constructor, this should not be possible.");
70 public boolean matches(RecipientAddress other
) {
71 return (uuid
.isPresent() && other
.uuid
.isPresent() && uuid
.get().equals(other
.uuid
.get())) || (
72 e164
.isPresent() && other
.e164
.isPresent() && e164
.get().equals(other
.e164
.get())
76 public SignalServiceAddress
toSignalServiceAddress() {
77 return new SignalServiceAddress(uuid
.orElse(UuidUtil
.UNKNOWN_UUID
),
78 org
.whispersystems
.libsignal
.util
.guava
.Optional
.fromNullable(e164
.orElse(null)));
82 public boolean equals(final Object o
) {
83 if (this == o
) return true;
84 if (o
== null || getClass() != o
.getClass()) return false;
86 final RecipientAddress that
= (RecipientAddress
) o
;
88 if (!uuid
.equals(that
.uuid
)) return false;
89 return e164
.equals(that
.e164
);
93 public int hashCode() {
94 int result
= uuid
.hashCode();
95 result
= 31 * result
+ e164
.hashCode();