1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.vfs2;
18
19 /**
20 * An enumerated type that represents a file's type.
21 */
22 public enum FileType {
23
24 /**
25 * A folder. May contain other files, and have attributes, but does not have any data content.
26 */
27 FOLDER("folder", true, false, true),
28
29 /**
30 * A regular file. May have data content and attributes, but cannot contain other files.
31 */
32 FILE("file", false, true, true),
33
34 /**
35 * A file or folder. May have data content and attributes, and can contain other files.
36 */
37 FILE_OR_FOLDER("fileOrFolder", true, true, true),
38
39 /**
40 * A file that does not exist. May not have data content, attributes, or contain other files.
41 */
42 IMAGINARY("imaginary", false, false, false);
43
44 /** The name of the FileType */
45 private final String name;
46
47 /** True if the FileType can have children */
48 private final boolean hasChildren;
49
50 /** True if the FileType can have content */
51 private final boolean hasContent;
52
53 /** True if the FileType has attributes */
54 private final boolean hasAttrs;
55
56 FileType(final String name, final boolean hasChildren, final boolean hasContent, final boolean hasAttrs) {
57 this.name = name;
58 this.hasChildren = hasChildren;
59 this.hasContent = hasContent;
60 this.hasAttrs = hasAttrs;
61 }
62
63 /**
64 * Returns the name of this type.
65 *
66 * @return The name of the type.
67 */
68 public String getName() {
69 return name;
70 }
71
72 /**
73 * Returns true if files of this type may have attributes.
74 *
75 * @return true if files can have attributes
76 */
77 public boolean hasAttributes() {
78 return hasAttrs;
79 }
80
81 /**
82 * Returns true if files of this type may contain other files.
83 *
84 * @return true if files can contain other files.
85 */
86 public boolean hasChildren() {
87 return hasChildren;
88 }
89
90 /**
91 * Returns true if files of this type may have data content.
92 *
93 * @return true if files can have content.
94 */
95 public boolean hasContent() {
96 return hasContent;
97 }
98
99 /**
100 * Returns the name of this type.
101 *
102 * @return The name of this type.
103 */
104 @Override
105 public String toString() {
106 return name;
107 }
108 }