All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.unix4j.unix.ls.LsOption Maven / Gradle / Ivy

There is a newer version: 0.6
Show newest version
package org.unix4j.unix.ls;

import java.util.Collections;
import java.util.EnumSet;
import java.util.Iterator;

import org.unix4j.option.Option;
import org.unix4j.unix.Ls;

/**
 * Options for the {@link Ls ls} command.
 * 

* For most applications, it may be more convenient to use {@link Ls#Options} * instead of the option constants defined here. *

*

* * * * * * *
{@code -a}  {@code --allFiles} Lists all files in the given directory, including hidden files (those whose names start with \".\" in Unix). By default, these files are excluded from the list.
{@code -h}  {@code --humanReadable} Print sizes in human readable format. (e.g., 1K, 234M, 2G, etc.)
{@code -l}  {@code --longFormat} Long format, displaying file types, permissions, number of hard links, owner, group, size, date, and filename.
{@code -R}  {@code --recurseSubdirs} Recursively lists subdirectories encountered.
{@code -r}  {@code --reverseOrder} Reverses the order of the sort to get reverse collating sequence or oldest first.
{@code -t}  {@code --timeSorted} Sorts with the primary key being time modified (most recently modified first) and the secondary key being filename in the collating sequence.
*/ public enum LsOption implements Option, LsOptions { /** * Option {@code --allFiles}, {@code -a}: * Lists all files in the given directory, including hidden files (those whose names start with \".\" in Unix). By default, these files are excluded from the list. */ allFiles('a'), /** * Option {@code --humanReadable}, {@code -h}: * Print sizes in human readable format. (e.g., 1K, 234M, 2G, etc.) */ humanReadable('h'), /** * Option {@code --longFormat}, {@code -l}: * Long format, displaying file types, permissions, number of hard links, owner, group, size, date, and filename. */ longFormat('l'), /** * Option {@code --recurseSubdirs}, {@code -R}: * Recursively lists subdirectories encountered. */ recurseSubdirs('R'), /** * Option {@code --reverseOrder}, {@code -r}: * Reverses the order of the sort to get reverse collating sequence or oldest first. */ reverseOrder('r'), /** * Option {@code --timeSorted}, {@code -t}: * Sorts with the primary key being time modified (most recently modified first) and the secondary key being filename in the collating sequence. */ timeSorted('t'); private final char acronym; private LsOption(char acronym) { this.acronym = acronym; } @Override public Class optionType() { return LsOption.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 LsOption findByAcronym(char acronym) { for (final LsOption opt : values()) { if (opt.acronym() == acronym) return opt; } return null; } @Override public char acronym() { return acronym; } @Override public boolean isSet(LsOption 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(LsOption option) { return true; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy