@Nullable private List<String> toArrayWrapping(@Nullable String s,int width){
  List<String> list=new ArrayList<String>();
  List<Pair<String,Boolean>> pairs=splitToParagraphs(s);
  if (pairs == null) {
    return null;
  }
  for (  Pair<String,Boolean> pair : pairs) {
    String seq=pair.getFirst();
    boolean isMarked=pair.getSecond();
    if (seq.isEmpty()) {
      list.add("");
      continue;
    }
    while (true) {
      if (seq.length() < width) {
        seq=isMarked ? seq : seq.trim();
        list.add(seq);
        break;
      }
 else {
        int wrapPos=Math.min(seq.length() - 1,width);
        wrapPos=seq.lastIndexOf(' ',wrapPos);
        if (wrapPos <= 2 * width / 3) {
          wrapPos=Math.min(seq.length() - 1,width);
          wrapPos=seq.indexOf(' ',wrapPos);
        }
        if (wrapPos >= seq.length() - 1 || wrapPos < 0) {
          seq=isMarked ? seq : seq.trim();
          list.add(seq);
          break;
        }
 else {
          list.add(seq.substring(0,wrapPos));
          seq=seq.substring(wrapPos + 1);
        }
      }
    }
  }
  return list;
}

@ Nullable private List < String > toArrayWrapping ( @ Nullable String s , int width ) { List < String > list = new ArrayList < String > ( ) ; List < Pair < String , Boolean > > pairs = splitToParagraphs ( s ) ; if ( pairs == null ) { return null ; } for ( Pair < String , Boolean > pair : pairs ) { String seq = pair . getFirst ( ) ; boolean isMarked = pair . getSecond ( ) ; if ( seq . isEmpty ( ) ) { list . add ( "" ) ; continue ; } while ( true ) { if ( seq . length ( ) < width ) { seq = isMarked ? seq : seq . trim ( ) ; list . add ( seq ) ; break ; } else { int wrapPos = Math . min ( seq . length ( ) - 1 , width ) ; wrapPos = seq . lastIndexOf ( ' ' , wrapPos ) ; if ( wrapPos <= 2 * width / 3 ) { wrapPos = Math . min ( seq . length ( ) - 1 , width ) ; wrapPos = seq . indexOf ( ' ' , wrapPos ) ; } if ( wrapPos >= seq . length ( ) - 1 || wrapPos < 0 ) { seq = isMarked ? seq : seq . trim ( ) ; list . add ( seq ) ; break ; } else { list . add ( seq . substring ( 0 , wrapPos ) ) ; seq = seq . substring ( wrapPos + 1 ) ; } } } } return list ; }
processes all lines ( char sequences separated by line feed symbol ) from the given string slitting them if necessary ensuring that every returned line contains less symbols than the given width .
