View Javadoc

    1   /*
    2    * This file is part of dependency-check-core.
    3    *
    4    * Dependency-check-core is free software: you can redistribute it and/or modify it
    5    * under the terms of the GNU General Public License as published by the Free
    6    * Software Foundation, either version 3 of the License, or (at your option) any
    7    * later version.
    8    *
    9    * Dependency-check-core is distributed in the hope that it will be useful, but
    10   * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11   * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    12   * details.
    13   *
    14   * You should have received a copy of the GNU General Public License along with
    15   * dependency-check-core. If not, see http://www.gnu.org/licenses/.
    16   *
    17   * Copyright (c) 2012 Jeremy Long. All Rights Reserved.
    18   */
    19  package org.owasp.dependencycheck.dependency;
    20
    21  import java.io.Serializable;
    22
    23  /**
    24   * An external reference for a vulnerability. This contains a name, URL, and a
    25   * source.
    26   *
    27   * @author Jeremy Long (jeremy.long@owasp.org)
    28   */
    29  public class Reference implements Serializable, Comparable<Reference> {
    30
    31      /**
    32       * the serial version uid.
    33       */
    34      private static final long serialVersionUID = -3444464824563008021L;
    35      /**
    36       * The name of the reference.
    37       */
    38      private String name;
    39
    40      /**
    41       * Get the value of name.
    42       *
    43       * @return the value of name
    44       */
    45      public String getName() {
    46          return name;
    47      }
    48
    49      /**
    50       * Set the value of name.
    51       *
    52       * @param name new value of name
    53       */
    54      public void setName(String name) {
    55          this.name = name;
    56      }
    57      /**
    58       * the url for the reference.
    59       */
    60      private String url;
    61
    62      /**
    63       * Get the value of url.
    64       *
    65       * @return the value of url
    66       */
    67      public String getUrl() {
    68          return url;
    69      }
    70
    71      /**
    72       * Set the value of url.
    73       *
    74       * @param url new value of url
    75       */
    76      public void setUrl(String url) {
    77          this.url = url;
    78      }
    79      /**
    80       * the source of the reference.
    81       */
    82      private String source;
    83
    84      /**
    85       * Get the value of source.
    86       *
    87       * @return the value of source
    88       */
    89      public String getSource() {
    90          return source;
    91      }
    92
    93      /**
    94       * Set the value of source.
    95       *
    96       * @param source new value of source
    97       */
    98      public void setSource(String source) {
    99          this.source = source;
    100     }
    101
    102     @Override
    103     public boolean equals(Object obj) {
    104         if (obj == null) {
    105             return false;
    106         }
    107         if (getClass() != obj.getClass()) {
    108             return false;
    109         }
    110         final Reference other = (Reference) obj;
    111         if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
    112             return false;
    113         }
    114         if ((this.url == null) ? (other.url != null) : !this.url.equals(other.url)) {
    115             return false;
    116         }
    117         if ((this.source == null) ? (other.source != null) : !this.source.equals(other.source)) {
    118             return false;
    119         }
    120         return true;
    121     }
    122
    123     @Override
    124     public int hashCode() {
    125         int hash = 5;
    126         hash = 67 * hash + (this.name != null ? this.name.hashCode() : 0);
    127         hash = 67 * hash + (this.url != null ? this.url.hashCode() : 0);
    128         hash = 67 * hash + (this.source != null ? this.source.hashCode() : 0);
    129         return hash;
    130     }
    131
    132     /**
    133      * Implementation of the comparable interface.
    134      *
    135      * @param o the Reference being compared
    136      * @return an integer indicating the ordering of the two objects
    137      */
    138     public int compareTo(Reference o) {
    139         if (source.equals(o.source)) {
    140             if (name.equals(o.name)) {
    141                 if (url.equals(o.url)) {
    142                     return 0; //they are equal
    143                 } else {
    144                     return url.compareTo(o.url);
    145                 }
    146             } else {
    147                 return name.compareTo(o.name);
    148             }
    149         } else {
    150             return source.compareTo(o.source);
    151         }
    152     }
    153 }