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.scan; 20 21 import java.util.Set; 22 import java.util.TreeSet; 23 24 /** 25 * Describes a directory. 26 */ 27 public class Directory implements Comparable<Directory> { 28 /** Names this directory. */ 29 private String name; 30 /** Names resources contained. */ 31 private Set<String> contents = new TreeSet<String>(); 32 33 34 /** 35 * Gets the directory name. 36 * @return the name 37 */ 38 public String getName() { 39 return name; 40 } 41 /** 42 * Sets the directory name. 43 * @param name the name to set 44 * @return this, not null 45 */ 46 public Directory setName(final String name) { 47 this.name = name; 48 return this; 49 } 50 51 /** 52 * Gets the directory contents. 53 * @return the contents 54 */ 55 public Set<String> getContents() { 56 return contents; 57 } 58 59 /** 60 * Sets the directory contents. 61 * @param contents the contents to set 62 */ 63 public void setContents(final Set<String> contents) { 64 this.contents = contents; 65 } 66 67 /** 68 * @return the hash code 69 * @see java.lang.Object#hashCode() 70 */ 71 @Override 72 public int hashCode() { 73 final int prime = 31; 74 int result = 1; 75 result = prime * result + ((name == null) ? 0 : name.hashCode()); 76 return result; 77 } 78 79 /** 80 * Equal if and only if names are equal. 81 * @param obj possibly null 82 * @return true when equal 83 * @see java.lang.Object#equals(java.lang.Object) 84 */ 85 @Override 86 public boolean equals(final Object obj) { 87 if (this == obj) 88 return true; 89 if (obj == null) 90 return false; 91 if (getClass() != obj.getClass()) 92 return false; 93 Directory other = (Directory) obj; 94 if (name == null) { 95 if (other.name != null) 96 return false; 97 } else if (!name.equals(other.name)) 98 return false; 99 return true; 100 } 101 102 /** 103 * Suitable for logging. 104 * @return not null 105 * @see java.lang.Object#toString() 106 */ 107 @Override 108 public String toString() { 109 return "Directory [name=" + name + "]"; 110 } 111 112 /** 113 * Registers a contained resource. 114 * @param name not null 115 */ 116 public void addResource(final String name) { 117 contents.add(name); 118 } 119 120 /** 121 * Natural comparison based on name. 122 * @param other another directory 123 * @return comparison 124 * @see java.lang.Comparable#compareTo(java.lang.Object) 125 */ 126 public int compareTo(final Directory other) { 127 if (other == null) { 128 return -1; 129 } 130 return this.name.compareTo(other.name); 131 } 132 }