BrightSide Workbench Full Report + Source Code
Interest.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2024 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 package org.turro.interest;
19 
20 import java.util.Objects;
21 import java.util.Optional;
22 import org.turro.entities.IElephantEntity;
23 import org.turro.participation.ParticipationReason;
24 
29 public class Interest {
30 
31  private final ParticipationReason reason;
32  private final IElephantEntity entity;
33  private final boolean reversed;
34 
35  public Interest(ParticipationReason reason, IElephantEntity entity, boolean reversed) {
36  this.reason = reason;
37  this.entity = entity;
38  this.reversed = reversed;
39  }
40 
42  return reason;
43  }
44 
46  return entity;
47  }
48 
49  public boolean isReversed() {
50  return reversed;
51  }
52 
53  public String getLabel() {
54  return Optional.ofNullable(entity)
55  .map(e -> e.getLabel())
56  .orElse("**");
57  }
58 
59  /* Utils */
60 
61  @Override
62  public int hashCode() {
63  int hash = 7;
64  hash = 71 * hash + Objects.hashCode(this.reason);
65  hash = 71 * hash + Objects.hashCode(this.entity.getPath());
66  return hash;
67  }
68 
69  @Override
70  public boolean equals(Object obj) {
71  if (this == obj) {
72  return true;
73  }
74  if (obj == null) {
75  return false;
76  }
77  if (getClass() != obj.getClass()) {
78  return false;
79  }
80  final Interest other = (Interest) obj;
81  if (this.reason != other.reason) {
82  return false;
83  }
84  return Objects.equals(this.entity.getPath(), other.entity.getPath());
85  }
86 
87 }
Interest(ParticipationReason reason, IElephantEntity entity, boolean reversed)
Definition: Interest.java:35
ParticipationReason getReason()
Definition: Interest.java:41
boolean equals(Object obj)
Definition: Interest.java:70
IElephantEntity getEntity()
Definition: Interest.java:45