Commit 5f3c39a0 authored by Emmanuel Bourg's avatar Emmanuel Bourg

New upstream version 3.7

parent 9e235977
......@@ -18,11 +18,11 @@ sudo: false
jdk:
- openjdk7
- oraclejdk7
- oraclejdk8
- oraclejdk9
script:
- mvn test apache-rat:check clirr:check checkstyle:check findbugs:check javadoc:javadoc -B
- mvn
after_success:
- mvn clean cobertura:cobertura coveralls:report
- mvn clean cobertura:cobertura coveralls:report -Ptravis-cobertura
......@@ -46,6 +46,7 @@ Apache Commons Lang
[![Build Status](https://travis-ci.org/apache/commons-lang.svg?branch=master)](https://travis-ci.org/apache/commons-lang)
[![Coverage Status](https://coveralls.io/repos/apache/commons-lang/badge.svg?branch=master)](https://coveralls.io/r/apache/commons-lang)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-lang3/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-lang3/)
[![Javadocs](https://javadoc.io/badge/org.apache.commons/commons-lang3/3.6.svg)](https://javadoc.io/doc/org.apache.commons/commons-lang3/3.6)
Apache Commons Lang, a package of Java utility classes for the
classes that are in java.lang's hierarchy, or are considered to be so
......
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Apache Commons Lang
Version 3.7
Release Notes
INTRODUCTION:
This document contains the release notes for the 3.7 version of Apache Commons Lang.
Commons Lang is a set of utility functions and reusable components that should be of use in any
Java environment.
Lang 3.0 and onwards now targets Java 5.0, making use of features that arrived with Java 5.0 such as generics,
variable arguments, autoboxing, concurrency and formatted output.
For the advice on upgrading from 2.x to 3.x, see the following page:
http://commons.apache.org/lang/article3_0.html
Apache Commons Lang, a package of Java utility classes for the
classes that are in java.lang's hierarchy, or are considered to be so
standard as to justify existence in java.lang.
New features and bug fixes. Requires Java 7, supports Java 8, 9, 10.
Changes in this version include:
New features:
o LANG-1355: TimeZone.getTimeZone() in FastDateParser causes resource contention (PR #296.) Thanks to Chas Honton.
o LANG-1360: Add methods to ObjectUtils to get various forms of class names in a null-safe manner Thanks to Gary Gregory.
Fixed Bugs:
o LANG-1362: Fix tests DateUtilsTest for Java 9 with en_GB locale Thanks to Stephen Colebourne.
o LANG-1365: Fix NullPointerException in isJavaVersionAtLeast on Java 10, add SystemUtils.IS_JAVA_10, add JavaVersion.JAVA_10 Thanks to Gary Gregory.
o LANG-1348: StackOverflowError on TypeUtils.toString(...) for a generic return type of Enum.valueOf Thanks to mbusso.
o LANG-1350: ConstructorUtils.invokeConstructor(Class, Object...) regression Thanks to Brett Kail.
o LANG-1349: EqualsBuilder#isRegistered: swappedPair construction bug Thanks to Naman Nigam.
o LANG-1357: org.apache.commons.lang3.time.FastDateParser should use toUpperCase(Locale) Thanks to BruceKuiLiu.
Changes:
o LANG-1358: Improve StringUtils#replace throughput Thanks to Stephane Landelle.
o LANG-1346: Remove deprecation from RandomStringUtils
o LANG-1361: ExceptionUtils.getThrowableList() is using deprecated ExceptionUtils.getCause() Thanks to Ana.
Historical list of changes: http://commons.apache.org/proper/commons-lang/changes-report.html
For complete information on Apache Commons Lang, including instructions on how to submit bug reports,
patches, or suggestions for improvement, see the Apache Apache Commons Lang website:
http://commons.apache.org/proper/commons-lang/
=============================================================================
Apache Commons Lang
Version 3.6
Release Notes
......@@ -180,6 +250,8 @@ o LANG-1301: Moving apache-rat-plugin configuration into pluginManagement.
Thanks to Karl Heinz Marbaise.
o LANG-1316: Deprecate classes/methods moved to commons-text.
=============================================================================
Release Notes for version 3.5
......@@ -477,6 +549,8 @@ o LANG-1107: Fix parsing edge cases in FastDateParser.
o LANG-1273: Added new property IS_OS_MAC_OSX_EL_CAPITAN in SystemUtils. Thanks
to Jake Wang.
=============================================================================
Release Notes for version 3.4
......@@ -611,6 +685,8 @@ o LANG-1003: DurationFormatUtils are not able to handle negative
o LANG-998: Javadoc is not clear on preferred pattern to instantiate
FastDateParser / FastDatePrinter
=============================================================================
Release Notes for version 3.3.2
NEW FEATURES
......@@ -623,6 +699,8 @@ FIXED BUGS
o LANG-992: NumberUtils#isNumber() returns false for "0.0", "0.4790", et al
=============================================================================
Release Notes for version 3.3.1
FIXED BUGS
......@@ -637,6 +715,8 @@ o LANG-982: DurationFormatUtils.formatDuration(61999, "s.SSSS") - ms field
size should be 4 digits
o LANG-978: Failing tests with Java 8 b128
=============================================================================
Release Notes for version 3.3
NEW FEATURES
......@@ -702,6 +782,8 @@ o LANG-953: Convert package.html files to package-info.java files
o LANG-940: Fix deprecation warnings
o LANG-819: EnumUtils.generateBitVector needs a "? extends"
=============================================================================
Release Notes for version 3.2.1
BUG FIXES
......@@ -714,6 +796,8 @@ o LANG-942: Test failure in FastDateParserTest and FastDateFormat_ParserTest
Henri Yandell.
o LANG-938: Build fails with test failures when building with JDK 8
=============================================================================
Release Notes for version 3.2
COMPATIBILITY WITH 3.1
......@@ -874,6 +958,7 @@ CHANGES WITHOUT TICKET
o Fixed URLs in javadoc to point to new oracle.com pages
=============================================================================
Release Notes for version 3.1
......@@ -908,6 +993,7 @@ o LANG-748: Deprecating chomp(String, String)
o LANG-736: CharUtils static final array CHAR_STRING is not needed to compute
CHAR_STRING_ARRAY
=============================================================================
Release Notes for version 3.0
......
......@@ -35,6 +35,9 @@ limitations under the License.
<property name="format" value="\s+$"/>
<property name="message" value="Line has trailing spaces."/>
</module>
<module name="SuppressionFilter">
<property name="file" value="checkstyle-suppressions.xml"/>
</module>
<module name="TreeWalker">
<property name="cacheFile" value="target/cachefile"/>
<module name="AvoidStarImport"/>
......
......@@ -80,34 +80,6 @@
<Bug pattern="SF_SWITCH_FALLTHROUGH" />
</Match>
<!-- Reason: hashCode is lazily loaded in Range classes -->
<!-- TODO: Work out why regex didn't work here -->
<Match>
<Class name="org.apache.commons.lang3.math.DoubleRange" />
<Field name="hashCode" />
<Bug pattern="SE_TRANSIENT_FIELD_NOT_RESTORED" />
</Match>
<Match>
<Class name="org.apache.commons.lang3.math.FloatRange" />
<Field name="hashCode" />
<Bug pattern="SE_TRANSIENT_FIELD_NOT_RESTORED" />
</Match>
<Match>
<Class name="org.apache.commons.lang3.math.IntRange" />
<Field name="hashCode" />
<Bug pattern="SE_TRANSIENT_FIELD_NOT_RESTORED" />
</Match>
<Match>
<Class name="org.apache.commons.lang3.math.LongRange" />
<Field name="hashCode" />
<Bug pattern="SE_TRANSIENT_FIELD_NOT_RESTORED" />
</Match>
<Match>
<Class name="org.apache.commons.lang3.math.NumberRange" />
<Field name="hashCode" />
<Bug pattern="SE_TRANSIENT_FIELD_NOT_RESTORED" />
</Match>
<!-- Reason: toProperString is lazily loaded -->
<Match>
<Class name="org.apache.commons.lang3.math.Fraction" />
......@@ -158,7 +130,7 @@
<Bug pattern="SF_SWITCH_NO_DEFAULT" />
</Match>
<!-- Reason: The fallthrough on the swich stateme is intentional -->
<!-- Reason: The fallthrough on the swich statement is intentional -->
<Match>
<Class name="org.apache.commons.lang3.time.FastDatePrinter"/>
<Method name="appendFullDigits" params="java.lang.Appendable, int, int"/>
......
......@@ -26,7 +26,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>commons-lang3</artifactId>
<version>3.6</version>
<version>3.7</version>
<name>Apache Commons Lang</name>
<inceptionYear>2001</inceptionYear>
......@@ -522,17 +522,10 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.bcel</groupId>
<artifactId>bcel</artifactId>
<version>6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.4</version>
<version>3.5</version>
<scope>test</scope>
</dependency>
......@@ -578,7 +571,7 @@
<commons.componentid>lang3</commons.componentid>
<commons.module.name>org.apache.commons.lang3</commons.module.name>
<!-- Current 3.x release series -->
<commons.release.version>3.6</commons.release.version>
<commons.release.version>3.7</commons.release.version>
<commons.release.desc>(Java 7.0+)</commons.release.desc>
<!-- Previous 2.x release series -->
<commons.release.2.version>2.6</commons.release.2.version>
......@@ -598,13 +591,13 @@
<checkstyle.plugin.version>2.17</checkstyle.plugin.version>
<!-- JMH Benchmark related properties, version, target compiler and name of the benchmarking uber jar. -->
<jmh.version>1.17.4</jmh.version>
<jmh.version>1.19</jmh.version>
<uberjar.name>benchmarks</uberjar.name>
</properties>
<build>
<defaultGoal>clean test apache-rat:check clirr:check checkstyle:check findbugs:check javadoc:javadoc</defaultGoal>
<defaultGoal>clean verify apache-rat:check clirr:check checkstyle:check findbugs:check javadoc:javadoc</defaultGoal>
<pluginManagement>
<plugins>
<plugin>
......@@ -684,7 +677,6 @@
<version>${checkstyle.plugin.version}</version>
<configuration>
<configLocation>${basedir}/checkstyle.xml</configLocation>
<suppressionsLocation>${basedir}/checkstyle-suppressions.xml</suppressionsLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<enableRulesSummary>false</enableRulesSummary>
</configuration>
......@@ -709,7 +701,6 @@
<version>${checkstyle.plugin.version}</version>
<configuration>
<configLocation>${basedir}/checkstyle.xml</configLocation>
<suppressionsLocation>${basedir}/checkstyle-suppressions.xml</suppressionsLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<enableRulesSummary>false</enableRulesSummary>
</configuration>
......@@ -733,7 +724,7 @@
</plugin>
<plugin>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.7</version>
<version>3.8</version>
<configuration>
<targetJdk>${maven.compiler.target}</targetJdk>
</configuration>
......@@ -836,35 +827,6 @@
</build>
</profile>
<profile>
<id>travis</id>
<activation>
<property>
<name>env.TRAVIS</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${commons.cobertura.version}</version>
<configuration>
<formats>
<format>xml</format>
</formats>
</configuration>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.3.0</version>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>java9</id>
<activation>
......@@ -873,6 +835,10 @@
<properties>
<!-- LANG-1265: allow tests to access private fields/methods of java.base classes via reflection -->
<argLine>-Xmx512m --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED</argLine>
<!-- versions below 3.0.0 do not work with java 9 -->
<commons.javadoc.version>3.0.0-M1</commons.javadoc.version>
<!-- coverall version 4.3.0 does not work with java 9, see https://github.com/trautonen/coveralls-maven-plugin/issues/112 -->
<coveralls.skip>true</coveralls.skip>
</properties>
</profile>
......
......@@ -45,6 +45,20 @@ The <action> type attribute can be add,update,fix,remove.
</properties>
<body>
<release version="3.7" date="2017-11-04" description="New features and bug fixes. Requires Java 7, supports Java 8, 9, 10.">
<action issue="LANG-1362" type="fix" dev="ggregory" due-to="Stephen Colebourne">Fix tests DateUtilsTest for Java 9 with en_GB locale</action>
<action issue="LANG-1365" type="fix" dev="ggregory" due-to="Gary Gregory">Fix NullPointerException in isJavaVersionAtLeast on Java 10, add SystemUtils.IS_JAVA_10, add JavaVersion.JAVA_10</action>
<action issue="LANG-1348" type="fix" dev="pschumacher" due-to="mbusso">StackOverflowError on TypeUtils.toString(...) for a generic return type of Enum.valueOf</action>
<action issue="LANG-1350" type="fix" dev="ggregory" due-to="Brett Kail">ConstructorUtils.invokeConstructor(Class, Object...) regression</action>
<action issue="LANG-1349" type="fix" dev="pschumacher" due-to="Naman Nigam">EqualsBuilder#isRegistered: swappedPair construction bug</action>
<action issue="LANG-1357" type="fix" dev="ggregory" due-to="BruceKuiLiu">org.apache.commons.lang3.time.FastDateParser should use toUpperCase(Locale)</action>
<action issue="LANG-1358" type="update" dev="pschumacher" due-to="Stephane Landelle">Improve StringUtils#replace throughput</action>
<action issue="LANG-1346" type="update" dev="pschumacher">Remove deprecation from RandomStringUtils</action>
<action issue="LANG-1361" type="update" dev="ggregory" due-to="Ana">ExceptionUtils.getThrowableList() is using deprecated ExceptionUtils.getCause()</action>
<action issue="LANG-1355" type="add" dev="ggregory" due-to="Chas Honton">TimeZone.getTimeZone() in FastDateParser causes resource contention (PR #296.)</action>
<action issue="LANG-1360" type="add" dev="ggregory" due-to="Gary Gregory">Add methods to ObjectUtils to get various forms of class names in a null-safe manner</action>
</release>
<release version="3.6" date="2017-06-08" description="New features and bug fixes. Requires Java 7.">
<action issue="LANG-1338" type="update" dev="britter">Add Automatic-Module-Name MANIFEST entry for Java 9 compatibility</action>
<action issue="LANG-1336" type="add" dev="britter" due-to="Beluga Behr">Add NUL Byte To CharUtils</action>
......
......@@ -49,32 +49,32 @@ private static void init() {
}
private static void init_X86_32Bit() {
Processor processor = new Processor(Processor.Arch.BIT_32, Processor.Type.X86);
final Processor processor = new Processor(Processor.Arch.BIT_32, Processor.Type.X86);
addProcessors(processor, "x86", "i386", "i486", "i586", "i686", "pentium");
}
private static void init_X86_64Bit() {
Processor processor = new Processor(Processor.Arch.BIT_64, Processor.Type.X86);
final Processor processor = new Processor(Processor.Arch.BIT_64, Processor.Type.X86);
addProcessors(processor, "x86_64", "amd64", "em64t", "universal");
}
private static void init_IA64_32Bit() {
Processor processor = new Processor(Processor.Arch.BIT_32, Processor.Type.IA_64);
final Processor processor = new Processor(Processor.Arch.BIT_32, Processor.Type.IA_64);
addProcessors(processor, "ia64_32", "ia64n");
}
private static void init_IA64_64Bit() {
Processor processor = new Processor(Processor.Arch.BIT_64, Processor.Type.IA_64);
final Processor processor = new Processor(Processor.Arch.BIT_64, Processor.Type.IA_64);
addProcessors(processor, "ia64", "ia64w");
}
private static void init_PPC_32Bit() {
Processor processor = new Processor(Processor.Arch.BIT_32, Processor.Type.PPC);
final Processor processor = new Processor(Processor.Arch.BIT_32, Processor.Type.PPC);
addProcessors(processor, "ppc", "power", "powerpc", "power_pc", "power_rs");
}
private static void init_PPC_64Bit() {
Processor processor = new Processor(Processor.Arch.BIT_64, Processor.Type.PPC);
final Processor processor = new Processor(Processor.Arch.BIT_64, Processor.Type.PPC);
addProcessors(processor, "ppc64", "power64", "powerpc64", "power_pc64", "power_rs64");
}
......@@ -85,11 +85,11 @@ private static void init_PPC_64Bit() {
* @param processor The {@link Processor} to add.
* @throws IllegalStateException If the key already exists.
*/
private static void addProcessor(String key, Processor processor) throws IllegalStateException {
private static void addProcessor(final String key, final Processor processor) throws IllegalStateException {
if (!ARCH_TO_PROCESSOR.containsKey(key)) {
ARCH_TO_PROCESSOR.put(key, processor);
} else {
String msg = "Key " + key + " already exists in processor map";
final String msg = "Key " + key + " already exists in processor map";
throw new IllegalStateException(msg);
}
}
......@@ -101,8 +101,8 @@ private static void addProcessor(String key, Processor processor) throws Illegal
* @param processor The {@link Processor} to add.
* @throws IllegalStateException If the key already exists.
*/
private static void addProcessors(Processor processor, String... keys) throws IllegalStateException {
for (String key : keys) {
private static void addProcessors(final Processor processor, final String... keys) throws IllegalStateException {
for (final String key : keys) {
addProcessor(key, processor);
}
}
......@@ -128,7 +128,7 @@ public static Processor getProcessor() {
* @param value A {@link String} like a value returned by the os.arch System Property.
* @return A {@link Processor} when it exists, else <code>null</code>.
*/
public static Processor getProcessor(String value) {
public static Processor getProcessor(final String value) {
return ARCH_TO_PROCESSOR.get(value);
}
......
......@@ -206,7 +206,7 @@ public boolean equals(final Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof CharRange == false) {
if (!(obj instanceof CharRange)) {
return false;
}
final CharRange other = (CharRange) obj;
......@@ -335,7 +335,7 @@ public boolean hasNext() {
*/
@Override
public Character next() {
if (hasNext == false) {
if (!hasNext) {
throw new NoSuchElementException();
}
final char cur = current;
......
......@@ -113,10 +113,10 @@ static int indexOf(final CharSequence cs, final int searchChar, int start) {
}
//supplementary characters (LANG1300)
if (searchChar <= Character.MAX_CODE_POINT) {
char[] chars = Character.toChars(searchChar);
final char[] chars = Character.toChars(searchChar);
for (int i = start; i < sz - 1; i++) {
char high = cs.charAt(i);
char low = cs.charAt(i + 1);
final char high = cs.charAt(i);
final char low = cs.charAt(i + 1);
if (high == chars[0] && low == chars[1]) {
return i;
}
......@@ -193,14 +193,14 @@ static int lastIndexOf(final CharSequence cs, final int searchChar, int start) {
//supplementary characters (LANG1300)
//NOTE - we must do a forward traversal for this to avoid duplicating code points
if (searchChar <= Character.MAX_CODE_POINT) {
char[] chars = Character.toChars(searchChar);
final char[] chars = Character.toChars(searchChar);
//make sure it's not the last index
if (start == sz - 1) {
return NOT_FOUND;
}
for (int i = start; i >= 0; i--) {
char high = cs.charAt(i);
char low = cs.charAt(i + 1);
final char high = cs.charAt(i);
final char low = cs.charAt(i + 1);
if (chars[0] == high && chars[1] == low) {
return i;
}
......
......@@ -175,7 +175,7 @@ public static CharSet getInstance(final String... setStrs) {
*/
protected CharSet(final String... set) {
super();
for (String s : set) {
for (final String s : set) {
add(s);
}
}
......@@ -263,7 +263,7 @@ public boolean equals(final Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof CharSet == false) {
if (!(obj instanceof CharSet)) {
return false;
}
final CharSet other = (CharSet) obj;
......
......@@ -232,7 +232,7 @@ private static String modify(final String str, final String[] set, final boolean
final CharSet chars = CharSet.getInstance(set);
final StringBuilder buffer = new StringBuilder(str.length());
final char[] chrs = str.toCharArray();
for (char chr : chrs) {
for (final char chr : chrs) {
if (chars.contains(chr) == expect) {
buffer.append(chr);
}
......
......@@ -206,7 +206,7 @@ public static char toChar(final String str, final char defaultValue) {
* <p>Converts the character to the Integer it represents, throwing an
* exception if the character is not numeric.</p>
*
* <p>This method coverts the char '1' to the int 1 and so on.</p>
* <p>This method converts the char '1' to the int 1 and so on.</p>
*
* <pre>
* CharUtils.toIntValue('3') = 3
......@@ -218,7 +218,7 @@ public static char toChar(final String str, final char defaultValue) {
* @throws IllegalArgumentException if the character is not ASCII numeric
*/
public static int toIntValue(final char ch) {
if (isAsciiNumeric(ch) == false) {
if (!isAsciiNumeric(ch)) {
throw new IllegalArgumentException("The character " + ch + " is not in the range '0' - '9'");
}
return ch - 48;
......@@ -228,7 +228,7 @@ public static int toIntValue(final char ch) {
* <p>Converts the character to the Integer it represents, throwing an
* exception if the character is not numeric.</p>
*
* <p>This method coverts the char '1' to the int 1 and so on.</p>
* <p>This method converts the char '1' to the int 1 and so on.</p>
*
* <pre>
* CharUtils.toIntValue('3', -1) = 3
......@@ -240,7 +240,7 @@ public static int toIntValue(final char ch) {
* @return the int value of the character
*/
public static int toIntValue(final char ch, final int defaultValue) {
if (isAsciiNumeric(ch) == false) {
if (!isAsciiNumeric(ch)) {
return defaultValue;
}
return ch - 48;
......@@ -250,7 +250,7 @@ public static int toIntValue(final char ch, final int defaultValue) {
* <p>Converts the character to the Integer it represents, throwing an
* exception if the character is not numeric.</p>
*
* <p>This method coverts the char '1' to the int 1 and so on.</p>
* <p>This method converts the char '1' to the int 1 and so on.</p>
*
* <pre>
* CharUtils.toIntValue('3') = 3
......@@ -271,7 +271,7 @@ public static int toIntValue(final Character ch) {
* <p>Converts the character to the Integer it represents, throwing an
* exception if the character is not numeric.</p>
*
* <p>This method coverts the char '1' to the int 1 and so on.</p>
* <p>This method converts the char '1' to the int 1 and so on.</p>
*
* <pre>
* CharUtils.toIntValue(null, -1) = -1
......@@ -351,13 +351,11 @@ public static String toString(final Character ch) {
* @return the escaped Unicode string
*/
public static String unicodeEscaped(final char ch) {
final StringBuilder sb = new StringBuilder(6);
sb.append("\\u");
sb.append(HEX_DIGITS[(ch >> 12) & 15]);
sb.append(HEX_DIGITS[(ch >> 8) & 15]);
sb.append(HEX_DIGITS[(ch >> 4) & 15]);
sb.append(HEX_DIGITS[(ch) & 15]);
return sb.toString();
return "\\u" +
HEX_DIGITS[(ch >> 12) & 15] +
HEX_DIGITS[(ch >> 8) & 15] +
HEX_DIGITS[(ch >> 4) & 15] +
HEX_DIGITS[(ch) & 15];
}
/**
......
......@@ -44,6 +44,7 @@
* @since 2.0
*/
public class ClassUtils {
/**
* Inclusivity literals for {@link #hierarchy(Class, Interfaces)}.
* @since 3.2
......@@ -242,32 +243,101 @@ public static String getShortClassName(String className) {
/**
* <p>Null-safe version of <code>aClass.getSimpleName()</code></p>
*
* @param cls the class for which to get the simple name.
* @param cls the class for which to get the simple name; may be null
* @return the simple class name.
* @since 3.0
* @see Class#getSimpleName()
*/
public static String getSimpleName(final Class<?> cls) {
if (cls == null) {
return StringUtils.EMPTY;
}
return cls.getSimpleName();
return getSimpleName(cls, StringUtils.EMPTY);
}
/**
* <p>Null-safe version of <code>aClass.getSimpleName()</code></p>
*
* @param cls the class for which to get the simple name; may be null
* @param valueIfNull the value to return if null
* @return the simple class name or {@code valueIfNull}
* @since 3.0
* @see Class#getSimpleName()
*/
public static String getSimpleName(final Class<?> cls, String valueIfNull) {
return cls == null ? valueIfNull : cls.getSimpleName();
}
/**
* <p>Null-safe version of <code>aClass.getSimpleName()</code></p>
*
* @param object the object for which to get the simple class name; may be null
* @return the simple class name or the empty String
* @since 3.7
* @see Class#getSimpleName()
*/
public static String getSimpleName(final Object object) {
return getSimpleName(object, StringUtils.EMPTY);
}
/**
* <p>Null-safe version of <code>aClass.getSimpleName()</code></p>
*
* @param object the object for which to get the simple class name.
* @param object the object for which to get the simple class name; may be null
* @param valueIfNull the value to return if <code>object</code> is <code>null</code>
* @return the simple class name.
* @return the simple class name or {@code valueIfNull}
* @since 3.0
* @see Class#getSimpleName()
*/
public static String getSimpleName(final Object object, final String valueIfNull) {
if (object == null) {
return valueIfNull;
}
return getSimpleName(object.getClass());
return object == null ? valueIfNull : object.getClass().getSimpleName();
}
/**
* <p>Null-safe version of <code>Class.getName()</code></p>
*
* @param cls the class for which to get the class name; may be null
* @return the class name or the empty String.
* @since 3.7
* @see Class#getSimpleName()
*/
public static String getName(final Class<?> cls) {
return getName(cls, StringUtils.EMPTY);
}
/**
* <p>Null-safe version of <code>aClass.getName()</code></p>
*
* @param cls the class for which to get the class name; may be null
* @param valueIfNull the return value if <code>cls</code> is <code>null</code>
* @return the class name or {@code valueIfNull}
* @since 3.7
* @see Class#getName()
*/
public static String getName(final Class<?> cls, final String valueIfNull) {
return cls == null ? valueIfNull : cls.getName();
}