1 package org
.asamk
.signal
.manager
.api
;
3 import org
.asamk
.signal
.manager
.groups
.GroupId
;
4 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientAddress
;
5 import org
.whispersystems
.signalservice
.api
.push
.SignalServiceAddress
;
6 import org
.whispersystems
.signalservice
.api
.util
.InvalidNumberException
;
7 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
8 import org
.whispersystems
.signalservice
.api
.util
.UuidUtil
;
10 import java
.util
.UUID
;
12 public abstract class RecipientIdentifier
{
14 public static class NoteToSelf
extends RecipientIdentifier
{
16 public static NoteToSelf INSTANCE
= new NoteToSelf();
18 private NoteToSelf() {
22 public abstract static class Single
extends RecipientIdentifier
{
24 public static Single
fromString(String identifier
, String localNumber
) throws InvalidNumberException
{
25 return UuidUtil
.isUuid(identifier
)
26 ?
new Uuid(UUID
.fromString(identifier
))
27 : new Number(PhoneNumberFormatter
.formatNumber(identifier
, localNumber
));
30 public static Single
fromAddress(SignalServiceAddress address
) {
31 return new Uuid(address
.getUuid());
34 public static Single
fromAddress(RecipientAddress address
) {
35 if (address
.getNumber().isPresent()) {
36 return new Number(address
.getNumber().get());
37 } else if (address
.getUuid().isPresent()) {
38 return new Uuid(address
.getUuid().get());
40 throw new AssertionError("RecipientAddress without identifier");
43 public abstract String
getIdentifier();
46 public static class Uuid
extends Single
{
48 public final UUID uuid
;
50 public Uuid(final UUID uuid
) {
55 public boolean equals(final Object o
) {
56 if (this == o
) return true;
57 if (o
== null || getClass() != o
.getClass()) return false;
59 final Uuid uuid1
= (Uuid
) o
;
61 return uuid
.equals(uuid1
.uuid
);
65 public int hashCode() {
66 return uuid
.hashCode();
70 public String
getIdentifier() {
71 return uuid
.toString();
75 public static class Number
extends Single
{
77 public final String number
;
79 public Number(final String number
) {
84 public boolean equals(final Object o
) {
85 if (this == o
) return true;
86 if (o
== null || getClass() != o
.getClass()) return false;
88 final Number number1
= (Number
) o
;
90 return number
.equals(number1
.number
);
94 public int hashCode() {
95 return number
.hashCode();
99 public String
getIdentifier() {
104 public static class Group
extends RecipientIdentifier
{
106 public final GroupId groupId
;
108 public Group(final GroupId groupId
) {
109 this.groupId
= groupId
;
113 public boolean equals(final Object o
) {
114 if (this == o
) return true;
115 if (o
== null || getClass() != o
.getClass()) return false;
117 final Group group
= (Group
) o
;
119 return groupId
.equals(group
.groupId
);
123 public int hashCode() {
124 return groupId
.hashCode();