/** * Converts the string passed as argument to a level. If the conversion fails, then this method returns the value of * <code>defaultLevel</code>. * * @param name The name of the desired Level. * @param defaultLevel The Level to use if the String is invalid. * @return The Level associated with the String. */ public static Level toLevel(final String name, final Level defaultLevel) { if (name == null) { return defaultLevel; } final Level level = LEVELS.get(toUpperCase(name)); return level == null ? defaultLevel : level; }
/** * Return the Level associated with the name. * * @param name The name of the Level to return. * @return The Level. * @throws java.lang.NullPointerException if the Level name is {@code null}. * @throws java.lang.IllegalArgumentException if the Level name is not registered. */ public static Level valueOf(final String name) { Objects.requireNonNull(name, "No level name given."); final String levelName = toUpperCase(name); final Level level = LEVELS.get(levelName); if (level != null) { return level; } throw new IllegalArgumentException("Unknown level constant [" + levelName + "]."); }
/** * Converts the string passed as argument to a level. If the conversion fails, then this method returns the value of * <code>defaultLevel</code>. * * @param name The name of the desired Level. * @param defaultLevel The Level to use if the String is invalid. * @return The Level associated with the String. */ public static Level toLevel(final String name, final Level defaultLevel) { if (name == null) { return defaultLevel; } final Level level = LEVELS.get(toUpperCase(name)); return level == null ? defaultLevel : level; }
/** * Return the Level associated with the name. * * @param name The name of the Level to return. * @return The Level. * @throws java.lang.NullPointerException if the Level name is {@code null}. * @throws java.lang.IllegalArgumentException if the Level name is not registered. */ public static Level valueOf(final String name) { Objects.requireNonNull(name, "No level name given."); final String levelName = toUpperCase(name); final Level level = LEVELS.get(levelName); if (level != null) { return level; } throw new IllegalArgumentException("Unknown level constant [" + levelName + "]."); }