/** * @param input string of property key * @return whether the input is a valid property name */ public static boolean isValid(String input) { // Check if input matches any default keys or aliases if (DEFAULT_KEYS_MAP.containsKey(input) || DEFAULT_ALIAS_MAP.containsKey(input)) { return true; } // Check if input matches any parameterized keys for (Template template : Template.values()) { if (template.matches(input)) { return true; } } return false; }
/** * Parses a string and return its corresponding {@link PropertyKey}, throwing exception if no such * a property can be found. * * @param input string of property key * @return corresponding property */ public static PropertyKey fromString(String input) { // First try to parse it as default key PropertyKey key = DEFAULT_KEYS_MAP.get(input); if (key != null) { return key; } // Try to match input with alias key = DEFAULT_ALIAS_MAP.get(input); if (key != null) { return key; } // Try different templates and see if any template matches for (Template template : Template.values()) { key = template.getPropertyKey(input); if (key != null) { return key; } } throw new IllegalArgumentException( ExceptionMessage.INVALID_CONFIGURATION_KEY.getMessage(input)); }