Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Directory |
|
| 2.5555555555555554;2.556 |
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 | 0 | public class Directory implements Comparable<Directory> { |
28 | /** Names this directory. */ | |
29 | private String name; | |
30 | /** Names resources contained. */ | |
31 | 0 | 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 | 0 | 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 | 0 | this.name = name; |
48 | 0 | return this; |
49 | } | |
50 | ||
51 | /** | |
52 | * Gets the directory contents. | |
53 | * @return the contents | |
54 | */ | |
55 | public Set<String> getContents() { | |
56 | 0 | 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 | 0 | this.contents = contents; |
65 | 0 | } |
66 | ||
67 | /** | |
68 | * @return the hash code | |
69 | * @see java.lang.Object#hashCode() | |
70 | */ | |
71 | @Override | |
72 | public int hashCode() { | |
73 | 0 | final int prime = 31; |
74 | 0 | int result = 1; |
75 | 0 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
76 | 0 | 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 | 0 | if (this == obj) |
88 | 0 | return true; |
89 | 0 | if (obj == null) |
90 | 0 | return false; |
91 | 0 | if (getClass() != obj.getClass()) |
92 | 0 | return false; |
93 | 0 | Directory other = (Directory) obj; |
94 | 0 | if (name == null) { |
95 | 0 | if (other.name != null) |
96 | 0 | return false; |
97 | 0 | } else if (!name.equals(other.name)) |
98 | 0 | return false; |
99 | 0 | 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 | 0 | 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 | 0 | contents.add(name); |
118 | 0 | } |
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 | 0 | if (other == null) { |
128 | 0 | return -1; |
129 | } | |
130 | 0 | return this.name.compareTo(other.name); |
131 | } | |
132 | } |