/** * Determine if the supplied character is a valid non-first character for Avro fullnames. * * @param c the character * @return {@code true} if the character is a valid non-first character of an Avro fullname, or {@code false} otherwise * @see #isValidFullname(String) */ public static boolean isValidFullnameNonFirstCharacter(char c) { return c == '.' || isValidFullnameFirstCharacter(c) || (c >= '0' && c <= '9'); }
/** * Determine if the supplied string is a valid Avro namespace. * * @param fullname the name to be used as an Avro fullname; may not be null * @return {@code true} if the fullname satisfies Avro rules, or {@code false} otherwise */ public static boolean isValidFullname(String fullname) { if (fullname.length() == 0) return true; char c = fullname.charAt(0); if (!isValidFullnameFirstCharacter(c)) return false; for (int i = 1; i != fullname.length(); ++i) { c = fullname.charAt(i); if (!isValidFullnameNonFirstCharacter(c)) return false; } return true; }
char c = proposedName.charAt(0); boolean changed = false; if (isValidFullnameFirstCharacter(c)) { sb.append(c); } else {
@Test public void shouldDetermineValidFirstCharacters() { String validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"; for (int i = 0; i != validChars.length(); ++i) { assertThat(SchemaNameAdjuster.isValidFullnameFirstCharacter(validChars.charAt(i))).isTrue(); } }
/** * Determine if the supplied character is a valid non-first character for Avro fullnames. * * @param c the character * @return {@code true} if the character is a valid non-first character of an Avro fullname, or {@code false} otherwise * @see #isValidFullname(String) */ public static boolean isValidFullnameNonFirstCharacter(char c) { return c == '.' || isValidFullnameFirstCharacter(c) || (c >= '0' && c <= '9'); }
/** * Determine if the supplied string is a valid Avro namespace. * * @param fullname the name to be used as an Avro fullname; may not be null * @return {@code true} if the fullname satisfies Avro rules, or {@code false} otherwise */ public static boolean isValidFullname(String fullname) { if (fullname.length() == 0) return true; char c = fullname.charAt(0); if (!isValidFullnameFirstCharacter(c)) return false; for (int i = 1; i != fullname.length(); ++i) { c = fullname.charAt(i); if (!isValidFullnameNonFirstCharacter(c)) return false; } return true; }
char c = proposedName.charAt(0); boolean changed = false; if (isValidFullnameFirstCharacter(c)) { sb.append(c); } else {