/** * Truncate to a maximum length the string values for each of the columns with the fully-qualified names. * Only columns {@link String} values can be truncated. * * @param fullyQualifiedColumnNames the comma-separated list of fully-qualified column names; may not be null * @param maxLength the maximum number of characters to appear in the value * @return this object so that methods can be chained together; never null */ public Builder truncateStrings(String fullyQualifiedColumnNames, int maxLength) { return map(fullyQualifiedColumnNames, new TruncateStrings(maxLength)); }
@Test public void shouldTruncateStrings() { converter = new TruncateStrings(5).create(column); assertThat(converter.convert("1234567890").toString()).isEqualTo("12345"); assertThat(converter.convert("123456").toString()).isEqualTo("12345"); assertThat(converter.convert("12345").toString()).isEqualTo("12345"); assertThat(converter.convert("1234").toString()).isEqualTo("1234"); assertThat(converter.convert("123").toString()).isEqualTo("123"); assertThat(converter.convert("12").toString()).isEqualTo("12"); assertThat(converter.convert("1").toString()).isEqualTo("1"); assertThat(converter.convert(null)).isNull(); }
/** * Truncate to a maximum length the string values for each of the columns with the fully-qualified names. * Only columns {@link String} values can be truncated. * * @param fullyQualifiedColumnNames the comma-separated list of fully-qualified column names; may not be null * @param maxLength the maximum number of characters to appear in the value * @return this object so that methods can be chained together; never null */ public Builder truncateStrings(String fullyQualifiedColumnNames, int maxLength) { return map(fullyQualifiedColumnNames, new TruncateStrings(maxLength)); }