private String delimiter(int columnCount, int[] columnSizes) { StringBuilder sb = new StringBuilder(); for (int i = 1; i <= columnCount; i++) { if (i > 1) sb.append("---"); sb.append(Strings.createString('-', columnSizes[i])); } return sb.toString(); }
/** * Use a string of the specified number of characters to mask the string values for each of the columns with * fully-qualified names that match the given comma-separated list of regular expression patterns. * * @param fullyQualifiedColumnNames the comma-separated list of fully-qualified column names; may not be null * @param numberOfChars the number of mask characters to be used in the mask value * @param maskChar the character to be used; may not be null * @return this object so that methods can be chained together; never null */ public Builder maskStrings(String fullyQualifiedColumnNames, int numberOfChars, char maskChar) { return maskStrings(fullyQualifiedColumnNames, Strings.createString(maskChar, numberOfChars)); }
@Test public void shouldMaskStringsToFixedNumberOfSpecifiedCharacters() { char maskChar = '='; String maskValue = Strings.createString(maskChar, 10); mappers = ColumnMappers.build().maskStrings(fullyQualifiedNames, maskValue.length(), maskChar).build(); converter = mappers.mappingConverterFor(tableId, column); assertThat(converter).isNotNull(); assertThat(converter.convert("12345678901234567890")).isEqualTo(maskValue); assertThat(converter.convert("12345678901")).isEqualTo(maskValue); assertThat(converter.convert("1234567890")).isEqualTo(maskValue); assertThat(converter.convert("123456789")).isEqualTo(maskValue); assertThat(converter.convert(null)).isEqualTo(maskValue); // null values are masked, too }
private String delimiter(int columnCount, int[] columnSizes) { StringBuilder sb = new StringBuilder(); for (int i = 1; i <= columnCount; i++) { if (i > 1) sb.append("---"); sb.append(Strings.createString('-', columnSizes[i])); } return sb.toString(); }
/** * Use a string of the specified number of characters to mask the string values for each of the columns with * fully-qualified names that match the given comma-separated list of regular expression patterns. * * @param fullyQualifiedColumnNames the comma-separated list of fully-qualified column names; may not be null * @param numberOfChars the number of mask characters to be used in the mask value * @param maskChar the character to be used; may not be null * @return this object so that methods can be chained together; never null */ public Builder maskStrings(String fullyQualifiedColumnNames, int numberOfChars, char maskChar) { return maskStrings(fullyQualifiedColumnNames, Strings.createString(maskChar, numberOfChars)); }