/** * A valid key contains alphanumerics and underscores, cannot start with a * number, and cannot start or end with {@code -}. */ private static boolean isValidKey(final String s) { // Equivalent to this regex \*|[_a-zA-Z](?:[-_a-zA-Z0-9]*[_a-zA-Z0-9]) but faster if (s == null) { return false; } if (s.equals(WILDCARD_VALUE)) { return true; } int lastIndex = s.length() - 1; if (lastIndex == -1) { return false; } if (!isValidKeyStartCharacter(s.charAt(0))) { return false; } for (int i = 1; i < lastIndex; i++) { if (!isValidKeyCharacter(s.charAt(i))) { return false; } } if (lastIndex > 0 && !isValidKeyEndCharacter(s.charAt(lastIndex))) { return false; } return true; }
/** * A valid key contains alphanumerics and underscores, cannot start with a * number, and cannot start or end with {@code -}. */ private static boolean isValidKey(final String s) { // Equivalent to this regex \*|[_a-zA-Z](?:[-_a-zA-Z0-9]*[_a-zA-Z0-9]) but faster if (s == null) { return false; } if (s.equals(WILDCARD_VALUE)) { return true; } int lastIndex = s.length() - 1; if (lastIndex == -1) { return false; } if (!isValidKeyStartCharacter(s.charAt(0))) { return false; } for (int i = 1; i < lastIndex; i++) { if (!isValidKeyCharacter(s.charAt(i))) { return false; } } if (lastIndex > 0 && !isValidKeyEndCharacter(s.charAt(lastIndex))) { return false; } return true; }