001package org.unix4j.unix.find; 002 003import java.io.File; 004import java.io.FileFilter; 005 006/** 007 * File filter based on file type. 008 */ 009enum TypeFilter implements FileFilter, Optionable<FindOption> { 010 Directory(FindOption.typeDirectory) { 011 @Override 012 public boolean accept(File file) { 013 return FileAttributes.isDirectory(file); 014 } 015 }, 016 RegularFile(FindOption.typeFile) { 017 @Override 018 public boolean accept(File file) { 019 return FileAttributes.isRegularFile(file); 020 } 021 }, 022 SymbolicLink(FindOption.typeSymlink) { 023 @Override 024 public boolean accept(File file) { 025 return FileAttributes.isSymbolicLink(file); 026 } 027 }, 028 Other(FindOption.typeOther) { 029 @Override 030 public boolean accept(File file) { 031 return FileAttributes.isOther(file); 032 } 033 }; 034 private final FindOption option; 035 036 TypeFilter(FindOption option) { 037 this.option = option; 038 } 039 040 @Override 041 public FindOption getOption() { 042 return option; 043 } 044 045 /** 046 * Returns the (first) type filter constant if such an option is set, and 047 * null if no type option is found. 048 * 049 * @param options 050 * the options 051 * @return the type filter constant based on the given options, or null if 052 * no type option is set 053 */ 054 public static TypeFilter valueOf(FindOptions options) { 055 return OptionableUtil.findFirstEnumByOptionInSet(TypeFilter.class, options, null); 056 } 057}