View Javadoc
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      private 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 this type.
67       */
68      @Override
69      public String toString() {
70          return name;
71      }
72  
73      /**
74       * Returns the name of this type.
75       *
76       * @return The name of the type.
77       */
78      public String getName() {
79          return name;
80      }
81  
82      /**
83       * Returns true if files of this type may contain other files.
84       *
85       * @return true if files can contain other files.
86       */
87      public boolean hasChildren() {
88          return hasChildren;
89      }
90  
91      /**
92       * Returns true if files of this type may have data content.
93       *
94       * @return true if files can have content.
95       */
96      public boolean hasContent() {
97          return hasContent;
98      }
99  
100     /**
101      * Returns true if files of this type may have attributes.
102      *
103      * @return true if files can have attributes
104      */
105     public boolean hasAttributes() {
106         return hasAttrs;
107     }
108 }