private String fillSentenceWithSpaces ( List < String > sentence ) { sentenceWithSpaces . clear ( ) ; //We don't need to do this process if the sentence received is a single word. if ( sentence . size ( ) > 1 ) { //We fill with normal spaces first, we can do this with confidence because "fitsInSentence" //already takes these spaces into account. for ( String word : sentence ) { sentenceWithSpaces . add ( word ) ; sentenceWithSpaces . add ( NORMAL_SPACE ) ; } //Filling sentence with thin spaces. while ( fitsInSentence ( HAIR_SPACE , sentenceWithSpaces , false ) ) { //We remove 2 from the sentence size because we need to make sure we are not adding //spaces to the end of the line. sentenceWithSpaces . add ( getRandomNumber ( sentenceWithSpaces . size ( ) - 2 ) , HAIR_SPACE ) ; } } return getSentenceFromList ( sentenceWithSpaces , false ) ; }
Fills sentence with appropriate amount of spaces .