##### Coverage Report - org.owasp.dependencycheck.dependency.Evidence

Classes in this File | Line Coverage | Branch Coverage | Complexity
Evidence |
48% | 24/49
25% | 10/40
| 2.2941176470588234;2.294
Evidence$Confidence |
100% | 5/5
N/A | N/A
| 2.2941176470588234;2.294

1 |  |
     /*
2 |  |
      * This file is part of dependency-check-core.
3 |  |
      *
4 |  |
      * Dependency-check-core is free software: you can redistribute it and/or modify it
5 |  |
      * under the terms of the GNU General Public License as published by the Free
6 |  |
      * Software Foundation, either version 3 of the License, or (at your option) any
7 |  |
      * later version.
8 |  |
      *
9 |  |
      * Dependency-check-core is distributed in the hope that it will be useful, but
10 |  |
      * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 |  |
      * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 |  |
      * details.
13 |  |
      *
14 |  |
      * You should have received a copy of the GNU General Public License along with
15 |  |
      * dependency-check-core. If not, see http://www.gnu.org/licenses/.
16 |  |
      *
17 |  |
      * Copyright (c) 2012 Jeremy Long. All Rights Reserved.
18 |  |
      */
19 |  |
     package org.owasp.dependencycheck.dependency;
20 |  |
21 |  |
     /**
22 |  |
      * Evidence is a piece of information about a Dependency.
23 |  |
      *
24 |  |
      * @author Jeremy Long (jeremy.long@owasp.org)
25 |  |
      */
