001package org.unix4j.unix;
002
003import org.unix4j.command.CommandInterface;
004
005import org.unix4j.unix.uniq.UniqFactory;
006import org.unix4j.unix.uniq.UniqOption;
007import org.unix4j.unix.uniq.UniqOptions;
008import org.unix4j.unix.uniq.UniqOptionSets;
009
010/**
011 * Non-instantiable module with inner types making up the <b>uniq</b> command.
012 * <p>
013 * <b>NAME</b>
014 * <p>
015 * uniq - report or filter out repeated lines in a usually pre-sorted file 
016 * <p>
017 * <b>SYNOPSIS</b>
018 * <p>
019 * <table>
020 * <tr><td width="10px"></td><td nowrap="nowrap">{@code uniq}</td></tr>
021 * <tr><td width="10px"></td><td nowrap="nowrap">{@code uniq <args>}</td></tr>
022 * <tr><td width="10px"></td><td nowrap="nowrap">{@code uniq <file>}</td></tr>
023 * <tr><td width="10px"></td><td nowrap="nowrap">{@code uniq <path>}</td></tr>
024 * <tr><td width="10px"></td><td nowrap="nowrap">{@code uniq [-cdug]}</td></tr>
025 * <tr><td width="10px"></td><td nowrap="nowrap">{@code uniq [-cdug] <file>}</td></tr>
026 * <tr><td width="10px"></td><td nowrap="nowrap">{@code uniq [-cdug] <path>}</td></tr>
027 * </table>
028 * <p>
029 * See {@link Interface} for the corresponding command signature methods.
030 * <p>
031 * <b>DESCRIPTION</b>
032 * <p>
033 *  <p> 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. </p> <p> 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. </p> 
034 * 
035 * <p>
036 * <b>Options</b>
037 * <p>
038 * The following options are supported:
039 * <p>
040 * <table>
041 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -c}</td><td>&nbsp;&nbsp;</td><td nowrap="nowrap">{@code --count}</td><td>&nbsp;</td><td>Precedes each output line with a count of the number of times the
042                        line occurred in the input.</td></tr>
043 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -d}</td><td>&nbsp;&nbsp;</td><td nowrap="nowrap">{@code --duplicatedOnly}</td><td>&nbsp;</td><td>Suppresses the writing of lines that are not repeated in the input.</td></tr>
044 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -u}</td><td>&nbsp;&nbsp;</td><td nowrap="nowrap">{@code --uniqueOnly}</td><td>&nbsp;</td><td>Suppresses the writing of lines that are repeated in the input.</td></tr>
045 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -g}</td><td>&nbsp;&nbsp;</td><td nowrap="nowrap">{@code --global}</td><td>&nbsp;</td><td>Suppresses repeated lines globally, that is, if lines are 
046                        non-adjacent. This option guarantees unique output lines even if the
047                        input lines are not sorted.</td></tr>
048 * </table>
049 * <p>
050 * <b>OPERANDS</b>
051 * <p>
052 * The following operands are supported:
053 * <p>
054 * <table>
055 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <file>}</td><td>&nbsp;:&nbsp;</td><td nowrap="nowrap">{@code java.io.File}</td><td>&nbsp;</td><td>The files or directories used as starting point for the listing; 
056                        relative paths are not resolved (use the string path argument to 
057                        enable relative path resolving based on the current working 
058                        directory).</td></tr>
059 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <path>}</td><td>&nbsp;:&nbsp;</td><td nowrap="nowrap">{@code String}</td><td>&nbsp;</td><td>The files or directories used as starting point for the listing; 
060                        wildcards * and ? are supported; relative paths are resolved on the
061            basis of the current working directory.</td></tr>
062 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <args>}</td><td>&nbsp;:&nbsp;</td><td nowrap="nowrap">{@code String...}</td><td>&nbsp;</td><td>String arguments defining the options and operands for the command. 
063                        Options can be specified by acronym (with a leading dash "-") or by 
064                        long name (with two leading dashes "--"). Operands other than the
065                        default "--path" operand have to be prefixed with the operand 
066                        name.</td></tr>
067 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <options>}</td><td>&nbsp;:&nbsp;</td><td nowrap="nowrap">{@code UniqOptions}</td><td>&nbsp;</td><td>The options defining the uniqueness details for the output lines.</td></tr>
068 * </table>
069 */
070public final class Uniq {
071        /**
072         * The "uniq" command name.
073         */
074        public static final String NAME = "uniq";
075
076        /**
077         * Interface defining all method signatures for the "uniq" command.
078         * 
079         * @param <R>
080         *            the generic return type for all command signature methods
081         *            to support different implementor types; the methods of a 
082         *            command factory for instance returns a command instance; 
083         *            command builders can also implement this interface, but their
084         *            methods return the builder itself enabling for chained method
085         *            invocation to create joined commands
086         */
087        public static interface Interface<R> extends CommandInterface<R> {
088                /**
089                 * Reads from the standard input and compares adjacent lines, writing
090                        one copy  of each input line to the standard output. The second and 
091                        succeeding copies of repeated adjacent input lines are not written
092                        to the output.
093                        <p>
094                        Note that repeated lines in the input are not detected if they are 
095                        not adjacent (see --global or -g option); sorted input lines always
096                        result in unique output lines.
097                 *
098                 * @return the generic type {@code <R>} defined by the implementing class;
099                 *         the command itself returns no value and writes its result to the
100                 *         standard output; see class level parameter comments for more 
101                 *         details
102                 */
103                R uniq();
104                /**
105                 * Reads the file specified by the {@code "--path"} operand (the 
106                        default operand) and writes only unique lines to the standard 
107                        output. The second and succeeding copies of repeated input lines are 
108                        not written to the output.
109                        <p>
110                        Options can be specified by acronym (with a leading dash "-") or by 
111                        long name (with two leading dashes "--"). Operands other than the 
112                        default "--path" operand have to be prefixed with the operand name. 
113<p>
114                        Note that repeated lines in the input are not detected if they are 
115                        not adjacent unless the --global is specified (sorted input lines 
116                        always result in unique output lines).
117                 *
118                 * @param args String arguments defining the options and operands for the command. 
119                        Options can be specified by acronym (with a leading dash "-") or by 
120                        long name (with two leading dashes "--"). Operands other than the
121                        default "--path" operand have to be prefixed with the operand 
122                        name.
123                 * @return the generic type {@code <R>} defined by the implementing class;
124                 *         the command itself returns no value and writes its result to the
125                 *         standard output; see class level parameter comments for more 
126                 *         details
127                 */
128                R uniq(String... args);
129                /**
130                 * Reads from the specified input {@code file} and compares adjacent
131                        lines, writing one copy of each input line to the standard output. 
132                        The second and succeeding copies of repeated adjacent input lines 
133                        are not written to the output.
134                        <p>
135                        Note that repeated lines in the input are not detected if they are 
136                        not adjacent (see --global or -g option); sorted input lines always
137                        result in unique output lines.
138                 *
139                 * @param file The files or directories used as starting point for the listing; 
140                        relative paths are not resolved (use the string path argument to 
141                        enable relative path resolving based on the current working 
142                        directory).
143                 * @return the generic type {@code <R>} defined by the implementing class;
144                 *         the command itself returns no value and writes its result to the
145                 *         standard output; see class level parameter comments for more 
146                 *         details
147                 */
148                R uniq(java.io.File file);
149                /**
150                 * Reads the file specified by its {@code path} and compares adjacent
151                        lines, writing one copy of each input line to the standard output. 
152                        The second and succeeding copies of repeated adjacent input lines 
153                        are not written to the output.
154                        <p>
155                        Note that repeated lines in the input are not detected if they are 
156                        not adjacent (see --global or -g option); sorted input lines always
157                        result in unique output lines.
158                 *
159                 * @param path The files or directories used as starting point for the listing; 
160                        wildcards * and ? are supported; relative paths are resolved on the
161            basis of the current working directory.
162                 * @return the generic type {@code <R>} defined by the implementing class;
163                 *         the command itself returns no value and writes its result to the
164                 *         standard output; see class level parameter comments for more 
165                 *         details
166                 */
167                R uniq(String path);
168                /**
169                 * Reads from the standard input and compares adjacent lines, writing
170                        one copy  of each input line to the standard output. The second and 
171                        succeeding copies of repeated adjacent input lines are not written
172                        to the output.
173                        <p>
174                        Note that repeated non-adjacent lines in the input are only detected
175                        with the --global or -g option. In other words, unique output lines
176                        are guaranteed only if either (a) the --global or -g option is
177                        specified, or (b) the input lines are sorted.
178                 *
179                 * @param options The options defining the uniqueness details for the output lines.
180                 * @return the generic type {@code <R>} defined by the implementing class;
181                 *         the command itself returns no value and writes its result to the
182                 *         standard output; see class level parameter comments for more 
183                 *         details
184                 */
185                R uniq(UniqOptions options);
186                /**
187                 * Reads from the specified input {@code file} and compares adjacent
188                        lines, writing one copy of each input line to the standard output. 
189                        The second and succeeding copies of repeated adjacent input lines 
190                        are not written to the output.
191                        <p>
192                        Note that repeated non-adjacent lines in the input are only detected
193                        with the --global or -g option. In other words, unique output lines
194                        are guaranteed only if either (a) the --global or -g option is
195                        specified, or (b) the input lines are sorted.
196                 *
197                 * @param options The options defining the uniqueness details for the output lines.
198                 * @param file The files or directories used as starting point for the listing; 
199                        relative paths are not resolved (use the string path argument to 
200                        enable relative path resolving based on the current working 
201                        directory).
202                 * @return the generic type {@code <R>} defined by the implementing class;
203                 *         the command itself returns no value and writes its result to the
204                 *         standard output; see class level parameter comments for more 
205                 *         details
206                 */
207                R uniq(UniqOptions options, java.io.File file);
208                /**
209                 * Reads the file specified by its {@code path} and compares adjacent
210                        lines, writing one copy of each input line to the standard output. 
211                        The second and succeeding copies of repeated adjacent input lines 
212                        are not written to the output.
213                        <p>
214                        Note that repeated non-adjacent lines in the input are only detected
215                        with the --global or -g option. In other words, unique output lines
216                        are guaranteed only if either (a) the --global or -g option is
217                        specified, or (b) the input lines are sorted.
218                 *
219                 * @param options The options defining the uniqueness details for the output lines.
220                 * @param path The files or directories used as starting point for the listing; 
221                        wildcards * and ? are supported; relative paths are resolved on the
222            basis of the current working directory.
223                 * @return the generic type {@code <R>} defined by the implementing class;
224                 *         the command itself returns no value and writes its result to the
225                 *         standard output; see class level parameter comments for more 
226                 *         details
227                 */
228                R uniq(UniqOptions options, String path);
229        }
230
231        /**
232         * Options for the "uniq" command: {@link UniqOption#count c}, {@link UniqOption#duplicatedOnly d}, {@link UniqOption#uniqueOnly u}, {@link UniqOption#global g}.
233         * <p> 
234 * <table>
235 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -c}</td><td>&nbsp;&nbsp;</td><td nowrap="nowrap">{@code --count}</td><td>&nbsp;</td><td>Precedes each output line with a count of the number of times the
236                        line occurred in the input.</td></tr>
237 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -d}</td><td>&nbsp;&nbsp;</td><td nowrap="nowrap">{@code --duplicatedOnly}</td><td>&nbsp;</td><td>Suppresses the writing of lines that are not repeated in the input.</td></tr>
238 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -u}</td><td>&nbsp;&nbsp;</td><td nowrap="nowrap">{@code --uniqueOnly}</td><td>&nbsp;</td><td>Suppresses the writing of lines that are repeated in the input.</td></tr>
239 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -g}</td><td>&nbsp;&nbsp;</td><td nowrap="nowrap">{@code --global}</td><td>&nbsp;</td><td>Suppresses repeated lines globally, that is, if lines are 
240                        non-adjacent. This option guarantees unique output lines even if the
241                        input lines are not sorted.</td></tr>
242 * </table>
243         */
244        public static final UniqOptionSets Options = UniqOptionSets.INSTANCE;
245
246        /**
247         * Singleton {@link UniqFactory factory} instance for the "uniq" command.
248         */
249        public static final UniqFactory Factory = UniqFactory.INSTANCE;
250
251        // no instances
252        private Uniq() {
253                super();
254        }
255}