Coverage Report - org.apache.creadur.whisker.app.analysis.ResourceDescription
 
Classes in this File Line Coverage Branch Coverage Complexity
ResourceDescription
0%
0/36
0%
0/24
3.714
 
 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  0
 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  0
         super();
 38  0
         this.directory = directoryName;
 39  0
         this.resource = resourceName;
 40  0
     }
 41  
 
 42  
     /**
 43  
      * Gets the name of the containing directory.
 44  
      * @return the directoryName, not null
 45  
      */
 46  
     public final String getDirectory() {
 47  0
         return directory;
 48  
     }
 49  
 
 50  
     /**
 51  
      * Gets the resource name.
 52  
      * @return the resourceName, not null
 53  
      */
 54  
     public final String getResource() {
 55  0
         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  0
         final int prime = 31;
 66  0
         int result = 1;
 67  0
         result = prime * result
 68  
                 + ((directory == null) ? 0 : directory.hashCode());
 69  0
         result = prime * result
 70  
                 + ((resource == null) ? 0 : resource.hashCode());
 71  0
         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  0
         if (this == obj) {
 83  0
             return true;
 84  
         }
 85  0
         if (obj == null) {
 86  0
             return false;
 87  
         }
 88  0
         if (getClass() != obj.getClass()) {
 89  0
             return false;
 90  
         }
 91  0
         final ResourceDescription other = (ResourceDescription) obj;
 92  0
         if (directory == null) {
 93  0
             if (other.directory != null) {
 94  0
                 return false;
 95  
             }
 96  0
         } else if (!directory.equals(other.directory)) {
 97  0
             return false;
 98  
         }
 99  0
         if (resource == null) {
 100  0
             if (other.resource != null) {
 101  0
                 return false;
 102  
             }
 103  0
         } else if (!resource.equals(other.resource)) {
 104  0
             return false;
 105  
         }
 106  0
         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  0
         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  0
         final int compareOnDirectoryName = this.getDirectory().compareTo(other.getDirectory());
 129  0
         if (compareOnDirectoryName == 0) {
 130  0
             result = this.getResource().compareTo(other.getResource());
 131  
         } else {
 132  0
             result = compareOnDirectoryName;
 133  
         }
 134  0
         return result;
 135  
     }
 136  
 
 137  
 
 138  
 }