org.unix4j.unix.Uniq Maven / Gradle / Ivy
package org.unix4j.unix;
import org.unix4j.command.CommandInterface;
import org.unix4j.unix.uniq.UniqFactory;
import org.unix4j.unix.uniq.UniqOption;
import org.unix4j.unix.uniq.UniqOptions;
import org.unix4j.unix.uniq.UniqOptionSets;
/**
* Non-instantiable module with inner types making up the uniq command.
*
* NAME
*
* uniq - report or filter out repeated lines in a usually pre-sorted file
*
* SYNOPSIS
*
*
* {@code uniq}
* {@code uniq }
* {@code uniq }
* {@code uniq }
* {@code uniq [-cdug]}
* {@code uniq [-cdug] }
* {@code uniq [-cdug] }
*
*
* See {@link Interface} for the corresponding command signature methods.
*
* DESCRIPTION
*
*
Reads from the standard input or from a specified input file and compares adjacent lines, writing one copy of each input line on the output. The second and succeeding copies of repeated adjacent input lines are not written to the output.
Note that repeated non-adjacent lines in the input are only detected with the --global or -g option. In other words, unique output lines are guaranteed only if either (a) the --global or -g option is specified, or (b) the input lines are sorted.
*
*
* Options
*
* The following options are supported:
*
*
* {@code -c} {@code --count} Precedes each output line with a count of the number of times the
line occurred in the input.
* {@code -d} {@code --duplicatedOnly} Suppresses the writing of lines that are not repeated in the input.
* {@code -u} {@code --uniqueOnly} Suppresses the writing of lines that are repeated in the input.
* {@code -g} {@code --global} Suppresses repeated lines globally, that is, if lines are
non-adjacent. This option guarantees unique output lines even if the
input lines are not sorted.
*
*
* OPERANDS
*
* The following operands are supported:
*
*
* {@code } : {@code java.io.File} The files or directories used as starting point for the listing;
relative paths are not resolved (use the string path argument to
enable relative path resolving based on the current working
directory).
* {@code } : {@code String} The files or directories used as starting point for the listing;
wildcards * and ? are supported; relative paths are resolved on the
basis of the current working directory.
* {@code } : {@code String...} String arguments defining the options and operands for the command.
Options can be specified by acronym (with a leading dash "-") or by
long name (with two leading dashes "--"). Operands other than the
default "--path" operand have to be prefixed with the operand
name.
* {@code } : {@code UniqOptions} The options defining the uniqueness details for the output lines.
*
*/
public final class Uniq {
/**
* The "uniq" command name.
*/
public static final String NAME = "uniq";
/**
* Interface defining all method signatures for the "uniq" command.
*
* @param
* the generic return type for all command signature methods
* to support different implementor types; the methods of a
* command factory for instance returns a command instance;
* command builders can also implement this interface, but their
* methods return the builder itself enabling for chained method
* invocation to create joined commands
*/
public static interface Interface extends CommandInterface {
/**
* Reads from the standard input and compares adjacent lines, writing
one copy of each input line to the standard output. The second and
succeeding copies of repeated adjacent input lines are not written
to the output.
Note that repeated lines in the input are not detected if they are
not adjacent (see --global or -g option); sorted input lines always
result in unique output lines.
*
* @return the generic type {@code } defined by the implementing class;
* the command itself returns no value and writes its result to the
* standard output; see class level parameter comments for more
* details
*/
R uniq();
/**
* Reads the file specified by the {@code "--path"} operand (the
default operand) and writes only unique lines to the standard
output. The second and succeeding copies of repeated input lines are
not written to the output.
Options can be specified by acronym (with a leading dash "-") or by
long name (with two leading dashes "--"). Operands other than the
default "--path" operand have to be prefixed with the operand name.
Note that repeated lines in the input are not detected if they are
not adjacent unless the --global is specified (sorted input lines
always result in unique output lines).
*
* @param args String arguments defining the options and operands for the command.
Options can be specified by acronym (with a leading dash "-") or by
long name (with two leading dashes "--"). Operands other than the
default "--path" operand have to be prefixed with the operand
name.
* @return the generic type {@code } defined by the implementing class;
* the command itself returns no value and writes its result to the
* standard output; see class level parameter comments for more
* details
*/
R uniq(String... args);
/**
* Reads from the specified input {@code file} and compares adjacent
lines, writing one copy of each input line to the standard output.
The second and succeeding copies of repeated adjacent input lines
are not written to the output.
Note that repeated lines in the input are not detected if they are
not adjacent (see --global or -g option); sorted input lines always
result in unique output lines.
*
* @param file The files or directories used as starting point for the listing;
relative paths are not resolved (use the string path argument to
enable relative path resolving based on the current working
directory).
* @return the generic type {@code } defined by the implementing class;
* the command itself returns no value and writes its result to the
* standard output; see class level parameter comments for more
* details
*/
R uniq(java.io.File file);
/**
* Reads the file specified by its {@code path} and compares adjacent
lines, writing one copy of each input line to the standard output.
The second and succeeding copies of repeated adjacent input lines
are not written to the output.
Note that repeated lines in the input are not detected if they are
not adjacent (see --global or -g option); sorted input lines always
result in unique output lines.
*
* @param path The files or directories used as starting point for the listing;
wildcards * and ? are supported; relative paths are resolved on the
basis of the current working directory.
* @return the generic type {@code } defined by the implementing class;
* the command itself returns no value and writes its result to the
* standard output; see class level parameter comments for more
* details
*/
R uniq(String path);
/**
* Reads from the standard input and compares adjacent lines, writing
one copy of each input line to the standard output. The second and
succeeding copies of repeated adjacent input lines are not written
to the output.
Note that repeated non-adjacent lines in the input are only detected
with the --global or -g option. In other words, unique output lines
are guaranteed only if either (a) the --global or -g option is
specified, or (b) the input lines are sorted.
*
* @param options The options defining the uniqueness details for the output lines.
* @return the generic type {@code } defined by the implementing class;
* the command itself returns no value and writes its result to the
* standard output; see class level parameter comments for more
* details
*/
R uniq(UniqOptions options);
/**
* Reads from the specified input {@code file} and compares adjacent
lines, writing one copy of each input line to the standard output.
The second and succeeding copies of repeated adjacent input lines
are not written to the output.
Note that repeated non-adjacent lines in the input are only detected
with the --global or -g option. In other words, unique output lines
are guaranteed only if either (a) the --global or -g option is
specified, or (b) the input lines are sorted.
*
* @param options The options defining the uniqueness details for the output lines.
* @param file The files or directories used as starting point for the listing;
relative paths are not resolved (use the string path argument to
enable relative path resolving based on the current working
directory).
* @return the generic type {@code } defined by the implementing class;
* the command itself returns no value and writes its result to the
* standard output; see class level parameter comments for more
* details
*/
R uniq(UniqOptions options, java.io.File file);
/**
* Reads the file specified by its {@code path} and compares adjacent
lines, writing one copy of each input line to the standard output.
The second and succeeding copies of repeated adjacent input lines
are not written to the output.
Note that repeated non-adjacent lines in the input are only detected
with the --global or -g option. In other words, unique output lines
are guaranteed only if either (a) the --global or -g option is
specified, or (b) the input lines are sorted.
*
* @param options The options defining the uniqueness details for the output lines.
* @param path The files or directories used as starting point for the listing;
wildcards * and ? are supported; relative paths are resolved on the
basis of the current working directory.
* @return the generic type {@code } defined by the implementing class;
* the command itself returns no value and writes its result to the
* standard output; see class level parameter comments for more
* details
*/
R uniq(UniqOptions options, String path);
}
/**
* Options for the "uniq" command: {@link UniqOption#count c}, {@link UniqOption#duplicatedOnly d}, {@link UniqOption#uniqueOnly u}, {@link UniqOption#global g}.
*
*
* {@code -c} {@code --count} Precedes each output line with a count of the number of times the
line occurred in the input.
* {@code -d} {@code --duplicatedOnly} Suppresses the writing of lines that are not repeated in the input.
* {@code -u} {@code --uniqueOnly} Suppresses the writing of lines that are repeated in the input.
* {@code -g} {@code --global} Suppresses repeated lines globally, that is, if lines are
non-adjacent. This option guarantees unique output lines even if the
input lines are not sorted.
*
*/
public static final UniqOptionSets Options = UniqOptionSets.INSTANCE;
/**
* Singleton {@link UniqFactory factory} instance for the "uniq" command.
*/
public static final UniqFactory Factory = UniqFactory.INSTANCE;
// no instances
private Uniq() {
super();
}
}