26 | 129498 |
     public class Evidence implements Comparable<Evidence> {
27 |  |
28 |  |
         /**
29 |  |
          * The confidence that the evidence is "high" quality.
30 |  |
          */
31 | 76 |
         public enum Confidence {
32 |  |
33 |  |
             /**
34 |  |
              * High confidence evidence.
35 |  |
              */
36 | 1 |
             HIGHEST,
37 |  |
             /**
38 |  |
              * High confidence evidence.
39 |  |
              */
40 | 1 |
             HIGH,
41 |  |
             /**
42 |  |
              * Medium confidence evidence.
43 |  |
              */
44 | 1 |
             MEDIUM,
45 |  |
             /**
46 |  |
              * Low confidence evidence.
47 |  |
              */
48 | 1 |
             LOW
49 |  |
         }
50 |  |
51 |  |
         /**
52 |  |
          * Creates a new Evidence object.
53 |  |
          */
54 | 0 |
         public Evidence() {
55 | 0 |
         }
56 |  |
57 |  |
         /**
58 |  |
          * Creates a new Evidence objects.
59 |  |
          *
60 |  |
          * @param source the source of the evidence.
61 |  |
          * @param name the name of the evidence.
62 |  |
          * @param value the value of the evidence.
63 |  |
          * @param confidence the confidence of the evidence.
64 |  |
          */
65 | 70882 |
         public Evidence(String source, String name, String value, Confidence confidence) {
66 | 70882 |
             this.source = source;
67 | 70882 |
             this.name = name;
68 | 70882 |
             this.value = value;
69 | 70882 |
             this.confidence = confidence;
70 | 70882 |
         }
71 |  |
         /**
72 |  |
          * The name of the evidence.
73 |  |
          */
74 |  |
         private String name;
75 |  |
76 |  |
         /**
77 |  |
          * Get the value of name.
78 |  |
          *
79 |  |
          * @return the value of name
80 |  |
          */
81 |  |
         public String getName() {
82 | 52 |
             return name;
83 |  |
         }
84 |  |
85 |  |
         /**
86 |  |
          * Set the value of name.
87 |  |
          *
88 |  |
          * @param name new value of name
89 |  |
          */
90 |  |
         public void setName(String name) {
91 | 0 |
             this.name = name;
92 | 0 |
         }
93 |  |
         /**
94 |  |
          * The source of the evidence.
95 |  |
          */
96 |  |
         private String source;
97 |  |
98 |  |
         /**
99 |  |
          * Get the value of source.
100 |  |
          *
101 |  |
          * @return the value of source
102 |  |
          */
103 |  |
         public String getSource() {
104 | 41 |
             return source;
105 |  |
         }
106 |  |
107 |  |
         /**
108 |  |
          * Set the value of source.
109 |  |
          *
110 |  |
          * @param source new value of source
111 |  |
          */
112 |  |
         public void setSource(String source) {
113 | 0 |
             this.source = source;
114 | 0 |
         }
115 |  |
         /**
116 |  |
          * The value of the evidence.
117 |  |
          */
118 |  |
         private String value;
119 |  |
120 |  |
         /**
121 |  |
          * Get the value of value.
122 |  |
          *
123 |  |
          * @return the value of value
124 |  |
          */
125 |  |
         public String getValue() {
126 | 6725 |
             used = true;
127 | 6725 |
             return value;
128 |  |
         }
129 |  |
130 |  |
         /**
131 |  |
          * Get the value of value. If setUsed is set to false this call to get will
132 |  |
          * not mark the evidence as used.
133 |  |
          *
134 |  |
          * @param setUsed whether or not this call to getValue should cause the used
135 |  |
          * flag to be updated
136 |  |
          * @return the value of value
137 |  |
          */
138 |  |
         public String getValue(Boolean setUsed) {
139 | 210 |
             used = used || setUsed;
140 | 210 |
             return value;
141 |  |
         }
142 |  |
143 |  |
         /**
144 |  |
          * Set the value of value.
145 |  |
          *
146 |  |
          * @param value new value of value
147 |  |
          */
148 |  |
         public void setValue(String value) {
149 | 0 |
             this.value = value;
150 | 0 |
         }
151 |  |
         /**
152 |  |
          * A value indicating if the Evidence has been "used" (aka read).
153 |  |
          */
154 |  |
         private boolean used;
155 |  |
156 |  |
         /**
157 |  |
          * Get the value of used.
158 |  |
          *
159 |  |
          * @return the value of used
160 |  |
          */
161 |  |
         public boolean isUsed() {
162 | 9273 |
             return used;
163 |  |
         }
164 |  |
165 |  |
         /**
166 |  |
          * Set the value of used.
167 |  |
          *
168 |  |
          * @param used new value of used
169 |  |
          */
170 |  |
         public void setUsed(boolean used) {
171 | 0 |
             this.used = used;
172 | 0 |
         }
173 |  |
         /**
174 |  |
          * The confidence level for the evidence.
175 |  |
          */
176 |  |
         private Confidence confidence;
177 |  |
178 |  |
         /**
179 |  |
          * Get the value of confidence.
180 |  |
          *
181 |  |
          * @return the value of confidence
182 |  |
          */
183 |  |
         public Confidence getConfidence() {
184 | 2551 |
             return confidence;
185 |  |
         }
186 |  |
187 |  |
         /**
188 |  |
          * Set the value of confidence.
189 |  |
          *
190 |  |
          * @param confidence new value of confidence
191 |  |
          */
192 |  |
         public void setConfidence(Confidence confidence) {
193 | 0 |
             this.confidence = confidence;
194 | 0 |
         }
195 |  |
196 |  |
         /**
197 |  |
          * Implements the hashCode for Evidence.
198 |  |
          *
199 |  |
          * @return hash code.
200 |  |
          */
201 |  |
         @Override
202 |  |
         public int hashCode() {
203 | 0 |
             int hash = 3;
204 | 0 |
             hash = 67 * hash + (this.name != null ? this.name.hashCode() : 0);
205 | 0 |
             hash = 67 * hash + (this.source != null ? this.source.hashCode() : 0);
206 | 0 |
             hash = 67 * hash + (this.value != null ? this.value.hashCode() : 0);
207 | 0 |
             hash = 67 * hash + (this.confidence != null ? this.confidence.hashCode() : 0);
208 | 0 |
             return hash;
209 |  |
         }
210 |  |
211 |  |
         /**
212 |  |
          * Implements equals for Evidence.
213 |  |
          *
214 |  |
          * @param that an object to check the equality of.
215 |  |
          * @return whether the two objects are equal.
216 |  |
          */
217 |  |
         @Override
218 |  |
         public boolean equals(Object that) {
219 | 0 |
             if (this == that) {
220 | 0 |
                 return true;
221 |  |
             }
222 | 0 |
             if (!(that instanceof Evidence)) {
223 | 0 |
                 return false;
224 |  |
             }
225 | 0 |
             final Evidence e = (Evidence) that;
226 |  |
227 | 0 |
             return testEquality(name, e.name) && testEquality(source, e.source) && testEquality(value, e.value)
228 |  |
                     && (confidence == null ? e.confidence == null : confidence == e.confidence);
229 |  |
         }
230 |  |
231 |  |
         /**
232 |  |
          * Simple equality test for use within the equals method. This does a case
233 |  |
          * insensitive compare.
234 |  |
          *
235 |  |
          * @param l a string to compare.
236 |  |
          * @param r another string to compare.
237 |  |
          * @return whether the two strings are the same.
238 |  |
          */
239 |  |
         private boolean testEquality(String l, String r) {
240 | 0 |
             return l == null ? r == null : l.equalsIgnoreCase(r);
241 |  |
         }
242 |  |
243 |  |
         /**
244 |  |
          * Implementation of the comparable interface.
245 |  |
          *
246 |  |
          * @param o the evidence being compared
247 |  |
          * @return an integer indicating the ordering of the two objects
248 |  |
          */
249 |  |
         public int compareTo(Evidence o) {
250 | 129498 |
             if (source.equals(o.source)) {
251 | 99433 |
                 if (name.equals(o.name)) {
252 | 99127 |
                     if (value.equals(o.value)) {
253 | 70476 |
                         if (confidence.equals(o.confidence)) {
254 | 70471 |
                             return 0; //they are equal
255 |  |
                         } else {
256 | 5 |
                             return confidence.compareTo(o.confidence);
257 |  |
                         }
258 |  |
                     } else {
259 | 28651 |
                         return value.compareToIgnoreCase(o.value);
260 |  |
                     }
261 |  |
                 } else {
262 | 306 |
                     return name.compareToIgnoreCase(o.name);
263 |  |
                 }
264 |  |
             } else {
265 | 30065 |
                 return source.compareToIgnoreCase(o.source);
266 |  |
             }
267 |  |
         }
268 |  |
     }