| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Reference |
|
| 3.4444444444444446;3.444 |
| 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 | import java.io.Serializable; | |
| 22 | ||
| 23 | /** | |
| 24 | * An external reference for a vulnerability. This contains a name, URL, and a | |
| 25 | * source. | |
| 26 | * | |
| 27 | * @author Jeremy Long (jeremy.long@owasp.org) | |
| 28 | */ | |
| 29 | 1198 | public class Reference implements Serializable, Comparable<Reference> { |
| 30 | ||
| 31 | /** | |
| 32 | * the serial version uid. | |
| 33 | */ | |
| 34 | private static final long serialVersionUID = -3444464824563008021L; | |
| 35 | /** | |
| 36 | * The name of the reference. | |
| 37 | */ | |
| 38 | private String name; | |
| 39 | ||
| 40 | /** | |
| 41 | * Get the value of name. | |
| 42 | * | |
| 43 | * @return the value of name | |
| 44 | */ | |
| 45 | public String getName() { | |
| 46 | 208 | return name; |
| 47 | } | |
| 48 | ||
| 49 | /** | |
| 50 | * Set the value of name. | |
| 51 | * | |
| 52 | * @param name new value of name | |
| 53 | */ | |
| 54 | public void setName(String name) { | |
| 55 | 391 | this.name = name; |
| 56 | 391 | } |
| 57 | /** | |
| 58 | * the url for the reference. | |
| 59 | */ | |
| 60 | private String url; | |
| 61 | ||
| 62 | /** | |
| 63 | * Get the value of url. | |
| 64 | * | |
| 65 | * @return the value of url | |
| 66 | */ | |
| 67 | public String getUrl() { | |
| 68 | 208 | return url; |
| 69 | } | |
| 70 | ||
| 71 | /** | |
| 72 | * Set the value of url. | |
| 73 | * | |
| 74 | * @param url new value of url | |
| 75 | */ | |
| 76 | public void setUrl(String url) { | |
| 77 | 391 | this.url = url; |
| 78 | 391 | } |
| 79 | /** | |
| 80 | * the source of the reference. | |
| 81 | */ | |
| 82 | private String source; | |
| 83 | ||
| 84 | /** | |
| 85 | * Get the value of source. | |
| 86 | * | |
| 87 | * @return the value of source | |
| 88 | */ | |
| 89 | public String getSource() { | |
| 90 | 208 | return source; |
| 91 | } | |
| 92 | ||
| 93 | /** | |
| 94 | * Set the value of source. | |
| 95 | * | |
| 96 | * @param source new value of source | |
| 97 | */ | |
| 98 | public void setSource(String source) { | |
| 99 | 391 | this.source = source; |
| 100 | 391 | } |
| 101 | ||
| 102 | @Override | |
| 103 | public boolean equals(Object obj) { | |
| 104 | 0 | if (obj == null) { |
| 105 | 0 | return false; |
| 106 | } | |
| 107 | 0 | if (getClass() != obj.getClass()) { |
| 108 | 0 | return false; |
| 109 | } | |
| 110 | 0 | final Reference other = (Reference) obj; |
| 111 | 0 | if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { |
| 112 | 0 | return false; |
| 113 | } | |
| 114 | 0 | if ((this.url == null) ? (other.url != null) : !this.url.equals(other.url)) { |
| 115 | 0 | return false; |
| 116 | } | |
| 117 | 0 | if ((this.source == null) ? (other.source != null) : !this.source.equals(other.source)) { |
| 118 | 0 | return false; |
| 119 | } | |
| 120 | 0 | return true; |
| 121 | } | |
| 122 | ||
| 123 | @Override | |
| 124 | public int hashCode() { | |
| 125 | 0 | int hash = 5; |
| 126 | 0 | hash = 67 * hash + (this.name != null ? this.name.hashCode() : 0); |
| 127 | 0 | hash = 67 * hash + (this.url != null ? this.url.hashCode() : 0); |
| 128 | 0 | hash = 67 * hash + (this.source != null ? this.source.hashCode() : 0); |
| 129 | 0 | return hash; |
| 130 | } | |
| 131 | ||
| 132 | /** | |
| 133 | * Implementation of the comparable interface. | |
| 134 | * | |
| 135 | * @param o the Reference being compared | |
| 136 | * @return an integer indicating the ordering of the two objects | |
| 137 | */ | |
| 138 | public int compareTo(Reference o) { | |
| 139 | 807 | if (source.equals(o.source)) { |
| 140 | 141 | if (name.equals(o.name)) { |
| 141 | 0 | if (url.equals(o.url)) { |
| 142 | 0 | return 0; //they are equal |
| 143 | } else { | |
| 144 | 0 | return url.compareTo(o.url); |
| 145 | } | |
| 146 | } else { | |
| 147 | 141 | return name.compareTo(o.name); |
| 148 | } | |
| 149 | } else { | |
| 150 | 666 | return source.compareTo(o.source); |
| 151 | } | |
| 152 | } | |
| 153 | } |