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 return other.name == null; 96 } else return name.equals(other.name); 97 } 98 99 /** 100 * Suitable for logging. 101 * @return not null 102 * @see java.lang.Object#toString() 103 */ 104 @Override 105 public String toString() { 106 return "Directory [name=" + name + "]"; 107 } 108 109 /** 110 * Registers a contained resource. 111 * @param name not null 112 */ 113 public void addResource(final String name) { 114 contents.add(name); 115 } 116 117 /** 118 * Natural comparison based on name. 119 * @param other another directory 120 * @return comparison 121 * @see java.lang.Comparable#compareTo(java.lang.Object) 122 */ 123 public int compareTo(final Directory other) { 124 if (other == null) { 125 return -1; 126 } 127 return this.name.compareTo(other.name); 128 } 129 }