View Javadoc
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.creadur.whisker.app.analysis;
20  
21  /**
22   * Describes a resource in a software distribution.
23   */
24  public class ResourceDescription implements Comparable<ResourceDescription> {
25      /** Containing directory. */
26      private final String directory;
27      /** Resource name. */
28      private final String resource;
29  
30      /**
31       * Constructs a description of the given resource.
32       * @param directoryName not null
33       * @param resourceName not null
34       */
35      public ResourceDescription(
36              final String directoryName, final String resourceName) {
37          super();
38          this.directory = directoryName;
39          this.resource = resourceName;
40      }
41  
42      /**
43       * Gets the name of the containing directory.
44       * @return the directoryName, not null
45       */
46      public final String getDirectory() {
47          return directory;
48      }
49  
50      /**
51       * Gets the resource name.
52       * @return the resourceName, not null
53       */
54      public final String getResource() {
55          return resource;
56      }
57  
58      /**
59       * Hash code compatible with equals.
60       * @return a suitable hash code
61       * @see java.lang.Object#hashCode()
62       */
63      @Override
64      public int hashCode() {
65          final int prime = 31;
66          int result = 1;
67          result = prime * result
68                  + ((directory == null) ? 0 : directory.hashCode());
69          result = prime * result
70                  + ((resource == null) ? 0 : resource.hashCode());
71          return result;
72      }
73  
74      /**
75       * Equal means identical name and directory.
76       * @param obj object to be compared against
77       * @return true when equal
78       * @see java.lang.Object#equals(java.lang.Object)
79       */
80      @Override
81      public boolean equals(final Object obj) {
82          if (this == obj) {
83              return true;
84          }
85          if (obj == null) {
86              return false;
87          }
88          if (getClass() != obj.getClass()) {
89              return false;
90          }
91          final ResourceDescription other = (ResourceDescription) obj;
92          if (directory == null) {
93              if (other.directory != null) {
94                  return false;
95              }
96          } else if (!directory.equals(other.directory)) {
97              return false;
98          }
99          if (resource == null) {
100             if (other.resource != null) {
101                 return false;
102             }
103         } else if (!resource.equals(other.resource)) {
104             return false;
105         }
106         return true;
107     }
108 
109     /**
110      * Suitable for logging.
111      * @return not null
112      * @see java.lang.Object#toString()
113      */
114     @Override
115     public String toString() {
116         return "ResourceMissingLicense [directoryName=" + directory
117                 + ", resourceName=" + resource + "]";
118     }
119 
120     /**
121      * Natural comparison is directory name, then resource name.
122      * @param other possibly null
123      * @return numeric comparison
124      * @see java.lang.Comparable#compareTo(java.lang.Object)
125      */
126     public int compareTo(final ResourceDescription other) {
127         final int result;
128         final int compareOnDirectoryName = this.getDirectory().compareTo(other.getDirectory());
129         if (compareOnDirectoryName == 0) {
130             result = this.getResource().compareTo(other.getResource());
131         } else {
132             result = compareOnDirectoryName;
133         }
134         return result;
135     }
136 
137 
138 }