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 javax.annotation.concurrent.ThreadSafe;
22 import org.apache.commons.lang3.builder.CompareToBuilder;
23 import org.apache.commons.lang3.builder.EqualsBuilder;
24 import org.apache.commons.lang3.builder.HashCodeBuilder;
25 import org.jetbrains.annotations.NotNull;
26
27 /**
28 * An external reference for a vulnerability. This contains a name, URL, and a
29 * source.
30 *
31 * @author Jeremy Long
32 */
33 @ThreadSafe
34 public class Reference implements Serializable, Comparable<Reference> {
35
36 /**
37 * the serial version uid.
38 */
39 private static final long serialVersionUID = -3444464824563008021L;
40 /**
41 * The name of the reference.
42 */
43 private String name;
44 /**
45 * the url for the reference.
46 */
47 private String url;
48 /**
49 * the source of the reference.
50 */
51 private String source;
52
53 /**
54 * Creates a new reference.
55 */
56 public Reference() {
57 }
58
59 /**
60 * Creates a new reference.
61 *
62 * @param name the reference name
63 * @param source the reference source
64 * @param url the reference url
65 */
66 public Reference(String name, String source, String url) {
67 this.name = name;
68 this.source = source;
69 this.url = url;
70 }
71
72 /**
73 * Get the value of name.
74 *
75 * @return the value of name
76 */
77 public String getName() {
78 return name;
79 }
80
81 /**
82 * Set the value of name.
83 *
84 * @param name new value of name
85 */
86 public void setName(String name) {
87 this.name = name;
88 }
89
90 /**
91 * Get the value of url.
92 *
93 * @return the value of url
94 */
95 public String getUrl() {
96 return url;
97 }
98
99 /**
100 * Set the value of url.
101 *
102 * @param url new value of url
103 */
104 public void setUrl(String url) {
105 this.url = url;
106 }
107
108 /**
109 * Get the value of source.
110 *
111 * @return the value of source
112 */
113 public String getSource() {
114 return source;
115 }
116
117 /**
118 * Set the value of source.
119 *
120 * @param source new value of source
121 */
122 public void setSource(String source) {
123 this.source = source;
124 }
125
126 @Override
127 public String toString() {
128 return "Reference: { name='" + this.name + "', url='" + this.url + "', source='" + this.source + "' }";
129 }
130
131 @Override
132 public boolean equals(Object obj) {
133 if (obj == null || !(obj instanceof Reference)) {
134 return false;
135 }
136 if (this == obj) {
137 return true;
138 }
139 final Reference rhs = (Reference) obj;
140 return new EqualsBuilder()
141 .append(source, rhs.source)
142 .append(name, rhs.name)
143 .append(url, rhs.url)
144 .isEquals();
145 }
146
147 @Override
148 public int hashCode() {
149 return new HashCodeBuilder(5, 67)
150 .append(source)
151 .append(name)
152 .append(url)
153 .toHashCode();
154 }
155
156 /**
157 * Implementation of the comparable interface.
158 *
159 * @param o the Reference being compared
160 * @return an integer indicating the ordering of the two objects
161 */
162 @Override
163 public int compareTo(@NotNull Reference o) {
164 return new CompareToBuilder()
165 .append(source, o.source)
166 .append(name, o.name)
167 .append(url, o.url)
168 .toComparison();
169 }
170 }