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     * A folder. May contain other files, and have attributes, but does not have any data content.
025     */
026    FOLDER("folder", true, false, true),
027
028    /**
029     * A regular file. May have data content and attributes, but cannot contain other files.
030     */
031    FILE("file", false, true, true),
032
033    /**
034     * A file or folder. May have data content and attributes, and can contain other files.
035     */
036    FILE_OR_FOLDER("fileOrFolder", true, true, true),
037
038    /**
039     * A file that does not exist. May not have data content, attributes, or contain other files.
040     */
041    IMAGINARY("imaginary", false, false, false);
042
043    /** The name of the FileType */
044    private final String name;
045
046    /** true if the FileType can have children */
047    private final boolean hasChildren;
048
049    /** true if the FileType can have content */
050    private final boolean hasContent;
051
052    /** true if the FileType has attributes */
053    private final boolean hasAttrs;
054
055    private FileType(final String name, final boolean hasChildren, final boolean hasContent, final boolean hasAttrs) {
056        this.name = name;
057        this.hasChildren = hasChildren;
058        this.hasContent = hasContent;
059        this.hasAttrs = hasAttrs;
060    }
061
062    /**
063     * Returns the name of this type.
064     *
065     * @return The name of this type.
066     */
067    @Override
068    public String toString() {
069        return name;
070    }
071
072    /**
073     * Returns the name of this type.
074     *
075     * @return The name of the type.
076     */
077    public String getName() {
078        return name;
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 true if files of this type may have attributes.
101     *
102     * @return true if files can have attributes
103     */
104    public boolean hasAttributes() {
105        return hasAttrs;
106    }
107}