Update year in copyright lines
[Sone.git] / src / main / java / net / pterodactylus / sone / freenet / wot / Trust.java
1 /*
2  * Sone - Trust.java - Copyright © 2010–2019 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.sone.freenet.wot;
19
20 import static com.google.common.base.Objects.equal;
21
22 import com.google.common.base.Objects;
23
24 /**
25  * Container class for trust in the web of trust.
26  */
27 public class Trust {
28
29         /** Explicitely assigned trust. */
30         private final Integer explicit;
31
32         /** Implicitely calculated trust. */
33         private final Integer implicit;
34
35         /** The distance from the owner of the trust tree. */
36         private final Integer distance;
37
38         /**
39          * Creates a new trust container.
40          *
41          * @param explicit
42          *            The explicit trust
43          * @param implicit
44          *            The implicit trust
45          * @param distance
46          *            The distance
47          */
48         public Trust(Integer explicit, Integer implicit, Integer distance) {
49                 this.explicit = explicit;
50                 this.implicit = implicit;
51                 this.distance = distance;
52         }
53
54         /**
55          * Returns the trust explicitely assigned to an identity.
56          *
57          * @return The explicitely assigned trust, or {@code null} if the identity
58          *         is not in the own identity’s trust tree
59          */
60         public Integer getExplicit() {
61                 return explicit;
62         }
63
64         /**
65          * Returns the implicitely assigned trust, or the calculated trust.
66          *
67          * @return The calculated trust, or {@code null} if the identity is not in
68          *         the own identity’s trust tree
69          */
70         public Integer getImplicit() {
71                 return implicit;
72         }
73
74         /**
75          * Returns the distance of the trusted identity from the trusting identity.
76          *
77          * @return The distance from the own identity, or {@code null} if the
78          *         identity is not in the own identity’s trust tree
79          */
80         public Integer getDistance() {
81                 return distance;
82         }
83
84         @Override
85         public boolean equals(Object object) {
86                 if (!(object instanceof Trust)) {
87                         return false;
88                 }
89                 Trust trust = (Trust) object;
90                 return equal(getExplicit(), trust.getExplicit()) && equal(getImplicit(), trust.getImplicit()) && equal(getDistance(), trust.getDistance());
91         }
92
93         @Override
94         public int hashCode() {
95                 return Objects.hashCode(explicit, implicit, distance);
96         }
97
98         /** {@inheritDoc} */
99         @Override
100         public String toString() {
101                 return getClass().getName() + "[explicit=" + explicit + ",implicit=" + implicit + ",distance=" + distance + "]";
102         }
103
104 }