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