001package org.unix4j.unix; 002 003import org.unix4j.command.CommandInterface; 004 005import org.unix4j.unix.sort.SortFactory; 006import org.unix4j.unix.sort.SortOption; 007import org.unix4j.unix.sort.SortOptions; 008import org.unix4j.unix.sort.SortOptionSets; 009 010/** 011 * Non-instantiable module with inner types making up the <b>sort</b> command. 012 * <p> 013 * <b>NAME</b> 014 * <p> 015 * sort - sort, merge, or sequence check text files 016 * <p> 017 * <b>SYNOPSIS</b> 018 * <p> 019 * <table> 020 * <tr><td width="10px"></td><td nowrap="nowrap">{@code sort}</td></tr> 021 * <tr><td width="10px"></td><td nowrap="nowrap">{@code sort <args>}</td></tr> 022 * <tr><td width="10px"></td><td nowrap="nowrap">{@code sort <files>}</td></tr> 023 * <tr><td width="10px"></td><td nowrap="nowrap">{@code sort <inputs>}</td></tr> 024 * <tr><td width="10px"></td><td nowrap="nowrap">{@code sort <comparator>}</td></tr> 025 * <tr><td width="10px"></td><td nowrap="nowrap">{@code sort <comparator> <files>}</td></tr> 026 * <tr><td width="10px"></td><td nowrap="nowrap">{@code sort <comparator> <paths>}</td></tr> 027 * <tr><td width="10px"></td><td nowrap="nowrap">{@code sort <comparator> <inputs>}</td></tr> 028 * <tr><td width="10px"></td><td nowrap="nowrap">{@code sort [-cmubdfnghMVr]}</td></tr> 029 * <tr><td width="10px"></td><td nowrap="nowrap">{@code sort [-cmubdfnghMVr] <files>}</td></tr> 030 * <tr><td width="10px"></td><td nowrap="nowrap">{@code sort [-cmubdfnghMVr] <paths>}</td></tr> 031 * <tr><td width="10px"></td><td nowrap="nowrap">{@code sort [-cmubdfnghMVr] <inputs>}</td></tr> 032 * <tr><td width="10px"></td><td nowrap="nowrap">{@code sort [-cmubdfnghMVr] <comparator>}</td></tr> 033 * <tr><td width="10px"></td><td nowrap="nowrap">{@code sort [-cmubdfnghMVr] <comparator> <files>}</td></tr> 034 * <tr><td width="10px"></td><td nowrap="nowrap">{@code sort [-cmubdfnghMVr] <comparator> <paths>}</td></tr> 035 * <tr><td width="10px"></td><td nowrap="nowrap">{@code sort [-cmubdfnghMVr] <comparator> <inputs>}</td></tr> 036 * </table> 037 * <p> 038 * See {@link Interface} for the corresponding command signature methods. 039 * <p> 040 * <b>DESCRIPTION</b> 041 * <p> 042 * <p> The sort utility performs one of the following functions: <ol> <li> Sort lines of all the named files together and write the result to the specified output. </li> <li> Merge lines of all the named (presorted) files together and write the result to the specified output. </li> <li> Check that a single input file is correctly presorted. </li> </ol></p><p> Comparisons are based on one or more sort keys/fields extracted from each line of input. If no sort keys/fields are specified, comparisons are based on the entire line up to, but not including, the terminating <newline>. All comparisons are performed using the collating sequence of the current locale.</p><p> Sorting is stable, that is, the ordering of input lines is preserved if they are considered equal according to the current comparison criteria (if two lines originate from different input files, the index of the file in the input arguments list defines the ordering of the lines). </p> 043 * 044 * <p> 045 * <b>NOTES</b> 046 * <p> 047 * <ul> 048 * <li>A <newline> is added to the end of an input line if it is not 049 properly terminated with a line ending (usually the last line in a file)</li> 050 * 051 * <li>The following sort order options are currently not supported: {@code dictionaryOrder}, {@code humanNumericSort}, {@code monthSort}, {@code versionSort}</li> 052 * </ul> 053 * 054 * <p> 055 * <b>Options</b> 056 * <p> 057 * The following options are supported: 058 * <p> 059 * <table> 060 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -c}</td><td> </td><td nowrap="nowrap">{@code --check}</td><td> </td><td>Checks that the single input file is ordered as specified by the 061 arguments and the collating sequence of the current locale. No 062 output is produced; only the exit code is affected.</td></tr> 063 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -m}</td><td> </td><td nowrap="nowrap">{@code --merge}</td><td> </td><td>Merge only; the input file are assumed to be already sorted.</td></tr> 064 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -u}</td><td> </td><td nowrap="nowrap">{@code --unique}</td><td> </td><td>Unique: suppress all but one in each set of lines having equal keys. 065 If used with the {@code -c} option, checks that there are no lines 066 with duplicate keys, in addition to checking that the input file is 067 sorted.</td></tr> 068 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -b}</td><td> </td><td nowrap="nowrap">{@code --ignoreLeadingBlanks}</td><td> </td><td>Ignore leading blanks. 069 (This option is ignored if a comparator operand is present).</td></tr> 070 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -d}</td><td> </td><td nowrap="nowrap">{@code --dictionaryOrder}</td><td> </td><td>Consider only blanks and alphanumeric characters. 071 (This option is ignored if a comparator operand is present).</td></tr> 072 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -f}</td><td> </td><td nowrap="nowrap">{@code --ignoreCase}</td><td> </td><td>Consider all lowercase characters that have uppercase equivalents to 073 be the uppercase equivalent for the purposes of comparison. 074 (This option is ignored if a comparator operand is present).</td></tr> 075 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -n}</td><td> </td><td nowrap="nowrap">{@code --numericSort}</td><td> </td><td>Sort numerically; the number begins each line and consists of 076 optional blanks, an optional minus sign, and zero or more digits 077 possibly separated by thousands separators, optionally followed by a 078 decimal-point character and zero or more digits. An empty number is 079 treated as '0'. The current local specifies the decimal-point 080 character and thousands separator. 081 <p> 082 Comparison is exact; there is no rounding error. 083 <p> 084 Neither a leading '+' nor exponential notation is recognized. To 085 compare such strings numerically, use the 086 {@code -genericNumericSort (-g)} option. 087<p> 088 (This option is ignored if a comparator operand is present).</td></tr> 089 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -g}</td><td> </td><td nowrap="nowrap">{@code --generalNumericSort}</td><td> </td><td>Sort numerically, using the standard {@link Double#parseDouble(String)} 090 function to convert a trimmed line to a double-precision floating 091 point number. This allows floating point numbers to be specified in 092 scientific notation, like 1.0e-34 and 10e100. 093 <p> 094 Uses the following collating sequence: Lines that cannot be parsed 095 because they do not represent valid double values (in alpha-numeric 096 order); "-Infinity"; finite numbers in ascending numeric order 097 (with -0 < +0); "Infinity"; "NaN". 098<p> 099 This option is usually slower than {@code -numeric-sort (-n)} and it 100 can lose information when converting to floating point. 101 <p> 102 (This option is ignored if a comparator operand is present).</td></tr> 103 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -h}</td><td> </td><td nowrap="nowrap">{@code --humanNumericSort}</td><td> </td><td>Sort numerically, first by numeric sign (negative, zero, or 104 positive); then by SI suffix (either empty, or 'k' or 'K', or one 105 of 'MGTPEZY', in that order); and finally by numeric value. For 106 example, '1023M' sorts before '1G' because 'M' (mega) precedes 'G' 107 (giga) as an SI suffix. 108 <p> 109 This option sorts values that are consistently scaled to the nearest 110 suffix, regardless of whether suffixes denote powers of 1000 or 111 1024, and it therefore sorts the output of any single invocation of 112 the {@code ls} command that are invoked with the --human-readable 113 option. 114 <p> 115 The syntax for numbers is the same as for the 116 {@code --numericSort (-n)} option; the SI suffix must immediately 117 follow the number. 118<p> 119 (This option is ignored if a comparator operand is present).</td></tr> 120 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -M}</td><td> </td><td nowrap="nowrap">{@code --monthSort}</td><td> </td><td>An initial string, consisting of any amount of blanks, followed by a 121 month name abbreviation, is folded to UPPER case and compared in the 122 order: (unknown) < 'JAN' < ... < 'DEC'. The current locale 123 determines the month spellings.</td></tr> 124 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -V}</td><td> </td><td nowrap="nowrap">{@code --versionSort}</td><td> </td><td>Sort by version name and number. It behaves like a standard sort, 125 except that each sequence of decimal digits is treated numerically 126 as an index/version number. 127 <p> 128 (This option is ignored if a comparator operand is present).</td></tr> 129 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -r}</td><td> </td><td nowrap="nowrap">{@code --reverse}</td><td> </td><td>Reverse the sense of comparisons.</td></tr> 130 * </table> 131 * <p> 132 * <b>OPERANDS</b> 133 * <p> 134 * The following operands are supported: 135 * <p> 136 * <table> 137 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <paths>}</td><td> : </td><td nowrap="nowrap">{@code String...}</td><td> </td><td>Path names of the files to be sorted, merged, or checked; wildcards * 138 and ? are supported; relative paths are resolved on the 139 basis of the current working directory.</td></tr> 140 * <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 files to be sorted or merged; relative paths are not resolved 141 (use the string paths argument to enable relative path resolving 142 based on the current working directory).</td></tr> 143 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <inputs>}</td><td> : </td><td nowrap="nowrap">{@code org.unix4j.io.Input...}</td><td> </td><td>The inputs to be sorted or merged.</td></tr> 144 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <comparator>}</td><td> : </td><td nowrap="nowrap">{@code java.util.Comparator<? super org.unix4j.line.Line>}</td><td> </td><td>The comparator to use for the line comparisons.</td></tr> 145 * <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. 146 Options can be specified by acronym (with a leading dash "-") or by 147 long name (with two leading dashes "--"). Operands other than the 148 default "--paths" operand have to be prefixed with the operand 149 name (e.g. "--comparator" for a subsequent comparator operand value).</td></tr> 150 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <options>}</td><td> : </td><td nowrap="nowrap">{@code SortOptions}</td><td> </td><td>The options for the sort command.</td></tr> 151 * </table> 152 */ 153public final class Sort { 154 /** 155 * The "sort" command name. 156 */ 157 public static final String NAME = "sort"; 158 159 /** 160 * Interface defining all method signatures for the "sort" command. 161 * 162 * @param <R> 163 * the generic return type for all command signature methods 164 * to support different implementor types; the methods of a 165 * command factory for instance returns a command instance; 166 * command builders can also implement this interface, but their 167 * methods return the builder itself enabling for chained method 168 * invocation to create joined commands 169 */ 170 public static interface Interface<R> extends CommandInterface<R> { 171 /** 172 * Sort the lines read from the standard input and writes the result to 173 the standard output. 174 <p> 175 Comparisons are based on the entire line without line ending. The 176 collating sequence of the current locale is used to perform the 177 comparisons. 178 <p> 179 The sort algorithm used is guaranteed to be stable: lines considered 180 equal will not be reordered as a result of the sort. 181 * 182 * @return the generic type {@code <R>} defined by the implementing class; 183 * the command itself returns no value and writes its result to the 184 * standard output; see class level parameter comments for more 185 * details 186 */ 187 R sort(); 188 /** 189 * Sort the lines of all the specified files together and writes the 190 result to the standard output. 191 <p> 192 Options can be specified by acronym (with a leading dash "-") or by 193 long name (with two leading dashes "--"). Operands other than the 194 default "--paths" operand have to be prefixed with the operand 195 name. 196 <p> 197 The sort algorithm used is guaranteed to be stable: lines considered 198 equal will not be reordered as a result of the sort. If two lines 199 originate from different input files, the index of the file in the 200 input arguments list defines the ordering of the lines. 201 * 202 * @param args String arguments defining the options and operands for the command. 203 Options can be specified by acronym (with a leading dash "-") or by 204 long name (with two leading dashes "--"). Operands other than the 205 default "--paths" operand have to be prefixed with the operand 206 name (e.g. "--comparator" for a subsequent comparator operand value). 207 * @return the generic type {@code <R>} defined by the implementing class; 208 * the command itself returns no value and writes its result to the 209 * standard output; see class level parameter comments for more 210 * details 211 */ 212 R sort(String... args); 213 /** 214 * Sort the lines of all the specified files together and writes the 215 result to the standard output. 216<p> 217 Comparisons are based on the entire line without line ending. The 218 collating sequence of the current locale is used to perform the 219 comparisons. 220<p> 221 The sort algorithm used is guaranteed to be stable: lines considered 222 equal will not be reordered as a result of the sort. If two lines 223 originate from different input files, the index of the file in the 224 input arguments list defines the ordering of the lines. 225 * 226 * @param files The files to be sorted or merged; relative paths are not resolved 227 (use the string paths argument to enable relative path resolving 228 based on the current working directory). 229 * @return the generic type {@code <R>} defined by the implementing class; 230 * the command itself returns no value and writes its result to the 231 * standard output; see class level parameter comments for more 232 * details 233 */ 234 R sort(java.io.File... files); 235 /** 236 * Sort the lines of all the specified inputs together and writes the 237 result to the standard output. 238<p> 239 Comparisons are based on the entire line without line ending. The 240 collating sequence of the current locale is used to perform the 241 comparisons. 242<p> 243 The sort algorithm used is guaranteed to be stable: lines considered 244 equal will not be reordered as a result of the sort. If two lines 245 originate from different inputs, the index of the input in the 246 arguments list defines the ordering of the lines. 247 * 248 * @param inputs The inputs to be sorted or merged. 249 * @return the generic type {@code <R>} defined by the implementing class; 250 * the command itself returns no value and writes its result to the 251 * standard output; see class level parameter comments for more 252 * details 253 */ 254 R sort(org.unix4j.io.Input... inputs); 255 /** 256 * Sort the lines read from the standard input and writes the result to 257 the standard output. 258 <p> 259 Line comparisons are based on the specified {@code comparator}. 260 <p> 261 The sort algorithm used is guaranteed to be stable: lines considered 262 equal will not be reordered as a result of the sort. 263 * 264 * @param comparator The comparator to use for the line comparisons. 265 * @return the generic type {@code <R>} defined by the implementing class; 266 * the command itself returns no value and writes its result to the 267 * standard output; see class level parameter comments for more 268 * details 269 */ 270 R sort(java.util.Comparator<? super org.unix4j.line.Line> comparator); 271 /** 272 * Sort the lines of all the specified files together and writes the 273 result to the standard output. 274 <p> 275 Line comparisons are based on the specified {@code comparator}. 276 <p> 277 The sort algorithm used is guaranteed to be stable: lines considered 278 equal will not be reordered as a result of the sort. If two lines 279 originate from different input files, the index of the file in the 280 input arguments list defines the ordering of the lines. 281 * 282 * @param comparator The comparator to use for the line comparisons. 283 * @param files The files to be sorted or merged; relative paths are not resolved 284 (use the string paths argument to enable relative path resolving 285 based on the current working directory). 286 * @return the generic type {@code <R>} defined by the implementing class; 287 * the command itself returns no value and writes its result to the 288 * standard output; see class level parameter comments for more 289 * details 290 */ 291 R sort(java.util.Comparator<? super org.unix4j.line.Line> comparator, java.io.File... files); 292 /** 293 * Sort the lines of all the specified files together and writes the 294 result to the standard output. 295 <p> 296 Line comparisons are based on the specified {@code comparator}. 297 <p> 298 The sort algorithm used is guaranteed to be stable: lines considered 299 equal will not be reordered as a result of the sort. If two lines 300 originate from different input files, the index of the file in the 301 input arguments list defines the ordering of the lines. 302 * 303 * @param comparator The comparator to use for the line comparisons. 304 * @param paths Path names of the files to be sorted, merged, or checked; wildcards * 305 and ? are supported; relative paths are resolved on the 306 basis of the current working directory. 307 * @return the generic type {@code <R>} defined by the implementing class; 308 * the command itself returns no value and writes its result to the 309 * standard output; see class level parameter comments for more 310 * details 311 */ 312 R sort(java.util.Comparator<? super org.unix4j.line.Line> comparator, String... paths); 313 /** 314 * Sort the lines of all the specified inputs together and writes the 315 result to the standard output. 316<p> 317 Line comparisons are based on the specified {@code comparator}. 318<p> 319 The sort algorithm used is guaranteed to be stable: lines considered 320 equal will not be reordered as a result of the sort. If two lines 321 originate from different inputs, the index of the input in the 322 arguments list defines the ordering of the lines. 323 * 324 * @param comparator The comparator to use for the line comparisons. 325 * @param inputs The inputs to be sorted or merged. 326 * @return the generic type {@code <R>} defined by the implementing class; 327 * the command itself returns no value and writes its result to the 328 * standard output; see class level parameter comments for more 329 * details 330 */ 331 R sort(java.util.Comparator<? super org.unix4j.line.Line> comparator, org.unix4j.io.Input... inputs); 332 /** 333 * Sorts, merges, or sequence checks the lines read from the standard 334 input and writes the result to the standard output. 335 <p> 336 Comparisons are based on the entire line without line ending. The 337 collating sequence of the current locale is used to perform the 338 comparisons. 339 <p> 340 The sort algorithm used is guaranteed to be stable: lines considered 341 equal will not be reordered as a result of the sort. 342 * 343 * @param options The options for the sort command. 344 * @return the generic type {@code <R>} defined by the implementing class; 345 * the command itself returns no value and writes its result to the 346 * standard output; see class level parameter comments for more 347 * details 348 */ 349 R sort(SortOptions options); 350 /** 351 * Sorts, merges, or sequence checks the lines the lines of all the 352 specified files together and writes the result to the standard 353 output. 354 <p> 355 Comparisons are based on the entire line without line ending. The 356 collating sequence of the current locale is used to perform the 357 comparisons. 358 <p> 359 The sort algorithm used is guaranteed to be stable: lines considered 360 equal will not be reordered as a result of the sort. If two lines 361 originate from different input files, the index of the file in the 362 input arguments list defines the ordering of the lines. 363 * 364 * @param options The options for the sort command. 365 * @param files The files to be sorted or merged; relative paths are not resolved 366 (use the string paths argument to enable relative path resolving 367 based on the current working directory). 368 * @return the generic type {@code <R>} defined by the implementing class; 369 * the command itself returns no value and writes its result to the 370 * standard output; see class level parameter comments for more 371 * details 372 */ 373 R sort(SortOptions options, java.io.File... files); 374 /** 375 * Sorts, merges, or sequence checks the lines the lines of all the 376 specified files together and writes the result to the standard 377 output. 378 <p> 379 Comparisons are based on the entire line without line ending. The 380 collating sequence of the current locale is used to perform the 381 comparisons. 382 <p> 383 The sort algorithm used is guaranteed to be stable: lines considered 384 equal will not be reordered as a result of the sort. If two lines 385 originate from different input files, the index of the file in the 386 input arguments list defines the ordering of the lines. 387 * 388 * @param options The options for the sort command. 389 * @param paths Path names of the files to be sorted, merged, or checked; wildcards * 390 and ? are supported; relative paths are resolved on the 391 basis of the current working directory. 392 * @return the generic type {@code <R>} defined by the implementing class; 393 * the command itself returns no value and writes its result to the 394 * standard output; see class level parameter comments for more 395 * details 396 */ 397 R sort(SortOptions options, String... paths); 398 /** 399 * Sorts, merges, or sequence checks the lines the lines of all the 400 specified inputs together and writes the result to the standard 401 output. 402<p> 403 Comparisons are based on the entire line without line ending. The 404 collating sequence of the current locale is used to perform the 405 comparisons. 406<p> 407 The sort algorithm used is guaranteed to be stable: lines considered 408 equal will not be reordered as a result of the sort. If two lines 409 originate from different inputs, the index of the input in the 410 arguments list defines the ordering of the lines. 411 * 412 * @param options The options for the sort command. 413 * @param inputs The inputs to be sorted or merged. 414 * @return the generic type {@code <R>} defined by the implementing class; 415 * the command itself returns no value and writes its result to the 416 * standard output; see class level parameter comments for more 417 * details 418 */ 419 R sort(SortOptions options, org.unix4j.io.Input... inputs); 420 /** 421 * Sorts, merges, or sequence checks the lines read from the standard 422 input and writes the result to the standard output. 423 <p> 424 Line comparisons are based on the specified {@code comparator}. 425 All comparison related options are ignored except for 426 {@code --reverse}. 427 <p> 428 The sort algorithm used is guaranteed to be stable: lines considered 429 equal will not be reordered as a result of the sort. 430 * 431 * @param options The options for the sort command. 432 * @param comparator The comparator to use for the line comparisons. 433 * @return the generic type {@code <R>} defined by the implementing class; 434 * the command itself returns no value and writes its result to the 435 * standard output; see class level parameter comments for more 436 * details 437 */ 438 R sort(SortOptions options, java.util.Comparator<? super org.unix4j.line.Line> comparator); 439 /** 440 * Sorts, merges, or sequence checks the lines the lines of all the 441 specified files together and writes the result to the standard 442 output. 443 <p> 444 Line comparisons are based on the specified {@code comparator}. 445 All comparison related options except for {@code --reverse} are 446 ignored. 447 <p> 448 The sort algorithm used is guaranteed to be stable: lines considered 449 equal will not be reordered as a result of the sort. If two lines 450 originate from different input files, the index of the file in the 451 input arguments list defines the ordering of the lines. 452 * 453 * @param options The options for the sort command. 454 * @param comparator The comparator to use for the line comparisons. 455 * @param files The files to be sorted or merged; relative paths are not resolved 456 (use the string paths argument to enable relative path resolving 457 based on the current working directory). 458 * @return the generic type {@code <R>} defined by the implementing class; 459 * the command itself returns no value and writes its result to the 460 * standard output; see class level parameter comments for more 461 * details 462 */ 463 R sort(SortOptions options, java.util.Comparator<? super org.unix4j.line.Line> comparator, java.io.File... files); 464 /** 465 * Sorts, merges, or sequence checks the lines the lines of all the 466 specified files together and writes the result to the standard 467 output. 468 <p> 469 Line comparisons are based on the specified {@code comparator}. 470 All comparison related options except for {@code --reverse} are 471 ignored. 472 <p> 473 The sort algorithm used is guaranteed to be stable: lines considered 474 equal will not be reordered as a result of the sort. If two lines 475 originate from different input files, the index of the file in the 476 input arguments list defines the ordering of the lines. 477 * 478 * @param options The options for the sort command. 479 * @param comparator The comparator to use for the line comparisons. 480 * @param paths Path names of the files to be sorted, merged, or checked; wildcards * 481 and ? are supported; relative paths are resolved on the 482 basis of the current working directory. 483 * @return the generic type {@code <R>} defined by the implementing class; 484 * the command itself returns no value and writes its result to the 485 * standard output; see class level parameter comments for more 486 * details 487 */ 488 R sort(SortOptions options, java.util.Comparator<? super org.unix4j.line.Line> comparator, String... paths); 489 /** 490 * Sorts, merges, or sequence checks the lines the lines of all the 491 specified inputs together and writes the result to the standard 492 output. 493<p> 494 Line comparisons are based on the specified {@code comparator}. 495 All comparison related options except for {@code --reverse} are 496 ignored. 497<p> 498 The sort algorithm used is guaranteed to be stable: lines considered 499 equal will not be reordered as a result of the sort. If two lines 500 originate from different inputs, the index of the input in the 501 arguments list defines the ordering of the lines. 502 * 503 * @param options The options for the sort command. 504 * @param comparator The comparator to use for the line comparisons. 505 * @param inputs The inputs to be sorted or merged. 506 * @return the generic type {@code <R>} defined by the implementing class; 507 * the command itself returns no value and writes its result to the 508 * standard output; see class level parameter comments for more 509 * details 510 */ 511 R sort(SortOptions options, java.util.Comparator<? super org.unix4j.line.Line> comparator, org.unix4j.io.Input... inputs); 512 } 513 514 /** 515 * Options for the "sort" command: {@link SortOption#check c}, {@link SortOption#merge m}, {@link SortOption#unique u}, {@link SortOption#ignoreLeadingBlanks b}, {@link SortOption#dictionaryOrder d}, {@link SortOption#ignoreCase f}, {@link SortOption#numericSort n}, {@link SortOption#generalNumericSort g}, {@link SortOption#humanNumericSort h}, {@link SortOption#monthSort M}, {@link SortOption#versionSort V}, {@link SortOption#reverse r}. 516 * <p> 517 * <table> 518 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -c}</td><td> </td><td nowrap="nowrap">{@code --check}</td><td> </td><td>Checks that the single input file is ordered as specified by the 519 arguments and the collating sequence of the current locale. No 520 output is produced; only the exit code is affected.</td></tr> 521 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -m}</td><td> </td><td nowrap="nowrap">{@code --merge}</td><td> </td><td>Merge only; the input file are assumed to be already sorted.</td></tr> 522 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -u}</td><td> </td><td nowrap="nowrap">{@code --unique}</td><td> </td><td>Unique: suppress all but one in each set of lines having equal keys. 523 If used with the {@code -c} option, checks that there are no lines 524 with duplicate keys, in addition to checking that the input file is 525 sorted.</td></tr> 526 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -b}</td><td> </td><td nowrap="nowrap">{@code --ignoreLeadingBlanks}</td><td> </td><td>Ignore leading blanks. 527 (This option is ignored if a comparator operand is present).</td></tr> 528 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -d}</td><td> </td><td nowrap="nowrap">{@code --dictionaryOrder}</td><td> </td><td>Consider only blanks and alphanumeric characters. 529 (This option is ignored if a comparator operand is present).</td></tr> 530 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -f}</td><td> </td><td nowrap="nowrap">{@code --ignoreCase}</td><td> </td><td>Consider all lowercase characters that have uppercase equivalents to 531 be the uppercase equivalent for the purposes of comparison. 532 (This option is ignored if a comparator operand is present).</td></tr> 533 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -n}</td><td> </td><td nowrap="nowrap">{@code --numericSort}</td><td> </td><td>Sort numerically; the number begins each line and consists of 534 optional blanks, an optional minus sign, and zero or more digits 535 possibly separated by thousands separators, optionally followed by a 536 decimal-point character and zero or more digits. An empty number is 537 treated as '0'. The current local specifies the decimal-point 538 character and thousands separator. 539 <p> 540 Comparison is exact; there is no rounding error. 541 <p> 542 Neither a leading '+' nor exponential notation is recognized. To 543 compare such strings numerically, use the 544 {@code -genericNumericSort (-g)} option. 545<p> 546 (This option is ignored if a comparator operand is present).</td></tr> 547 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -g}</td><td> </td><td nowrap="nowrap">{@code --generalNumericSort}</td><td> </td><td>Sort numerically, using the standard {@link Double#parseDouble(String)} 548 function to convert a trimmed line to a double-precision floating 549 point number. This allows floating point numbers to be specified in 550 scientific notation, like 1.0e-34 and 10e100. 551 <p> 552 Uses the following collating sequence: Lines that cannot be parsed 553 because they do not represent valid double values (in alpha-numeric 554 order); "-Infinity"; finite numbers in ascending numeric order 555 (with -0 < +0); "Infinity"; "NaN". 556<p> 557 This option is usually slower than {@code -numeric-sort (-n)} and it 558 can lose information when converting to floating point. 559 <p> 560 (This option is ignored if a comparator operand is present).</td></tr> 561 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -h}</td><td> </td><td nowrap="nowrap">{@code --humanNumericSort}</td><td> </td><td>Sort numerically, first by numeric sign (negative, zero, or 562 positive); then by SI suffix (either empty, or 'k' or 'K', or one 563 of 'MGTPEZY', in that order); and finally by numeric value. For 564 example, '1023M' sorts before '1G' because 'M' (mega) precedes 'G' 565 (giga) as an SI suffix. 566 <p> 567 This option sorts values that are consistently scaled to the nearest 568 suffix, regardless of whether suffixes denote powers of 1000 or 569 1024, and it therefore sorts the output of any single invocation of 570 the {@code ls} command that are invoked with the --human-readable 571 option. 572 <p> 573 The syntax for numbers is the same as for the 574 {@code --numericSort (-n)} option; the SI suffix must immediately 575 follow the number. 576<p> 577 (This option is ignored if a comparator operand is present).</td></tr> 578 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -M}</td><td> </td><td nowrap="nowrap">{@code --monthSort}</td><td> </td><td>An initial string, consisting of any amount of blanks, followed by a 579 month name abbreviation, is folded to UPPER case and compared in the 580 order: (unknown) < 'JAN' < ... < 'DEC'. The current locale 581 determines the month spellings.</td></tr> 582 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -V}</td><td> </td><td nowrap="nowrap">{@code --versionSort}</td><td> </td><td>Sort by version name and number. It behaves like a standard sort, 583 except that each sequence of decimal digits is treated numerically 584 as an index/version number. 585 <p> 586 (This option is ignored if a comparator operand is present).</td></tr> 587 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -r}</td><td> </td><td nowrap="nowrap">{@code --reverse}</td><td> </td><td>Reverse the sense of comparisons.</td></tr> 588 * </table> 589 */ 590 public static final SortOptionSets Options = SortOptionSets.INSTANCE; 591 592 /** 593 * Singleton {@link SortFactory factory} instance for the "sort" command. 594 */ 595 public static final SortFactory Factory = SortFactory.INSTANCE; 596 597 // no instances 598 private Sort() { 599 super(); 600 } 601}