001package org.unix4j.unix;
002
003import org.unix4j.command.CommandInterface;
004
005import org.unix4j.unix.wc.WcFactory;
006import org.unix4j.unix.wc.WcOption;
007import org.unix4j.unix.wc.WcOptions;
008import org.unix4j.unix.wc.WcOptionSets;
009
010/**
011 * Non-instantiable module with inner types making up the <b>wc</b> command.
012 * <p>
013 * <b>NAME</b>
014 * <p>
015 * wc - word, line, and byte or character count 
016 * <p>
017 * <b>SYNOPSIS</b>
018 * <p>
019 * <table>
020 * <tr><td width="10px"></td><td nowrap="nowrap">{@code wc}</td></tr>
021 * <tr><td width="10px"></td><td nowrap="nowrap">{@code wc <args>}</td></tr>
022 * <tr><td width="10px"></td><td nowrap="nowrap">{@code wc <files>}</td></tr>
023 * <tr><td width="10px"></td><td nowrap="nowrap">{@code wc <inputs>}</td></tr>
024 * <tr><td width="10px"></td><td nowrap="nowrap">{@code wc [-lwm]}</td></tr>
025 * <tr><td width="10px"></td><td nowrap="nowrap">{@code wc [-lwm] <files>}</td></tr>
026 * <tr><td width="10px"></td><td nowrap="nowrap">{@code wc [-lwm] <paths>}</td></tr>
027 * <tr><td width="10px"></td><td nowrap="nowrap">{@code wc [-lwm] <inputs>}</td></tr>
028 * </table>
029 * <p>
030 * See {@link Interface} for the corresponding command signature methods.
031 * <p>
032 * <b>DESCRIPTION</b>
033 * <p>
034 * <p>The wc utility reads from the input and, by default, writes thenumber of lines, words, and characters to the output. If more than one input file is specified, a line of cumulative counts for all the files is displayed ona separate line after the output for the last file.</p><p>The wc utility considers a word to be a non-zero-length string of charactersdelimited by white space. White space characters are the set of characters for which {@link Character#isWhitespace(char)} returns true.</p><p>When any option is specified, wc reports only the information requested bythe specified options.</p><p>If only one count type is requested, the count is outputted as an integer. Ifmore than one count is requested, a fixed width formatting is used, with thecounts being right aligned. The width of each field is equal to the width ofthe widest field (count) plus two characters.</p>
035 * 
036 * <p>
037 * <b>Options</b>
038 * <p>
039 * The following options are supported:
040 * <p>
041 * <table>
042 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -l}</td><td>&nbsp;&nbsp;</td><td nowrap="nowrap">{@code --lines}</td><td>&nbsp;</td><td>Executes a count of lines and writes this count to the output.</td></tr>
043 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -w}</td><td>&nbsp;&nbsp;</td><td nowrap="nowrap">{@code --words}</td><td>&nbsp;</td><td>Executes a count of words and writes this count to the output. A
044                        word is a non-zero-length string of characters delimited by white
045                        space as defined by {@link Character#isWhitespace(char)}.</td></tr>
046 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -m}</td><td>&nbsp;&nbsp;</td><td nowrap="nowrap">{@code --chars}</td><td>&nbsp;</td><td>Executes a count of chars and writes this count to the output.</td></tr>
047 * </table>
048 * <p>
049 * <b>OPERANDS</b>
050 * <p>
051 * The following operands are supported:
052 * <p>
053 * <table>
054 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <paths>}</td><td>&nbsp;:&nbsp;</td><td nowrap="nowrap">{@code String[]}</td><td>&nbsp;</td><td>Path names of the input files; wildcards * and ? are supported;
055                        relative paths are resolved on the basis of the current working 
056                        directory.</td></tr>
057 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <files>}</td><td>&nbsp;:&nbsp;</td><td nowrap="nowrap">{@code java.io.File...}</td><td>&nbsp;</td><td>The input files; relative paths are not resolved (use the string
058                        paths argument to enable relative path resolving based on the
059                        current working directory).</td></tr>
060 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <inputs>}</td><td>&nbsp;:&nbsp;</td><td nowrap="nowrap">{@code org.unix4j.io.Input...}</td><td>&nbsp;</td><td>The inputs.</td></tr>
061 * <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. 
062                        Options can be specified by acronym (with a leading dash "-") or by 
063                        long name (with two leading dashes "--"). Operands other than the
064                        default "--paths" operand have to be prefixed with the operand 
065                        name.</td></tr>
066 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <options>}</td><td>&nbsp;:&nbsp;</td><td nowrap="nowrap">{@code WcOptions}</td><td>&nbsp;</td><td>The options defining command behavior.</td></tr>
067 * </table>
068 */
069public final class Wc {
070        /**
071         * The "wc" command name.
072         */
073        public static final String NAME = "wc";
074
075        /**
076         * Interface defining all method signatures for the "wc" command.
077         * 
078         * @param <R>
079         *            the generic return type for all command signature methods
080         *            to support different implementor types; the methods of a 
081         *            command factory for instance returns a command instance; 
082         *            command builders can also implement this interface, but their
083         *            methods return the builder itself enabling for chained method
084         *            invocation to create joined commands
085         */
086        public static interface Interface<R> extends CommandInterface<R> {
087                /**
088                 * Executes a count of lines, words and chars contained in the standard
089                        input and writes them to the standard output.
090                 *
091                 * @return the generic type {@code <R>} defined by the implementing class;
092                 *         the command itself returns no value and writes its result to the
093                 *         standard output; see class level parameter comments for more 
094                 *         details
095                 */
096                R wc();
097                /**
098                 * One or several counts are executed and written to the standard 
099                        output. Counts include lines, words and chars (depending on the 
100                        provided options) and cumulative counts for all the files are 
101                        displayed on a separate line after the output for the last file if
102                        more than one input file is specified. 
103<p>
104                        Options can be specified by acronym (with a leading dash "-") or by 
105                        long name (with two leading dashes "--"). Operands other than the 
106                        default "--paths" operand have to be prefixed with the operand 
107                        name.
108                 *
109                 * @param args String arguments defining the options and operands for the command. 
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 "--paths" operand have to be prefixed with the operand 
113                        name.
114                 * @return the generic type {@code <R>} defined by the implementing class;
115                 *         the command itself returns no value and writes its result to the
116                 *         standard output; see class level parameter comments for more 
117                 *         details
118                 */
119                R wc(String... args);
120                /**
121                 * Executes a count of lines, words and chars contained in each input
122                        file and writes them to the standard output. If more than one input
123                        file is specified, a line of cumulative counts for all the files is
124                        displayed on a separate line after the output for the last file.
125                 *
126                 * @param files The input files; relative paths are not resolved (use the string
127                        paths argument to enable relative path resolving based on the
128                        current working directory).
129                 * @return the generic type {@code <R>} defined by the implementing class;
130                 *         the command itself returns no value and writes its result to the
131                 *         standard output; see class level parameter comments for more 
132                 *         details
133                 */
134                R wc(java.io.File... files);
135                /**
136                 * Executes a count of lines, words and chars contained in each input
137                        and writes them to the standard output. If more than one input
138                        is specified, a line of cumulative counts for all the inputs is
139                        displayed on a separate line after the output for the last input.
140                 *
141                 * @param inputs The inputs.
142                 * @return the generic type {@code <R>} defined by the implementing class;
143                 *         the command itself returns no value and writes its result to the
144                 *         standard output; see class level parameter comments for more 
145                 *         details
146                 */
147                R wc(org.unix4j.io.Input... inputs);
148                /**
149                 * Executes a one or more counts, depending on the given options, in
150                        the standard input and writes them to the standard output.
151                 *
152                 * @param options The options defining command behavior.
153                 * @return the generic type {@code <R>} defined by the implementing class;
154                 *         the command itself returns no value and writes its result to the
155                 *         standard output; see class level parameter comments for more 
156                 *         details
157                 */
158                R wc(WcOptions options);
159                /**
160                 * Executes a one or more counts, depending on the given options, in
161                        each of the given input files and writes them to the standard 
162                        output. If more than one input file is specified, a line of 
163                        cumulative counts for all the files is displayed on a separate line 
164                        after the output for the last file.
165                 *
166                 * @param options The options defining command behavior.
167                 * @param files The input files; relative paths are not resolved (use the string
168                        paths argument to enable relative path resolving based on the
169                        current working directory).
170                 * @return the generic type {@code <R>} defined by the implementing class;
171                 *         the command itself returns no value and writes its result to the
172                 *         standard output; see class level parameter comments for more 
173                 *         details
174                 */
175                R wc(WcOptions options, java.io.File... files);
176                /**
177                 * Executes a one or more counts, depending on the given options, in
178                        each of the given input files and writes them to the standard 
179                        output. If more than one input file is specified, a line of 
180                        cumulative counts for all the files is displayed on a separate line
181                        after the output for the last file.
182                 *
183                 * @param options The options defining command behavior.
184                 * @param paths Path names of the input files; wildcards * and ? are supported;
185                        relative paths are resolved on the basis of the current working 
186                        directory.
187                 * @return the generic type {@code <R>} defined by the implementing class;
188                 *         the command itself returns no value and writes its result to the
189                 *         standard output; see class level parameter comments for more 
190                 *         details
191                 */
192                R wc(WcOptions options, String[] paths);
193                /**
194                 * Executes a one or more counts, depending on the given options, in
195                        each of the given inputs and writes them to the standard
196                        output. If more than one inputs is specified, a line of
197                        cumulative counts for all the inputs is displayed on a separate line
198                        after the output for the last input.
199                 *
200                 * @param options The options defining command behavior.
201                 * @param inputs The inputs.
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 wc(WcOptions options, org.unix4j.io.Input... inputs);
208        }
209
210        /**
211         * Options for the "wc" command: {@link WcOption#lines l}, {@link WcOption#words w}, {@link WcOption#chars m}.
212         * <p> 
213 * <table>
214 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -l}</td><td>&nbsp;&nbsp;</td><td nowrap="nowrap">{@code --lines}</td><td>&nbsp;</td><td>Executes a count of lines and writes this count to the output.</td></tr>
215 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -w}</td><td>&nbsp;&nbsp;</td><td nowrap="nowrap">{@code --words}</td><td>&nbsp;</td><td>Executes a count of words and writes this count to the output. A
216                        word is a non-zero-length string of characters delimited by white
217                        space as defined by {@link Character#isWhitespace(char)}.</td></tr>
218 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -m}</td><td>&nbsp;&nbsp;</td><td nowrap="nowrap">{@code --chars}</td><td>&nbsp;</td><td>Executes a count of chars and writes this count to the output.</td></tr>
219 * </table>
220         */
221        public static final WcOptionSets Options = WcOptionSets.INSTANCE;
222
223        /**
224         * Singleton {@link WcFactory factory} instance for the "wc" command.
225         */
226        public static final WcFactory Factory = WcFactory.INSTANCE;
227
228        // no instances
229        private Wc() {
230                super();
231        }
232}