001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.vfs2; 018 019/** 020 * An enumerated type that represents a file's type. 021 */ 022public enum FileType { 023 024 /** 025 * A folder. May contain other files, and have attributes, but does not have any data content. 026 */ 027 FOLDER("folder", true, false, true), 028 029 /** 030 * A regular file. May have data content and attributes, but cannot contain other files. 031 */ 032 FILE("file", false, true, true), 033 034 /** 035 * A file or folder. May have data content and attributes, and can contain other files. 036 */ 037 FILE_OR_FOLDER("fileOrFolder", true, true, true), 038 039 /** 040 * A file that does not exist. May not have data content, attributes, or contain other files. 041 */ 042 IMAGINARY("imaginary", false, false, false); 043 044 /** The name of the FileType */ 045 private final String name; 046 047 /** True if the FileType can have children */ 048 private final boolean hasChildren; 049 050 /** True if the FileType can have content */ 051 private final boolean hasContent; 052 053 /** True if the FileType has attributes */ 054 private final boolean hasAttrs; 055 056 FileType(final String name, final boolean hasChildren, final boolean hasContent, final boolean hasAttrs) { 057 this.name = name; 058 this.hasChildren = hasChildren; 059 this.hasContent = hasContent; 060 this.hasAttrs = hasAttrs; 061 } 062 063 /** 064 * Returns the name of this type. 065 * 066 * @return The name of the type. 067 */ 068 public String getName() { 069 return name; 070 } 071 072 /** 073 * Returns true if files of this type may have attributes. 074 * 075 * @return true if files can have attributes 076 */ 077 public boolean hasAttributes() { 078 return hasAttrs; 079 } 080 081 /** 082 * Returns true if files of this type may contain other files. 083 * 084 * @return true if files can contain other files. 085 */ 086 public boolean hasChildren() { 087 return hasChildren; 088 } 089 090 /** 091 * Returns true if files of this type may have data content. 092 * 093 * @return true if files can have content. 094 */ 095 public boolean hasContent() { 096 return hasContent; 097 } 098 099 /** 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}