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