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