src/jdk.internal.opt/share/classes/jdk/internal/joptsimple/internal/Columns.java
changeset 50428 8c88df2e8a78
parent 47216 71c04702a3d5
equal deleted inserted replaced
50427:b06f330492cd 50428:8c88df2e8a78
    29  * However, the following notice accompanied the original version of this
    29  * However, the following notice accompanied the original version of this
    30  * file:
    30  * file:
    31  *
    31  *
    32  * The MIT License
    32  * The MIT License
    33  *
    33  *
    34  * Copyright (c) 2004-2014 Paul R. Holser, Jr.
    34  * Copyright (c) 2004-2015 Paul R. Holser, Jr.
    35  *
    35  *
    36  * Permission is hereby granted, free of charge, to any person obtaining
    36  * Permission is hereby granted, free of charge, to any person obtaining
    37  * a copy of this software and associated documentation files (the
    37  * a copy of this software and associated documentation files (the
    38  * "Software"), to deal in the Software without restriction, including
    38  * "Software"), to deal in the Software without restriction, including
    39  * without limitation the rights to use, copy, modify, merge, publish,
    39  * without limitation the rights to use, copy, modify, merge, publish,
    56 package jdk.internal.joptsimple.internal;
    56 package jdk.internal.joptsimple.internal;
    57 
    57 
    58 import java.text.BreakIterator;
    58 import java.text.BreakIterator;
    59 import java.util.ArrayList;
    59 import java.util.ArrayList;
    60 import java.util.List;
    60 import java.util.List;
    61 import java.util.Locale;
       
    62 
    61 
    63 import static java.text.BreakIterator.*;
    62 import static java.text.BreakIterator.*;
    64 
    63 
    65 import static jdk.internal.joptsimple.internal.Strings.*;
    64 import static jdk.internal.joptsimple.internal.Strings.*;
    66 
    65 
    80 
    79 
    81     List<Row> fit( Row row ) {
    80     List<Row> fit( Row row ) {
    82         List<String> options = piecesOf( row.option, optionWidth );
    81         List<String> options = piecesOf( row.option, optionWidth );
    83         List<String> descriptions = piecesOf( row.description, descriptionWidth );
    82         List<String> descriptions = piecesOf( row.description, descriptionWidth );
    84 
    83 
    85         List<Row> rows = new ArrayList<Row>();
    84         List<Row> rows = new ArrayList<>();
    86         for ( int i = 0; i < Math.max( options.size(), descriptions.size() ); ++i )
    85         for ( int i = 0; i < Math.max( options.size(), descriptions.size() ); ++i )
    87             rows.add( new Row( itemOrEmpty( options, i ), itemOrEmpty( descriptions, i ) ) );
    86             rows.add( new Row( itemOrEmpty( options, i ), itemOrEmpty( descriptions, i ) ) );
    88 
    87 
    89         return rows;
    88         return rows;
    90     }
    89     }
    92     private static String itemOrEmpty( List<String> items, int index ) {
    91     private static String itemOrEmpty( List<String> items, int index ) {
    93         return index >= items.size() ? "" : items.get( index );
    92         return index >= items.size() ? "" : items.get( index );
    94     }
    93     }
    95 
    94 
    96     private List<String> piecesOf( String raw, int width ) {
    95     private List<String> piecesOf( String raw, int width ) {
    97         List<String> pieces = new ArrayList<String>();
    96         List<String> pieces = new ArrayList<>();
    98 
    97 
    99         for ( String each : raw.trim().split( LINE_SEPARATOR ) )
    98         for ( String each : raw.trim().split( LINE_SEPARATOR ) )
   100             pieces.addAll( piecesOfEmbeddedLine( each, width ) );
    99             pieces.addAll( piecesOfEmbeddedLine( each, width ) );
   101 
   100 
   102         return pieces;
   101         return pieces;
   103     }
   102     }
   104 
   103 
   105     private List<String> piecesOfEmbeddedLine( String line, int width ) {
   104     private List<String> piecesOfEmbeddedLine( String line, int width ) {
   106         List<String> pieces = new ArrayList<String>();
   105         List<String> pieces = new ArrayList<>();
   107 
   106 
   108         BreakIterator words = BreakIterator.getLineInstance( Locale.US );
   107         BreakIterator words = BreakIterator.getLineInstance();
   109         words.setText( line );
   108         words.setText( line );
   110 
   109 
   111         StringBuilder nextPiece = new StringBuilder();
   110         StringBuilder nextPiece = new StringBuilder();
   112 
   111 
   113         int start = words.first();
   112         int start = words.first();