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 if (!uuid
.isPresent() && !e164
.isPresent()) {
22 throw new AssertionError("Must have either a UUID or E164 number!");
29 public RecipientAddress(UUID uuid
, String e164
) {
30 this(Optional
.ofNullable(uuid
), Optional
.ofNullable(e164
));
33 public RecipientAddress(SignalServiceAddress address
) {
34 this.uuid
= Optional
.of(address
.getUuid());
35 this.e164
= Optional
.ofNullable(address
.getNumber().orNull());
38 public RecipientAddress(UUID uuid
) {
39 this.uuid
= Optional
.of(uuid
);
40 this.e164
= 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 boolean matches(RecipientAddress other
) {
62 return (uuid
.isPresent() && other
.uuid
.isPresent() && uuid
.get().equals(other
.uuid
.get())) || (
63 e164
.isPresent() && other
.e164
.isPresent() && e164
.get().equals(other
.e164
.get())
67 public SignalServiceAddress
toSignalServiceAddress() {
68 return new SignalServiceAddress(uuid
.orElse(UuidUtil
.UNKNOWN_UUID
),
69 org
.whispersystems
.libsignal
.util
.guava
.Optional
.fromNullable(e164
.orElse(null)));
73 public boolean equals(final Object o
) {
74 if (this == o
) return true;
75 if (o
== null || getClass() != o
.getClass()) return false;
77 final RecipientAddress that
= (RecipientAddress
) o
;
79 if (!uuid
.equals(that
.uuid
)) return false;
80 return e164
.equals(that
.e164
);
84 public int hashCode() {
85 int result
= uuid
.hashCode();
86 result
= 31 * result
+ e164
.hashCode();