Coverage Report - org.apache.creadur.whisker.model.WithinDirectory
 
Classes in this File Line Coverage Branch Coverage Complexity
WithinDirectory
50%
14/28
35%
5/14
2.111
 
 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.model;
 20  
 
 21  
 import java.util.Collection;
 22  
 
 23  
 /**
 24  
  * Links resources expected within a directory in the distribution
 25  
  * to licensing meta-data.
 26  
  */
 27  0
 public class WithinDirectory implements Comparable<WithinDirectory>, ContentElement {
 28  
 
 29  
     /** Resources grouped by license applicable. */
 30  
     private final Collection<WithLicense> licenses;
 31  
     /** Public domain resources, grouped by responsible organisation. */
 32  
     private final Collection<ByOrganisation> publicDomain;
 33  
     /** The directory name. */
 34  
     private final String name;
 35  
 
 36  
     /**
 37  
      * Constructs a description of a directory
 38  
      * @param name directory name, not null
 39  
      * @param licenses resources contained,
 40  
      * grouped by license applicable, not null
 41  
      * @param publicDomain resources in the public domain,
 42  
      * grouped by responsible organisation
 43  
      */
 44  
     public WithinDirectory(final String name,
 45  
             final Collection<WithLicense> licenses,
 46  
             final Collection<ByOrganisation> publicDomain) {
 47  18
         super();
 48  18
         this.name = name;
 49  18
         this.licenses = licenses;
 50  18
         this.publicDomain = publicDomain;
 51  18
     }
 52  
 
 53  
     /**
 54  
      * Gets resources in the public domain,
 55  
      * grouped by the organisation responsible.
 56  
      * @return not null
 57  
      */
 58  
     public Collection<ByOrganisation> getPublicDomain() {
 59  16
         return this.publicDomain;
 60  
     }
 61  
 
 62  
     /**
 63  
      * Gets the name of the directory described.
 64  
      * @return not null
 65  
      */
 66  
     public String getName() {
 67  0
         return this.name;
 68  
     }
 69  
 
 70  
     /**
 71  
      * Gets resources contained,
 72  
      * grouped by license applicable.
 73  
      * @return not null
 74  
      */
 75  
     public Collection<WithLicense> getLicenses() {
 76  16
         return this.licenses;
 77  
     }
 78  
 
 79  
     /**
 80  
      * Based on name.
 81  
      * @see java.lang.Object#hashCode()
 82  
      * @return hash code
 83  
      */
 84  
     @Override
 85  
     public int hashCode() {
 86  0
         return getName().hashCode();
 87  
     }
 88  
 
 89  
     /**
 90  
      * Based on directory name.
 91  
      * @see java.lang.Object#equals(java.lang.Object)
 92  
      * @param obj possibly null
 93  
      * @return true when directory names are equal,
 94  
      * false otherwise
 95  
      */
 96  
     @Override
 97  
     public boolean equals(final Object obj) {
 98  0
         if (this == obj) {
 99  0
             return true;
 100  
         }
 101  0
         if (obj == null) {
 102  0
             return false;
 103  
         }
 104  0
         if (getClass() != obj.getClass()) {
 105  0
             return false;
 106  
         }
 107  0
         final WithinDirectory other = (WithinDirectory) obj;
 108  0
         return getName().equals(other.getName());
 109  
     }
 110  
 
 111  
     /**
 112  
      * Based on name.
 113  
      * @see java.lang.Comparable#compareTo(java.lang.Object)
 114  
      * @return based on name
 115  
      */
 116  
     public int compareTo(final WithinDirectory other) {
 117  0
         return getName().compareTo(other.getName());
 118  
     }
 119  
 
 120  
     /**
 121  
      * Does the directory described have the given name?
 122  
      * @param directoryName not null
 123  
      * @return true when the name match that of this directory,
 124  
      * false otherwise
 125  
      */
 126  
     public boolean isNamed(final String directoryName) {
 127  0
         return getName().equals(directoryName);
 128  
     }
 129  
 
 130  
     /**
 131  
      * Accepts a visitor.
 132  
      * @param visitor possibly null
 133  
      */
 134  
     public void accept(final Visitor visitor) {
 135  16
         if (visitor != null) {
 136  16
             visitor.visit(this);
 137  16
             if (visitor.traversePublicDomain()) {
 138  16
                 for (final ByOrganisation organisation : getPublicDomain()) {
 139  0
                     organisation.accept(visitor);
 140  
                 }
 141  
             }
 142  
 
 143  16
             for (final ContentElement license : getLicenses()) {
 144  16
                 license.accept(visitor);
 145  
             }
 146  
         }
 147  16
     }
 148  
 }