7b18888e2021cfe6b31177d16f16523e3b51e2a6
[Sone.git] / src / main / java / net / pterodactylus / sone / freenet / wot / Trust.java
1 /*
2  * Sone - Trust.java - Copyright © 2010–2016 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  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
28  */
29 public class Trust {
30
31         /** Explicitely assigned trust. */
32         private final Integer explicit;
33
34         /** Implicitely calculated trust. */
35         private final Integer implicit;
36
37         /** The distance from the owner of the trust tree. */
38         private final Integer distance;
39
40         /**
41          * Creates a new trust container.
42          *
43          * @param explicit
44          *            The explicit trust
45          * @param implicit
46          *            The implicit trust
47          * @param distance
48          *            The distance
49          */
50         public Trust(Integer explicit, Integer implicit, Integer distance) {
51                 this.explicit = explicit;
52                 this.implicit = implicit;
53                 this.distance = distance;
54         }
55
56         /**
57          * Returns the trust explicitely assigned to an identity.
58          *
59          * @return The explicitely assigned trust, or {@code null} if the identity
60          *         is not in the own identity’s trust tree
61          */
62         public Integer getExplicit() {
63                 return explicit;
64         }
65
66         /**
67          * Returns the implicitely assigned trust, or the calculated trust.
68          *
69          * @return The calculated trust, or {@code null} if the identity is not in
70          *         the own identity’s trust tree
71          */
72         public Integer getImplicit() {
73                 return implicit;
74         }
75
76         /**
77          * Returns the distance of the trusted identity from the trusting identity.
78          *
79          * @return The distance from the own identity, or {@code null} if the
80          *         identity is not in the own identity’s trust tree
81          */
82         public Integer getDistance() {
83                 return distance;
84         }
85
86         @Override
87         public boolean equals(Object object) {
88                 if (!(object instanceof Trust)) {
89                         return false;
90                 }
91                 Trust trust = (Trust) object;
92                 return equal(getExplicit(), trust.getExplicit()) && equal(getImplicit(), trust.getImplicit()) && equal(getDistance(), trust.getDistance());
93         }
94
95         @Override
96         public int hashCode() {
97                 return Objects.hashCode(explicit, implicit, distance);
98         }
99
100         /** {@inheritDoc} */
101         @Override
102         public String toString() {
103                 return getClass().getName() + "[explicit=" + explicit + ",implicit=" + implicit + ",distance=" + distance + "]";
104         }
105
106 }