1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.maven.shared.dependency.analyzer;
20
21 /**
22 * Usage of a dependency class by a project class.
23 *
24 * @author <a href="mailto:hijon89@gmail.com">Jonathan Haber</a>
25 */
26 public class DependencyUsage {
27
28 private final String dependencyClass;
29
30 private final String usedBy;
31
32 public DependencyUsage(String dependencyClass, String usedBy) {
33 this.dependencyClass = dependencyClass;
34 this.usedBy = usedBy;
35 }
36
37 /**
38 * @return the dependency class used by the project class
39 */
40 public String getDependencyClass() {
41 return dependencyClass;
42 }
43
44 /**
45 * @return the project class using the dependency class
46 */
47 public String getUsedBy() {
48 return usedBy;
49 }
50
51 /*
52 * @see java.lang.Object#hashCode()
53 */
54 public int hashCode() {
55 int hashCode = dependencyClass.hashCode();
56 hashCode = (hashCode * 37) + usedBy.hashCode();
57
58 return hashCode;
59 }
60
61 /*
62 * @see java.lang.Object#equals(java.lang.Object)
63 */
64 public boolean equals(Object object) {
65 if (object instanceof DependencyUsage) {
66 DependencyUsage usage = (DependencyUsage) object;
67
68 return getDependencyClass().equals(usage.getDependencyClass())
69 && getUsedBy().equals(usage.getUsedBy());
70 }
71
72 return false;
73 }
74
75 /*
76 * @see java.lang.Object#toString()
77 */
78 public String toString() {
79 StringBuilder buffer = new StringBuilder();
80
81 buffer.append("dependencyClass=").append(getDependencyClass());
82 buffer.append(",");
83 buffer.append("usedBy=").append(getUsedBy());
84
85 buffer.insert(0, "[");
86 buffer.insert(0, getClass().getName());
87
88 buffer.append("]");
89
90 return buffer.toString();
91 }
92 }