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 import java.io.Serializable;
21 import org.apache.commons.lang3.builder.CompareToBuilder;
22
23 /**
24 * An external reference for a vulnerability. This contains a name, URL, and a
25 * source.
26 *
27 * @author Jeremy Long
28 */
29 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 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 this.name = name;
56 }
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 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 this.url = url;
78 }
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 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 this.source = source;
100 }
101
102 @Override
103 public String toString() {
104 return "Reference: { name='" + this.name + "', url='" + this.url + "', source='" + this.source + "' }";
105 }
106
107 @Override
108 public boolean equals(Object obj) {
109 if (obj == null) {
110 return false;
111 }
112 if (getClass() != obj.getClass()) {
113 return false;
114 }
115 final Reference other = (Reference) obj;
116 if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
117 return false;
118 }
119 if ((this.url == null) ? (other.url != null) : !this.url.equals(other.url)) {
120 return false;
121 }
122 if ((this.source == null) ? (other.source != null) : !this.source.equals(other.source)) {
123 return false;
124 }
125 return true;
126 }
127
128 @Override
129 public int hashCode() {
130 int hash = 5;
131 hash = 67 * hash + (this.name != null ? this.name.hashCode() : 0);
132 hash = 67 * hash + (this.url != null ? this.url.hashCode() : 0);
133 hash = 67 * hash + (this.source != null ? this.source.hashCode() : 0);
134 return hash;
135 }
136
137 /**
138 * Implementation of the comparable interface.
139 *
140 * @param o the Reference being compared
141 * @return an integer indicating the ordering of the two objects
142 */
143 @Override
144 public int compareTo(Reference o) {
145 return new CompareToBuilder()
146 .append(source, o.source)
147 .append(name, o.name)
148 .append(url, o.url)
149 .toComparison();
150 }
151 }