1 package be
.nikiroo
.utils
.main
;
3 import java
.util
.ArrayList
;
5 import java
.util
.Scanner
;
7 import be
.nikiroo
.utils
.StringUtils
;
8 import be
.nikiroo
.utils
.StringUtils
.Alignment
;
11 * Text justification (left, right, center, justify).
15 public class justify
{
17 * Syntax: $0 ([left|right|center|justify]) (max width)
20 * <li>mode: left, right, center or full justification (defaults to left)</li>
21 * <li>max width: the maximum width of a line, or "" for "no maximum"
22 * (defaults to "no maximum")</li>
27 public static void main(String
[] args
) {
29 StringUtils
.Alignment align
= Alignment
.LEFT
;
31 if (args
.length
>= 1) {
32 align
= Alignment
.valueOf(args
[0].toUpperCase());
34 if (args
.length
>= 2) {
35 width
= Integer
.parseInt(args
[1]);
38 Scanner scan
= new Scanner(System
.in
);
39 scan
.useDelimiter("\r\n|[\r\n]");
41 List
<String
> lines
= new ArrayList
<String
>();
42 while (scan
.hasNext()) {
43 lines
.add(scan
.next());
46 for (String line
: StringUtils
.justifyText(lines
, width
, align
)) {
47 System
.out
.println(line
);