| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Evidence |
|
| 2.2941176470588234;2.294 |
| 1 | /* | |
| 2 | * This file is part of dependency-check-core. | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | * | |
| 16 | * Copyright (c) 2012 Jeremy Long. All Rights Reserved. | |
| 17 | */ | |
| 18 | package org.owasp.dependencycheck.dependency; | |
| 19 | ||
| 20 | /** | |
| 21 | * Evidence is a piece of information about a Dependency. | |
| 22 | * | |
| 23 | * @author Jeremy Long <jeremy.long@owasp.org> | |
| 24 | */ | |
| 25 | 121449 | public class Evidence implements Comparable<Evidence> { |
| 26 | ||
| 27 | /** | |
| 28 | * Creates a new Evidence object. | |
| 29 | */ | |
| 30 | 0 | public Evidence() { |
| 31 | 0 | } |
| 32 | ||
| 33 | /** | |
| 34 | * Creates a new Evidence objects. | |
| 35 | * | |
| 36 | * @param source the source of the evidence. | |
| 37 | * @param name the name of the evidence. | |
| 38 | * @param value the value of the evidence. | |
| 39 | * @param confidence the confidence of the evidence. | |
| 40 | */ | |
| 41 | 70882 | public Evidence(String source, String name, String value, Confidence confidence) { |
| 42 | 70882 | this.source = source; |
| 43 | 70882 | this.name = name; |
| 44 | 70882 | this.value = value; |
| 45 | 70882 | this.confidence = confidence; |
| 46 | 70882 | } |
| 47 | /** | |
| 48 | * The name of the evidence. | |
| 49 | */ | |
| 50 | private String name; | |
| 51 | ||
| 52 | /** | |
| 53 | * Get the value of name. | |
| 54 | * | |
| 55 | * @return the value of name | |
| 56 | */ | |
| 57 | public String getName() { | |
| 58 | 52 | return name; |
| 59 | } | |
| 60 | ||
| 61 | /** | |
| 62 | * Set the value of name. | |
| 63 | * | |
| 64 | * @param name new value of name | |
| 65 | */ | |
| 66 | public void setName(String name) { | |
| 67 | 0 | this.name = name; |
| 68 | 0 | } |
| 69 | /** | |
| 70 | * The source of the evidence. | |
| 71 | */ | |
| 72 | private String source; | |
| 73 | ||
| 74 | /** | |
| 75 | * Get the value of source. | |
| 76 | * | |
| 77 | * @return the value of source | |
| 78 | */ | |
| 79 | public String getSource() { | |
| 80 | 41 | return source; |
| 81 | } | |
| 82 | ||
| 83 | /** | |
| 84 | * Set the value of source. | |
| 85 | * | |
| 86 | * @param source new value of source | |
| 87 | */ | |
| 88 | public void setSource(String source) { | |
| 89 | 0 | this.source = source; |
| 90 | 0 | } |
| 91 | /** | |
| 92 | * The value of the evidence. | |
| 93 | */ | |
| 94 | private String value; | |
| 95 | ||
| 96 | /** | |
| 97 | * Get the value of value. | |
| 98 | * | |
| 99 | * @return the value of value | |
| 100 | */ | |
| 101 | public String getValue() { | |
| 102 | 6806 | used = true; |
| 103 | 6806 | return value; |
| 104 | } | |
| 105 | ||
| 106 | /** | |
| 107 | * Get the value of value. If setUsed is set to false this call to get will not mark the evidence as used. | |
| 108 | * | |
| 109 | * @param setUsed whether or not this call to getValue should cause the used flag to be updated | |
| 110 | * @return the value of value | |
| 111 | */ | |
| 112 | public String getValue(Boolean setUsed) { | |
| 113 | 210 | used = used || setUsed; |
| 114 | 210 | return value; |
| 115 | } | |
| 116 | ||
| 117 | /** | |
| 118 | * Set the value of value. | |
| 119 | * | |
| 120 | * @param value new value of value | |
| 121 | */ | |
| 122 | public void setValue(String value) { | |
| 123 | 0 | this.value = value; |
| 124 | 0 | } |
| 125 | /** | |
| 126 | * A value indicating if the Evidence has been "used" (aka read). | |
| 127 | */ | |
| 128 | private boolean used; | |
| 129 | ||
| 130 | /** | |
| 131 | * Get the value of used. | |
| 132 | * | |
| 133 | * @return the value of used | |
| 134 | */ | |
| 135 | public boolean isUsed() { | |
| 136 | 9313 | return used; |
| 137 | } | |
| 138 | ||
| 139 | /** | |
| 140 | * Set the value of used. | |
| 141 | * | |
| 142 | * @param used new value of used | |
| 143 | */ | |
| 144 | public void setUsed(boolean used) { | |
| 145 | 0 | this.used = used; |
| 146 | 0 | } |
| 147 | /** | |
| 148 | * The confidence level for the evidence. | |
| 149 | */ | |
| 150 | private Confidence confidence; | |
| 151 | ||
| 152 | /** | |
| 153 | * Get the value of confidence. | |
| 154 | * | |
| 155 | * @return the value of confidence | |
| 156 | */ | |
| 157 | public Confidence getConfidence() { | |
| 158 | 2873 | return confidence; |
| 159 | } | |
| 160 | ||
| 161 | /** | |
| 162 | * Set the value of confidence. | |
| 163 | * | |
| 164 | * @param confidence new value of confidence | |
| 165 | */ | |
| 166 | public void setConfidence(Confidence confidence) { | |
| 167 | 0 | this.confidence = confidence; |
| 168 | 0 | } |
| 169 | ||
| 170 | /** | |
| 171 | * Implements the hashCode for Evidence. | |
| 172 | * | |
| 173 | * @return hash code. | |
| 174 | */ | |
| 175 | @Override | |
| 176 | public int hashCode() { | |
| 177 | 0 | int hash = 3; |
| 178 | 0 | hash = 67 * hash + (this.name != null ? this.name.hashCode() : 0); |
| 179 | 0 | hash = 67 * hash + (this.source != null ? this.source.hashCode() : 0); |
| 180 | 0 | hash = 67 * hash + (this.value != null ? this.value.hashCode() : 0); |
| 181 | 0 | hash = 67 * hash + (this.confidence != null ? this.confidence.hashCode() : 0); |
| 182 | 0 | return hash; |
| 183 | } | |
| 184 | ||
| 185 | /** | |
| 186 | * Implements equals for Evidence. | |
| 187 | * | |
| 188 | * @param that an object to check the equality of. | |
| 189 | * @return whether the two objects are equal. | |
| 190 | */ | |
| 191 | @Override | |
| 192 | public boolean equals(Object that) { | |
| 193 | 0 | if (this == that) { |
| 194 | 0 | return true; |
| 195 | } | |
| 196 | 0 | if (!(that instanceof Evidence)) { |
| 197 | 0 | return false; |
| 198 | } | |
| 199 | 0 | final Evidence e = (Evidence) that; |
| 200 | ||
| 201 | 0 | return testEquality(name, e.name) && testEquality(source, e.source) && testEquality(value, e.value) |
| 202 | && (confidence == null ? e.confidence == null : confidence == e.confidence); | |
| 203 | } | |
| 204 | ||
| 205 | /** | |
| 206 | * Simple equality test for use within the equals method. This does a case insensitive compare. | |
| 207 | * | |
| 208 | * @param l a string to compare. | |
| 209 | * @param r another string to compare. | |
| 210 | * @return whether the two strings are the same. | |
| 211 | */ | |
| 212 | private boolean testEquality(String l, String r) { | |
| 213 | 0 | return l == null ? r == null : l.equalsIgnoreCase(r); |
| 214 | } | |
| 215 | ||
| 216 | /** | |
| 217 | * Implementation of the comparable interface. | |
| 218 | * | |
| 219 | * @param o the evidence being compared | |
| 220 | * @return an integer indicating the ordering of the two objects | |
| 221 | */ | |
| 222 | public int compareTo(Evidence o) { | |
| 223 | 121449 | if (source.equals(o.source)) { |
| 224 | 99756 | if (name.equals(o.name)) { |
| 225 | 99453 | if (value.equals(o.value)) { |
| 226 | 70548 | if (confidence.equals(o.confidence)) { |
| 227 | 70543 | return 0; //they are equal |
| 228 | } else { | |
| 229 | 5 | return confidence.compareTo(o.confidence); |
| 230 | } | |
| 231 | } else { | |
| 232 | 28905 | return value.compareToIgnoreCase(o.value); |
| 233 | } | |
| 234 | } else { | |
| 235 | 303 | return name.compareToIgnoreCase(o.name); |
| 236 | } | |
| 237 | } else { | |
| 238 | 21693 | return source.compareToIgnoreCase(o.source); |
| 239 | } | |
| 240 | } | |
| 241 | } |