org.unix4j.unix.find.FindOption Maven / Gradle / Ivy
package org.unix4j.unix.find;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Iterator;
import org.unix4j.option.Option;
import org.unix4j.unix.Find;
/**
* Options for the {@link Find find} command.
*
* For most applications, it may be more convenient to use {@link Find#Options}
* instead of the option constants defined here.
*
*
* {@code -d} {@code --typeDirectory} Consider only directories
* {@code -f} {@code --typeFile} Consider only regular files
* {@code -l} {@code --typeSymlink} Consider only symbolic links
* {@code -x} {@code --typeOther} Consider only files that are neither of directory (d),
regular file (f) or symlink (l).
* {@code -r} {@code --regex} Use full regular expression syntax for the patterns specified by the
name operand
(This option is ignored if no name operand is specified).
* {@code -i} {@code --ignoreCase} Use case insensitive matching when applying the file name pattern
specified by the name operand
(This option is ignored if no name operand is specified).
* {@code -n} {@code --timeNewer} Consider only files that have been created, modified or accessed
after or at the time specified by the time operand (the default)
(This option is ignored if no time operand is specified).
* {@code -o} {@code --timeOlder} Consider only files that have been created, modified or accessed
before or at the time specified by the time operand
(This option is ignored if no time operand is specified).
* {@code -c} {@code --timeCreate} The time operand refers to the creation time of the file
(This option is ignored if no time operand is specified).
* {@code -a} {@code --timeAccess} The time operand refers to the last access time of the file
(This option is ignored if no time operand is specified).
* {@code -m} {@code --timeModified} The time operand refers to the last modification time of the file
(the default)
(This option is ignored if no time operand is specified).
* {@code -z} {@code --print0} Print the full file name on the standard output, followed by a null
character (instead of the newline character used by default). This
allows file names that contain newlines or other types of white
space to be correctly interpreted by programs that process the find
output. This option corresponds to the --delimiter0 option of xargs.
*
*/
public enum FindOption implements Option, FindOptions {
/**
* Option {@code --typeDirectory}, {@code -d}:
* Consider only directories
*/
typeDirectory('d'),
/**
* Option {@code --typeFile}, {@code -f}:
* Consider only regular files
*/
typeFile('f'),
/**
* Option {@code --typeSymlink}, {@code -l}:
* Consider only symbolic links
*/
typeSymlink('l'),
/**
* Option {@code --typeOther}, {@code -x}:
* Consider only files that are neither of directory (d),
regular file (f) or symlink (l).
*/
typeOther('x'),
/**
* Option {@code --regex}, {@code -r}:
* Use full regular expression syntax for the patterns specified by the
name operand
(This option is ignored if no name operand is specified).
*/
regex('r'),
/**
* Option {@code --ignoreCase}, {@code -i}:
* Use case insensitive matching when applying the file name pattern
specified by the name operand
(This option is ignored if no name operand is specified).
*/
ignoreCase('i'),
/**
* Option {@code --timeNewer}, {@code -n}:
* Consider only files that have been created, modified or accessed
after or at the time specified by the time operand (the default)
(This option is ignored if no time operand is specified).
*/
timeNewer('n'),
/**
* Option {@code --timeOlder}, {@code -o}:
* Consider only files that have been created, modified or accessed
before or at the time specified by the time operand
(This option is ignored if no time operand is specified).
*/
timeOlder('o'),
/**
* Option {@code --timeCreate}, {@code -c}:
* The time operand refers to the creation time of the file
(This option is ignored if no time operand is specified).
*/
timeCreate('c'),
/**
* Option {@code --timeAccess}, {@code -a}:
* The time operand refers to the last access time of the file
(This option is ignored if no time operand is specified).
*/
timeAccess('a'),
/**
* Option {@code --timeModified}, {@code -m}:
* The time operand refers to the last modification time of the file
(the default)
(This option is ignored if no time operand is specified).
*/
timeModified('m'),
/**
* Option {@code --print0}, {@code -z}:
* Print the full file name on the standard output, followed by a null
character (instead of the newline character used by default). This
allows file names that contain newlines or other types of white
space to be correctly interpreted by programs that process the find
output. This option corresponds to the --delimiter0 option of xargs.
*/
print0('z');
private final char acronym;
private FindOption(char acronym) {
this.acronym = acronym;
}
@Override
public Class optionType() {
return FindOption.class;
}
/**
* Returns the option with the given {@code acronym}, or {@code null} if no
* such option is found.
*
* @param acronym the option {@link #acronym() acronym}
* @return the option with the given {@code acronym} or {@code null} if it
* is not found
*/
public static FindOption findByAcronym(char acronym) {
for (final FindOption opt : values()) {
if (opt.acronym() == acronym) return opt;
}
return null;
}
@Override
public char acronym() {
return acronym;
}
@Override
public boolean isSet(FindOption option) {
return equals(option);
}
/**
* Returns a new set with {@code this} active option.
*
* @return a new set containing this option
*/
@Override
public EnumSet asSet() {
return EnumSet.of(this);
}
/**
* Returns an immutable iterator returning o single element: {@code this}
* option.
*
* @return an immutable iterator with {@code this} active option.
*/
@Override
public Iterator iterator() {
return Collections.singleton(this).iterator();
}
/**
* Returns 1 as this is a set with a single element: {@code this} option
*
* @return one
*/
@Override
public int size() {
return 1;
}
/**
* Returns true if the {@link Option#acronym() acronym} should be used for
* the specified {@code option} in string representations.
*
* This method returns always true for all options.
*
* @param option
* the option of interest
* @return always true indicating that option acronyms should be used in
* string representations for all options
*/
@Override
public boolean useAcronymFor(FindOption option) {
return true;
}
}