Fix Javadoc, use ternary expressions, use Objects instead of Validate,

format fix
This commit is contained in:
Gary Gregory 2022-05-28 13:59:39 -04:00
parent 16de452a37
commit 8a6a5d9ebc
1 changed files with 13 additions and 36 deletions

View File

@ -16,6 +16,8 @@
*/ */
package org.apache.commons.lang3; package org.apache.commons.lang3;
import java.util.Objects;
/** /**
* <p>Operations on char primitives and Character objects.</p> * <p>Operations on char primitives and Character objects.</p>
* *
@ -42,7 +44,7 @@ public class CharUtils {
public static final char LF = '\n'; public static final char LF = '\n';
/** /**
* Carriage return characterf CR ('\r', Unicode 000d). * Carriage return character CR ('\r', Unicode 000d).
* *
* @see <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.10.6">JLF: Escape Sequences * @see <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.10.6">JLF: Escape Sequences
* for Character and String Literals</a> * for Character and String Literals</a>
@ -109,10 +111,7 @@ public class CharUtils {
* @return the Character value of the first letter of the String * @return the Character value of the first letter of the String
*/ */
public static Character toCharacterObject(final String str) { public static Character toCharacterObject(final String str) {
if (StringUtils.isEmpty(str)) { return StringUtils.isEmpty(str) ? null : Character.valueOf(str.charAt(0));
return null;
}
return Character.valueOf(str.charAt(0));
} }
/** /**
@ -129,8 +128,7 @@ public class CharUtils {
* @throws NullPointerException if the Character is null * @throws NullPointerException if the Character is null
*/ */
public static char toChar(final Character ch) { public static char toChar(final Character ch) {
Validate.notNull(ch, "ch"); return Objects.requireNonNull(ch, "ch").charValue();
return ch.charValue();
} }
/** /**
@ -147,10 +145,7 @@ public class CharUtils {
* @return the char value of the Character or the default if null * @return the char value of the Character or the default if null
*/ */
public static char toChar(final Character ch, final char defaultValue) { public static char toChar(final Character ch, final char defaultValue) {
if (ch == null) { return ch != null ? ch.charValue() : defaultValue;
return defaultValue;
}
return ch.charValue();
} }
/** /**
@ -190,10 +185,7 @@ public class CharUtils {
* @return the char value of the first letter of the String or the default if null * @return the char value of the first letter of the String or the default if null
*/ */
public static char toChar(final String str, final char defaultValue) { public static char toChar(final String str, final char defaultValue) {
if (StringUtils.isEmpty(str)) { return StringUtils.isEmpty(str) ? defaultValue : str.charAt(0);
return defaultValue;
}
return str.charAt(0);
} }
/** /**
@ -234,10 +226,7 @@ public class CharUtils {
* @return the int value of the character * @return the int value of the character
*/ */
public static int toIntValue(final char ch, final int defaultValue) { public static int toIntValue(final char ch, final int defaultValue) {
if (!isAsciiNumeric(ch)) { return isAsciiNumeric(ch) ? ch - 48 : defaultValue;
return defaultValue;
}
return ch - 48;
} }
/** /**
@ -258,8 +247,7 @@ public class CharUtils {
* @throws IllegalArgumentException if the Character is not ASCII numeric * @throws IllegalArgumentException if the Character is not ASCII numeric
*/ */
public static int toIntValue(final Character ch) { public static int toIntValue(final Character ch) {
Validate.notNull(ch, "ch"); return toIntValue(toChar(ch));
return toIntValue(ch.charValue());
} }
/** /**
@ -279,10 +267,7 @@ public class CharUtils {
* @return the int value of the character * @return the int value of the character
*/ */
public static int toIntValue(final Character ch, final int defaultValue) { public static int toIntValue(final Character ch, final int defaultValue) {
if (ch == null) { return ch != null ? toIntValue(ch.charValue(), defaultValue) : defaultValue;
return defaultValue;
}
return toIntValue(ch.charValue(), defaultValue);
} }
/** /**
@ -324,13 +309,9 @@ public class CharUtils {
* @return a String containing the one specified character * @return a String containing the one specified character
*/ */
public static String toString(final Character ch) { public static String toString(final Character ch) {
if (ch == null) { return ch != null ? toString(ch.charValue()) : null;
return null;
}
return toString(ch.charValue());
} }
//--------------------------------------------------------------------------
/** /**
* <p>Converts the string to the Unicode format '\u0020'.</p> * <p>Converts the string to the Unicode format '\u0020'.</p>
* *
@ -369,13 +350,9 @@ public class CharUtils {
* @return the escaped Unicode string, null if null input * @return the escaped Unicode string, null if null input
*/ */
public static String unicodeEscaped(final Character ch) { public static String unicodeEscaped(final Character ch) {
if (ch == null) { return ch != null ? unicodeEscaped(ch.charValue()) : null;
return null;
}
return unicodeEscaped(ch.charValue());
} }
//--------------------------------------------------------------------------
/** /**
* <p>Checks whether the character is ASCII 7 bit.</p> * <p>Checks whether the character is ASCII 7 bit.</p>
* *
@ -539,6 +516,6 @@ public class CharUtils {
* @since 3.4 * @since 3.4
*/ */
public static int compare(final char x, final char y) { public static int compare(final char x, final char y) {
return x-y; return x - y;
} }
} }