Skip to content

Commit ed6f672

Browse files
committed
Use ternary expression
Javadoc
1 parent 6349e71 commit ed6f672

2 files changed

Lines changed: 9 additions & 19 deletions

File tree

src/main/java/org/apache/commons/cli/Converter.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
2626
import java.util.Date;
2727

2828
/**
29-
* The definition of the functional interface to call when doing a conversion.
30-
* Like {@code Function<String,T>} but can throw an Exception.
29+
* The definition of the functional interface to call when doing a conversion. Like {@code Function<String,T>} but can throw an Exception.
3130
*
3231
* @param <T> The return type for the function.
3332
* @param <E> The kind of thrown exception or error.
@@ -58,19 +57,13 @@ public interface Converter<T, E extends Throwable> {
5857
Converter<Path, InvalidPathException> PATH = Paths::get;
5958

6059
/**
61-
* Number converter. Converts to a Double if a decimal point ('.') is in the
62-
* string or a Long otherwise.
60+
* Number converter. Converts to a Double if a decimal point ('.') is in the string or a Long otherwise.
6361
*/
64-
Converter<Number, NumberFormatException> NUMBER = s -> {
65-
if (s.indexOf('.') != -1) {
66-
return Double.valueOf(s);
67-
}
68-
return Long.valueOf(s);
69-
};
62+
Converter<Number, NumberFormatException> NUMBER = s -> s.indexOf('.') != -1 ? (Number) Double.valueOf(s) : (Number) Long.valueOf(s);
7063

7164
/**
72-
* Converts a class name to an instance of the class. Uses the Class converter
73-
* to find the class and then call the default constructor.
65+
* Converts a class name to an instance of the class. Uses the Class converter to find the class and then call the default constructor.
66+
*
7467
* @see #CLASS
7568
*/
7669
Converter<Object, ReflectiveOperationException> OBJECT = s -> CLASS.apply(s).getConstructor().newInstance();
@@ -87,8 +80,9 @@ public interface Converter<T, E extends Throwable> {
8780

8881
/**
8982
* Applies the conversion function to the String argument.
90-
* @param str the String to convert
91-
* @return the Object from the conversion.
83+
*
84+
* @param str the String to convert
85+
* @return the Object from the conversion.
9286
* @throws E on error.
9387
*/
9488
T apply(String str) throws E;

src/main/java/org/apache/commons/cli/TypeHandler.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,7 @@ public static void resetConverters() {
251251
converterMap.put(Integer.class, Integer::parseInt);
252252
converterMap.put(Short.class, Short::parseShort);
253253
converterMap.put(Byte.class, Byte::parseByte);
254-
converterMap.put(Character.class, s -> {
255-
if (s.startsWith("\\u")) {
256-
return Character.toChars(Integer.parseInt(s.substring(2), HEX_RADIX))[0];
257-
}
258-
return s.charAt(0); });
254+
converterMap.put(Character.class, s -> s.startsWith("\\u") ? Character.toChars(Integer.parseInt(s.substring(2), HEX_RADIX))[0] : s.charAt(0));
259255
converterMap.put(Double.class, Double::parseDouble);
260256
converterMap.put(Float.class, Float::parseFloat);
261257
converterMap.put(BigInteger.class, BigInteger::new);

0 commit comments

Comments
 (0)