This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-cli.git
The following commit(s) were added to refs/heads/master by this push: new ed6f672 Use ternary expression ed6f672 is described below commit ed6f672067bd12bb219d87e23afd382bc201cc02 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Mon Jan 29 09:49:17 2024 -0500 Use ternary expression Javadoc --- .../java/org/apache/commons/cli/Converter.java | 22 ++++++++-------------- .../java/org/apache/commons/cli/TypeHandler.java | 6 +----- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/apache/commons/cli/Converter.java b/src/main/java/org/apache/commons/cli/Converter.java index b6d80a5..7188575 100644 --- a/src/main/java/org/apache/commons/cli/Converter.java +++ b/src/main/java/org/apache/commons/cli/Converter.java @@ -26,8 +26,7 @@ import java.text.SimpleDateFormat; import java.util.Date; /** - * The definition of the functional interface to call when doing a conversion. - * Like {@code Function<String,T>} but can throw an Exception. + * The definition of the functional interface to call when doing a conversion. Like {@code Function<String,T>} but can throw an Exception. * * @param <T> The return type for the function. * @param <E> The kind of thrown exception or error. @@ -58,19 +57,13 @@ public interface Converter<T, E extends Throwable> { Converter<Path, InvalidPathException> PATH = Paths::get; /** - * Number converter. Converts to a Double if a decimal point ('.') is in the - * string or a Long otherwise. + * Number converter. Converts to a Double if a decimal point ('.') is in the string or a Long otherwise. */ - Converter<Number, NumberFormatException> NUMBER = s -> { - if (s.indexOf('.') != -1) { - return Double.valueOf(s); - } - return Long.valueOf(s); - }; + Converter<Number, NumberFormatException> NUMBER = s -> s.indexOf('.') != -1 ? (Number) Double.valueOf(s) : (Number) Long.valueOf(s); /** - * Converts a class name to an instance of the class. Uses the Class converter - * to find the class and then call the default constructor. + * Converts a class name to an instance of the class. Uses the Class converter to find the class and then call the default constructor. + * * @see #CLASS */ Converter<Object, ReflectiveOperationException> OBJECT = s -> CLASS.apply(s).getConstructor().newInstance(); @@ -87,8 +80,9 @@ public interface Converter<T, E extends Throwable> { /** * Applies the conversion function to the String argument. - * @param str the String to convert - * @return the Object from the conversion. + * + * @param str the String to convert + * @return the Object from the conversion. * @throws E on error. */ T apply(String str) throws E; diff --git a/src/main/java/org/apache/commons/cli/TypeHandler.java b/src/main/java/org/apache/commons/cli/TypeHandler.java index 4184daf..ab85ab9 100644 --- a/src/main/java/org/apache/commons/cli/TypeHandler.java +++ b/src/main/java/org/apache/commons/cli/TypeHandler.java @@ -251,11 +251,7 @@ public class TypeHandler { converterMap.put(Integer.class, Integer::parseInt); converterMap.put(Short.class, Short::parseShort); converterMap.put(Byte.class, Byte::parseByte); - converterMap.put(Character.class, s -> { - if (s.startsWith("\\u")) { - return Character.toChars(Integer.parseInt(s.substring(2), HEX_RADIX))[0]; - } - return s.charAt(0); }); + converterMap.put(Character.class, s -> s.startsWith("\\u") ? Character.toChars(Integer.parseInt(s.substring(2), HEX_RADIX))[0] : s.charAt(0)); converterMap.put(Double.class, Double::parseDouble); converterMap.put(Float.class, Float::parseFloat); converterMap.put(BigInteger.class, BigInteger::new);