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) 2015 The OWASP Foundation. All Rights Reserved.
17   */
18  package org.owasp.dependencycheck.data.composer;
19  
20  import org.apache.commons.lang3.builder.EqualsBuilder;
21  import org.apache.commons.lang3.builder.HashCodeBuilder;
22  
23  import javax.annotation.concurrent.ThreadSafe;
24  
25  /**
26   * Represents a dependency (GAV, right now) from a Composer dependency.
27   *
28   * @author colezlaw
29   */
30  @ThreadSafe
31  public final class ComposerDependency {
32  
33      /**
34       * The group
35       */
36      private final String group;
37  
38      /**
39       * The project
40       */
41      private final String project;
42  
43      /**
44       * The version
45       */
46      private final String version;
47  
48      /**
49       * Create a ComposerDependency from group, project, and version.
50       *
51       * @param group the group
52       * @param project the project
53       * @param version the version
54       */
55      public ComposerDependency(String group, String project, String version) {
56          this.group = group;
57          this.project = project;
58          this.version = version;
59      }
60  
61      /**
62       * Get the group.
63       *
64       * @return the group
65       */
66      public String getGroup() {
67          return group;
68      }
69  
70      /**
71       * Get the project.
72       *
73       * @return the project
74       */
75      public String getProject() {
76          return project;
77      }
78  
79      /**
80       * Get the version.
81       *
82       * @return the version
83       */
84      public String getVersion() {
85          return version;
86      }
87  
88      @Override
89      public boolean equals(Object obj) {
90          if (obj == null || !(obj instanceof ComposerDependency)) {
91              return false;
92          }
93          if (this == obj) {
94              return true;
95          }
96          final ComposerDependency other = (ComposerDependency) obj;
97          return new EqualsBuilder()
98                  .append(group, other.group)
99                  .append(project, other.project)
100                 .append(version, other.version)
101                 .build();
102     }
103 
104     @Override
105     public int hashCode() {
106         return new HashCodeBuilder(103, 199)
107                 .append(group)
108                 .append(project)
109                 .append(version)
110                 .toHashCode();
111     }
112 }