BrightSide Workbench Full Report + Source Code
ProcedenceId.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.alliance.db.entities;
20 
21 import java.io.Serializable;
22 import java.util.Objects;
23 import javax.persistence.Embeddable;
24 import org.turro.string.Strings;
25 import org.turro.math.Zero;
26 import org.turro.plugin.contacts.CompoundId;
27 import org.turro.ws.WsMember;
28 import org.turro.ws.service.server.Clients;
29 
34 @Embeddable
35 public class ProcedenceId implements Serializable {
36 
37  private String entityId;
38  private Long memberId;
39 
40  public String getEntityId() {
41  return entityId;
42  }
43 
44  public void setEntityId(String entityId) {
45  this.entityId = entityId;
46  }
47 
48  public Long getMemberId() {
49  return memberId;
50  }
51 
52  public void setMemberId(Long memberId) {
53  this.memberId = memberId;
54  }
55 
56  /* Stringify */
57 
58  public String stringify() {
59  return new CompoundId(entityId, memberId).stringify();
60  }
61 
62  public static ProcedenceId from(String id) {
63  CompoundId pid = CompoundId.from(id);
64  if(pid != null) {
65  ProcedenceId pi = new ProcedenceId();
66  pi.entityId = pid.getEntityId();
67  pi.memberId = pid.getMemberId();
68  return pi;
69  }
70  return null;
71  }
72 
73  /* Utils */
74 
75  public boolean isEmpty() {
76  return Strings.isBlank(entityId) || Zero.orNull(memberId);
77  }
78 
79  public WsMember getMember() {
80  return Clients.getMember(memberId);
81  }
82 
83  @Override
84  public int hashCode() {
85  int hash = 7;
86  hash = 67 * hash + Objects.hashCode(this.entityId);
87  hash = 67 * hash + Objects.hashCode(this.memberId);
88  return hash;
89  }
90 
91  @Override
92  public boolean equals(Object obj) {
93  if (this == obj) {
94  return true;
95  }
96  if (obj == null) {
97  return false;
98  }
99  if (getClass() != obj.getClass()) {
100  return false;
101  }
102  final ProcedenceId other = (ProcedenceId) obj;
103  if (!Objects.equals(this.entityId, other.entityId)) {
104  return false;
105  }
106  return Objects.equals(this.memberId, other.memberId);
107  }
108 
109 }
static ProcedenceId from(String id)
static boolean orNull(Number value)
Definition: Zero.java:26
static CompoundId from(String id)
Definition: CompoundId.java:51