package pl.wroc.pwr.string; import pl.wroc.pwr.IOperator; import pl.wroc.pwr.system.Consts; public class StringLengthEqualizer implements IOperator< String > { private String text; private int requiredLength; public StringLengthEqualizer( String text, int requiredLength ) { this.text = text; this.requiredLength = requiredLength; } public String apply() { int textLength = this.text.length( ); String output = this.text; if ( textLength > this.requiredLength ) { output = output.substring( 0, this.requiredLength ); } int delta = this.requiredLength - textLength; while ( delta > 0 ) { output = Consts.BLANK + output; delta--; } return output; } }