private void parse(String value, Function<String, Path> pathCreator, List<Path> result) { if (!Strings.isNullOrEmpty(value)) { Arrays.stream(value.split(",")).forEach(name -> result.add(pathCreator.apply(name))); } }
/** * Check if the string contains only digits. * * @param str the string to check * @return {@code true} if only contains digits */ public static boolean isNumeric(String str) { if (isNullOrEmpty(str)) { return false; } final int sz = str.length(); for (int i = 0; i < sz; i++) { if (!Character.isDigit(str.charAt(i))) { return false; } } return true; }
/** * If KEY_FIELD_REGEX has a value that is really a regex, then the KEY_FIELD_REPLACEMENT must be a non-empty value. */ private static int validateKeyFieldReplacement(Configuration config, Field field, Field.ValidationOutput problems) { String keyFieldRegex = config.getString(KEY_FIELD_REGEX); if (keyFieldRegex != null) { keyFieldRegex = keyFieldRegex.trim(); } String keyFieldReplacement = config.getString(KEY_FIELD_REPLACEMENT); if (keyFieldReplacement != null) { keyFieldReplacement = keyFieldReplacement.trim(); } if (!Strings.isNullOrEmpty(keyFieldRegex) && Strings.isNullOrEmpty(keyFieldReplacement)) { problems.accept( KEY_FIELD_REPLACEMENT, null, String.format("%s must be non-empty if %s is set.", KEY_FIELD_REPLACEMENT.name(), KEY_FIELD_REGEX.name() ) ); return 1; } return 0; }
protected void readBinlogPosition(int step, SourceInfo source, JdbcConnection mysql, AtomicReference<String> sql) throws SQLException { if (context.isSchemaOnlyRecoverySnapshot()) { if (Strings.isNullOrEmpty(source.binlogFilename())) {
/** * Returns the type schema name for the given table. */ private String tableSchemaName(TableId tableId) { if (Strings.isNullOrEmpty(tableId.catalog())) { if (Strings.isNullOrEmpty(tableId.schema())) { return tableId.table(); } else { return tableId.schema() + "." + tableId.table(); } } else if (Strings.isNullOrEmpty(tableId.schema())) { return tableId.catalog() + "." + tableId.table(); } // When both catalog and schema is present then only schema is used else { return tableId.schema() + "." + tableId.table(); } }
@Test public void isNullOrEmptyReturnsFalseForFalseForNonEmptyString() { assertThat(Strings.isNullOrEmpty("hello")).isFalse(); }
@Test public void isNullOrEmptyReturnsTrueForNull() { assertThat(Strings.isNullOrEmpty(null)).isTrue(); }
@Test public void isNullOrEmptyReturnsTrueForEmptyString() { assertThat(Strings.isNullOrEmpty("")).isTrue(); }
@Test public void isNullOrEmptyReturnsFalseForFalseForBlankString() { assertThat(Strings.isNullOrEmpty(" ")).isFalse(); }
/** * Check if the string contains only digits. * * @param str the string to check * @return {@code true} if only contains digits */ public static boolean isNumeric(String str) { if (isNullOrEmpty(str)) { return false; } final int sz = str.length(); for (int i = 0; i < sz; i++) { if (!Character.isDigit(str.charAt(i))) { return false; } } return true; }
/** * If KEY_FIELD_REGEX has a value that is really a regex, then the KEY_FIELD_REPLACEMENT must be a non-empty value. */ private static int validateKeyFieldReplacement(Configuration config, Field field, Field.ValidationOutput problems) { String keyFieldRegex = config.getString(KEY_FIELD_REGEX); if (keyFieldRegex != null) { keyFieldRegex = keyFieldRegex.trim(); } String keyFieldReplacement = config.getString(KEY_FIELD_REPLACEMENT); if (keyFieldReplacement != null) { keyFieldReplacement = keyFieldReplacement.trim(); } if (!Strings.isNullOrEmpty(keyFieldRegex) && Strings.isNullOrEmpty(keyFieldReplacement)) { problems.accept( KEY_FIELD_REPLACEMENT, null, String.format("%s must be non-empty if %s is set.", KEY_FIELD_REPLACEMENT.name(), KEY_FIELD_REGEX.name() ) ); return 1; } return 0; }
/** * Returns the type schema name for the given table. */ private String tableSchemaName(TableId tableId) { if (Strings.isNullOrEmpty(tableId.catalog())) { if (Strings.isNullOrEmpty(tableId.schema())) { return tableId.table(); } else { return tableId.schema() + "." + tableId.table(); } } else if (Strings.isNullOrEmpty(tableId.schema())) { return tableId.catalog() + "." + tableId.table(); } // When both catalog and schema is present then only schema is used else { return tableId.schema() + "." + tableId.table(); } }