View Javadoc
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   *
24   * @author Jeremy Long
25   */
26  public class Identifier implements Serializable, Comparable<Identifier> {
27  
28      /**
29       * The serial version UID for serialization.
30       */
31      private static final long serialVersionUID = 1L;
32  
33      /**
34       * Default constructor. Should only be used for automatic class
35       * creation as is the case with many XML parsers (for the parsing
36       * of the Dependency-Check XML report). For all other use-cases,
37       * please use the non-default constructors.
38       */
39      public Identifier() {
40      }
41  
42      /**
43       * Constructs a new Identifier with the specified data.
44       *
45       * @param type the identifier type.
46       * @param value the identifier value.
47       * @param url the identifier url.
48       */
49      public Identifier(String type, String value, String url) {
50          this.type = type;
51          this.value = value;
52          this.url = url;
53      }
54  
55      /**
56       * Constructs a new Identifier with the specified data.
57       *
58       * @param type the identifier type.
59       * @param value the identifier value.
60       * @param url the identifier url.
61       * @param description the description of the identifier.
62       */
63      public Identifier(String type, String value, String url, String description) {
64          this(type, value, url);
65          this.description = description;
66      }
67  
68      /**
69       * The confidence that this is the correct identifier.
70       */
71      private Confidence confidence;
72  
73      /**
74       * Get the value of confidence.
75       *
76       * @return the value of confidence
77       */
78      public Confidence getConfidence() {
79          return confidence;
80      }
81  
82      /**
83       * Set the value of confidence.
84       *
85       * @param confidence new value of confidence
86       */
87      public void setConfidence(Confidence confidence) {
88          this.confidence = confidence;
89      }
90  
91      /**
92       * The value of the identifier
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         return value;
103     }
104 
105     /**
106      * Set the value of value.
107      *
108      * @param value new value of value
109      */
110     public void setValue(String value) {
111         this.value = value;
112     }
113     /**
114      * The url for the identifier.
115      */
116     private String url;
117 
118     /**
119      * Get the value of url.
120      *
121      * @return the value of url
122      */
123     public String getUrl() {
124         return url;
125     }
126 
127     /**
128      * Set the value of url.
129      *
130      * @param url new value of url
131      */
132     public void setUrl(String url) {
133         this.url = url;
134     }
135     /**
136      * The type of the identifier.
137      */
138     private String type;
139 
140     /**
141      * Get the value of type.
142      *
143      * @return the value of type
144      */
145     public String getType() {
146         return type;
147     }
148 
149     /**
150      * <p>
151      * Set the value of type.</p><p>
152      * Example would be "CPE".</p>
153      *
154      * @param type new value of type
155      */
156     public void setType(String type) {
157         this.type = type;
158     }
159     /**
160      * A description of the identifier.
161      */
162     private String description;
163 
164     /**
165      * Get the value of description.
166      *
167      * @return the value of description
168      */
169     public String getDescription() {
170         return description;
171     }
172 
173     /**
174      * Set the value of description.
175      *
176      * @param description new value of description
177      */
178     public void setDescription(String description) {
179         this.description = description;
180     }
181 
182     @Override
183     public boolean equals(Object obj) {
184         if (obj == null) {
185             return false;
186         }
187         if (getClass() != obj.getClass()) {
188             return false;
189         }
190         final Identifier other = (Identifier) obj;
191         if ((this.value == null) ? (other.value != null) : !this.value.equals(other.value)) {
192             return false;
193         }
194         if ((this.type == null) ? (other.type != null) : !this.type.equals(other.type)) {
195             return false;
196         }
197         return true;
198     }
199 
200     @Override
201     public int hashCode() {
202         int hash = 5;
203         hash = 53 * hash + (this.value != null ? this.value.hashCode() : 0);
204         hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0);
205         return hash;
206     }
207 
208     /**
209      * Standard implementation of toString; displays identifier value and type.
210      *
211      * @return a String representation of the object
212      */
213     @Override
214     public String toString() {
215         return "Identifier{" + "value=" + value + ", type=" + type + '}';
216     }
217 
218     /**
219      * Implementation of the comparator interface. This compares the value of the identifier only.
220      *
221      * @param o the object being compared
222      * @return an integer indicating the ordering
223      */
224     @Override
225     public int compareTo(Identifier o) {
226         if (o == null) {
227             return -1;
228         }
229         return this.value.compareTo(o.value);
230     }
231 }