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

org.unix4j.unix.tail.TailOption Maven / Gradle / Ivy

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

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

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

/**
 * Options for the {@link Tail tail} command.
 * 

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

*

* * * *
{@code -c}  {@code --chars} The {@code count} argument is in units of characters instead of lines. Starts from 1 and includes line ending characters.
{@code -q}  {@code --suppressHeaders} Suppresses printing of headers when multiple files are being examined.
{@code -s}  {@code --countFromStart} The {@code count} argument is relative to the beginning of the file instead of counting from the end of the file. For instance, {@code tail -s 10} prints the lines starting from line 10; {@code tail -s 1} prints the whole file.
*/ public enum TailOption implements Option, TailOptions { /** * Option {@code --chars}, {@code -c}: * The {@code count} argument is in units of characters instead of lines. Starts from 1 and includes line ending characters. */ chars('c'), /** * Option {@code --suppressHeaders}, {@code -q}: * Suppresses printing of headers when multiple files are being examined. */ suppressHeaders('q'), /** * Option {@code --countFromStart}, {@code -s}: * The {@code count} argument is relative to the beginning of the file instead of counting from the end of the file. For instance, {@code tail -s 10} prints the lines starting from line 10; {@code tail -s 1} prints the whole file. */ countFromStart('s'); private final char acronym; private TailOption(char acronym) { this.acronym = acronym; } @Override public Class optionType() { return TailOption.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 TailOption findByAcronym(char acronym) { for (final TailOption opt : values()) { if (opt.acronym() == acronym) return opt; } return null; } @Override public char acronym() { return acronym; } @Override public boolean isSet(TailOption 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(TailOption option) { return true; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy