NugetPackageReference.java

  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) 2018 Paul Irwin. All Rights Reserved.
  17.  */
  18. package org.owasp.dependencycheck.data.nuget;

  19. import org.apache.commons.lang3.builder.EqualsBuilder;
  20. import org.apache.commons.lang3.builder.HashCodeBuilder;

  21. /**
  22.  * Represents a reference to a NuGet package and version.
  23.  *
  24.  * @author paulirwin
  25.  */
  26. public class NugetPackageReference {

  27.     /**
  28.      * The id.
  29.      */
  30.     private String id;

  31.     /**
  32.      * The version.
  33.      */
  34.     private String version;

  35.     /**
  36.      * Sets the id.
  37.      *
  38.      * @param id the id
  39.      */
  40.     public void setId(String id) {
  41.         this.id = id;
  42.     }

  43.     /**
  44.      * Gets the id.
  45.      *
  46.      * @return the id
  47.      */
  48.     public String getId() {
  49.         return id;
  50.     }

  51.     /**
  52.      * Sets the version.
  53.      *
  54.      * @param version the version
  55.      */
  56.     public void setVersion(String version) {
  57.         this.version = version;
  58.     }

  59.     /**
  60.      * Gets the version.
  61.      *
  62.      * @return the version
  63.      */
  64.     public String getVersion() {
  65.         return version;
  66.     }

  67.     /**
  68.      * {@inheritDoc}
  69.      */
  70.     @Override
  71.     public boolean equals(Object obj) {
  72.         if (obj == null || !(obj instanceof NugetPackageReference)) {
  73.             return false;
  74.         }
  75.         if (this == obj) {
  76.             return true;
  77.         }
  78.         final NugetPackageReference rhs = (NugetPackageReference) obj;
  79.         return new EqualsBuilder()
  80.                 .append(id, rhs.id)
  81.                 .append(version, rhs.version)
  82.                 .isEquals();
  83.     }

  84.     /**
  85.      * {@inheritDoc}
  86.      */
  87.     @Override
  88.     public int hashCode() {
  89.         return new HashCodeBuilder(7, 89)
  90.                 .append(id)
  91.                 .append(version)
  92.                 .toHashCode();
  93.     }
  94. }