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 [-lwm]}</td></tr> 024 * <tr><td width="10px"></td><td nowrap="nowrap">{@code wc [-lwm] <files>}</td></tr> 025 * <tr><td width="10px"></td><td nowrap="nowrap">{@code wc [-lwm] <paths>}</td></tr> 026 * </table> 027 * <p> 028 * See {@link Interface} for the corresponding command signature methods. 029 * <p> 030 * <b>DESCRIPTION</b> 031 * <p> 032 * <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> 033 * 034 * <p> 035 * <b>Options</b> 036 * <p> 037 * The following options are supported: 038 * <p> 039 * <table> 040 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -l}</td><td> </td><td nowrap="nowrap">{@code --lines}</td><td> </td><td>Executes a count of lines and writes this count to the output.</td></tr> 041 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -w}</td><td> </td><td nowrap="nowrap">{@code --words}</td><td> </td><td>Executes a count of words and writes this count to the output. A 042 word is a non-zero-length string of characters delimited by white 043 space as defined by {@link Character#isWhitespace(char)}.</td></tr> 044 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -m}</td><td> </td><td nowrap="nowrap">{@code --chars}</td><td> </td><td>Executes a count of chars and writes this count to the output.</td></tr> 045 * </table> 046 * <p> 047 * <b>OPERANDS</b> 048 * <p> 049 * The following operands are supported: 050 * <p> 051 * <table> 052 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <paths>}</td><td> : </td><td nowrap="nowrap">{@code String[]}</td><td> </td><td>Pathnames of the input files; wildcards * and ? are supported; 053 relative paths are resolved on the basis of the current working 054 directory.</td></tr> 055 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <files>}</td><td> : </td><td nowrap="nowrap">{@code java.io.File...}</td><td> </td><td>The input files; relative paths are not resolved (use the string 056 paths argument to enable relative path resolving based on the 057 current working directory).</td></tr> 058 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <args>}</td><td> : </td><td nowrap="nowrap">{@code String...}</td><td> </td><td>String arguments defining the options and operands for the command. 059 Options can be specified by acronym (with a leading dash "-") or by 060 long name (with two leading dashes "--"). Operands other than the 061 default "--paths" operand have to be prefixed with the operand 062 name.</td></tr> 063 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <options>}</td><td> : </td><td nowrap="nowrap">{@code WcOptions}</td><td> </td><td>The options defining command behavior.</td></tr> 064 * </table> 065 */ 066public final class Wc { 067 /** 068 * The "wc" command name. 069 */ 070 public static final String NAME = "wc"; 071 072 /** 073 * Interface defining all method signatures for the "wc" command. 074 * 075 * @param <R> 076 * the generic return type for all command signature methods 077 * to support different implementor types; the methods of a 078 * command factory for instance returns a command instance; 079 * command builders can also implement this interface, but their 080 * methods return the builder itself enabling for chained method 081 * invocation to create joined commands 082 */ 083 public static interface Interface<R> extends CommandInterface<R> { 084 /** 085 * Executes a count of lines, words and chars contained in the standard 086 input and writes them to the standard output. 087 * 088 * @return the generic type {@code <R>} defined by the implementing class; 089 * the command itself returns no value and writes its result to the 090 * standard output; see class level parameter comments for more 091 * details 092 */ 093 R wc(); 094 /** 095 * One or several counts are executed and written to the standard 096 output. Counts include lines, words and chars (depending on the 097 provided options) and cumulative counts for all the files are 098 displayed on a separate line after the output for the last file if 099 more than one input file is specified. 100<p> 101 Options can be specified by acronym (with a leading dash "-") or by 102 long name (with two leading dashes "--"). Operands other than the 103 default "--paths" operand have to be prefixed with the operand 104 name. 105 * 106 * @param args String arguments defining the options and operands for the command. 107 Options can be specified by acronym (with a leading dash "-") or by 108 long name (with two leading dashes "--"). Operands other than the 109 default "--paths" operand have to be prefixed with the operand 110 name. 111 * @return the generic type {@code <R>} defined by the implementing class; 112 * the command itself returns no value and writes its result to the 113 * standard output; see class level parameter comments for more 114 * details 115 */ 116 R wc(String... args); 117 /** 118 * Executes a count of lines, words and chars contained in each input 119 file and writes them to the standard output. If more than one input 120 file is specified, a line of cumulative counts for all the files is 121 displayed on a separate line after the output for the last file. 122 * 123 * @param files The input files; relative paths are not resolved (use the string 124 paths argument to enable relative path resolving based on the 125 current working directory). 126 * @return the generic type {@code <R>} defined by the implementing class; 127 * the command itself returns no value and writes its result to the 128 * standard output; see class level parameter comments for more 129 * details 130 */ 131 R wc(java.io.File... files); 132 /** 133 * Executes a one or more counts, depending on the given options, in 134 the standard input and writes them to the standard output. 135 * 136 * @param options The options defining command behavior. 137 * @return the generic type {@code <R>} defined by the implementing class; 138 * the command itself returns no value and writes its result to the 139 * standard output; see class level parameter comments for more 140 * details 141 */ 142 R wc(WcOptions options); 143 /** 144 * Executes a one or more counts, depending on the given options, in 145 each of the given input files and writes them to the standard 146 output. If more than one input file is specified, a line of 147 cumulative counts for all the files is displayed on a separate line 148 after the output for the last file. 149 * 150 * @param options The options defining command behavior. 151 * @param files The input files; relative paths are not resolved (use the string 152 paths argument to enable relative path resolving based on the 153 current working directory). 154 * @return the generic type {@code <R>} defined by the implementing class; 155 * the command itself returns no value and writes its result to the 156 * standard output; see class level parameter comments for more 157 * details 158 */ 159 R wc(WcOptions options, java.io.File... files); 160 /** 161 * Executes a one or more counts, depending on the given options, in 162 each of the given input files and writes them to the standard 163 output. If more than one input file is specified, a line of 164 cumulative counts for all the files is displayed on a separate line 165 after the output for the last file. 166 * 167 * @param options The options defining command behavior. 168 * @param paths Pathnames of the input files; wildcards * and ? are supported; 169 relative paths are resolved on the basis of the current working 170 directory. 171 * @return the generic type {@code <R>} defined by the implementing class; 172 * the command itself returns no value and writes its result to the 173 * standard output; see class level parameter comments for more 174 * details 175 */ 176 R wc(WcOptions options, String[] paths); 177 } 178 179 /** 180 * Options for the "wc" command: {@link WcOption#lines l}, {@link WcOption#words w}, {@link WcOption#chars m}. 181 * <p> 182 * <table> 183 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -l}</td><td> </td><td nowrap="nowrap">{@code --lines}</td><td> </td><td>Executes a count of lines and writes this count to the output.</td></tr> 184 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -w}</td><td> </td><td nowrap="nowrap">{@code --words}</td><td> </td><td>Executes a count of words and writes this count to the output. A 185 word is a non-zero-length string of characters delimited by white 186 space as defined by {@link Character#isWhitespace(char)}.</td></tr> 187 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -m}</td><td> </td><td nowrap="nowrap">{@code --chars}</td><td> </td><td>Executes a count of chars and writes this count to the output.</td></tr> 188 * </table> 189 */ 190 public static final WcOptionSets Options = WcOptionSets.INSTANCE; 191 192 /** 193 * Singleton {@link WcFactory factory} instance for the "wc" command. 194 */ 195 public static final WcFactory Factory = WcFactory.INSTANCE; 196 197 // no instances 198 private Wc() { 199 super(); 200 } 201}