BrightSide Workbench Full Report + Source Code
CompoundId.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.plugin.contacts;
20 
21 import org.turro.string.Strings;
22 
27 public class CompoundId {
28 
29  private static final String ID_SEPARATOR = "##";
30 
31  private final String entityId;
32  private final long memberId;
33 
34  public CompoundId(String entityId, long memberId) {
35  this.entityId = entityId;
36  this.memberId = memberId;
37  }
38 
39  public String stringify() {
40  return entityId + ID_SEPARATOR + Long.toString(memberId);
41  }
42 
43  public String getEntityId() {
44  return entityId;
45  }
46 
47  public long getMemberId() {
48  return memberId;
49  }
50 
51  public static CompoundId from(String id) {
52  if(!Strings.isBlank(id)) {
53  String parts[] = id.split(ID_SEPARATOR);
54  if(parts.length == 2) {
55  return new CompoundId(parts[0], Long.valueOf(parts[1]));
56  }
57  }
58  return null;
59  }
60 
61  public static boolean isOutsiderId(String id) {
62  return isOutsider(id);
63  }
64 
65  public static boolean isOutsider(Object object) {
66  if(object instanceof String) {
67  return !Strings.isBlank((String) object) && ((String) object).matches("[^#]*##[0-9]+");
68  } else if(object instanceof IContact) {
69  return ((IContact) object).isOutsider();
70  }
71  return false;
72  }
73 
74 }
static boolean isOutsiderId(String id)
Definition: CompoundId.java:61
static boolean isOutsider(Object object)
Definition: CompoundId.java:65
CompoundId(String entityId, long memberId)
Definition: CompoundId.java:34
static CompoundId from(String id)
Definition: CompoundId.java:51