I wrote the following groovy function for taking a string of multiple lines (or any other character for splitting the code into parts), and bringing each line/part to a specified number of characters, cutting too long lines and filling up too short lines with a fill character:
static final String adjustLineLength(Integer length, String filler, String token, String source) {
source
.tokenize(token)
.collect{ String line ->
if(line.size() > length)
line.substring(0, length)
else if(line.size() < length)
line + (filler * (length - line.size()))
else
line
}
.join(token)
}
Is that a good approach? Any suggestions how this code can be improved in concerns of making it more easy to understand and maybe (but that has not priority over beeing easy to understand) improving performance?