1 package org
.asamk
.signal
.manager
.api
;
3 import org
.asamk
.signal
.manager
.groups
.GroupId
;
4 import org
.whispersystems
.signalservice
.api
.push
.SignalServiceAddress
;
5 import org
.whispersystems
.signalservice
.api
.util
.InvalidNumberException
;
6 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
7 import org
.whispersystems
.signalservice
.api
.util
.UuidUtil
;
11 public abstract class RecipientIdentifier
{
13 public static class NoteToSelf
extends RecipientIdentifier
{
16 public boolean equals(final Object obj
) {
17 return obj
instanceof NoteToSelf
;
21 public int hashCode() {
26 public abstract static class Single
extends RecipientIdentifier
{
28 public static Single
fromString(String identifier
, String localNumber
) throws InvalidNumberException
{
29 return UuidUtil
.isUuid(identifier
)
30 ?
new Uuid(UUID
.fromString(identifier
))
31 : new Number(PhoneNumberFormatter
.formatNumber(identifier
, localNumber
));
34 public static Single
fromAddress(SignalServiceAddress address
) {
35 return address
.getUuid().isPresent()
36 ?
new Uuid(address
.getUuid().get())
37 : new Number(address
.getNumber().get());
41 public static class Uuid
extends Single
{
43 public final UUID uuid
;
45 public Uuid(final UUID uuid
) {
50 public boolean equals(final Object o
) {
51 if (this == o
) return true;
52 if (o
== null || getClass() != o
.getClass()) return false;
54 final Uuid uuid1
= (Uuid
) o
;
56 return uuid
.equals(uuid1
.uuid
);
60 public int hashCode() {
61 return uuid
.hashCode();
65 public static class Number
extends Single
{
67 public final String number
;
69 public Number(final String number
) {
74 public boolean equals(final Object o
) {
75 if (this == o
) return true;
76 if (o
== null || getClass() != o
.getClass()) return false;
78 final Number number1
= (Number
) o
;
80 return number
.equals(number1
.number
);
84 public int hashCode() {
85 return number
.hashCode();
89 public static class Group
extends RecipientIdentifier
{
91 public final GroupId groupId
;
93 public Group(final GroupId groupId
) {
94 this.groupId
= groupId
;
98 public boolean equals(final Object o
) {
99 if (this == o
) return true;
100 if (o
== null || getClass() != o
.getClass()) return false;
102 final Group group
= (Group
) o
;
104 return groupId
.equals(group
.groupId
);
108 public int hashCode() {
109 return groupId
.hashCode();