Commit d5eac437 authored by Emmanuel Bourg's avatar Emmanuel Bourg

New upstream version 3.8

parent 5f3c39a0
......@@ -16,13 +16,31 @@
language: java
sudo: false
jdk:
- openjdk7
- oraclejdk8
- oraclejdk9
# Get latest install-jdk.sh script
before_install:
- wget -P ./target/ https://github.com/sormuras/bach/raw/master/install-jdk.sh
matrix:
include:
- env: JDK_RELEASE='OpenJDK 7'
jdk: openjdk7
- env: JDK_RELEASE='OracleJDK 8'
jdk: oraclejdk8
- env: JDK_RELEASE='OracleJDK 9'
jdk: oraclejdk9
- env: JDK_RELEASE='OracleJDK 10'
jdk: oraclejdk10
- env: JDK_RELEASE='OpenJDK 10'
jdk: openjdk10
# Java 11 "Oracle JDK" (not yet provided by Travis CI)
- env: JDK='Oracle JDK 11'
install: . ./target/install-jdk.sh -F 11 -L BCL
# some FastDateParser tests currently fail with java.text.ParseException: Unparseable date
allow_failures:
- env: JDK='Oracle JDK 11'
script:
- mvn
after_success:
- mvn clean cobertura:cobertura coveralls:report -Ptravis-cobertura
- mvn clean test jacoco:report coveralls:report -Ptravis-jacoco
......@@ -50,48 +50,66 @@ Getting Started
+ Make sure you have a [JIRA account](https://issues.apache.org/jira/).
+ Make sure you have a [GitHub account](https://github.com/signup/free).
+ If you're planning to implement a new feature it makes sense to discuss you're changes on the [dev list](https://commons.apache.org/mail-lists.html) first. This way you can make sure you're not wasting your time on something that isn't considered to be in Apache Commons Lang's scope.
+ Submit a ticket for your issue, assuming one does not already exist.
+ If you're planning to implement a new feature it makes sense to discuss your changes on the [dev list](https://commons.apache.org/mail-lists.html) first. This way you can make sure you're not wasting your time on something that isn't considered to be in Apache Commons Lang's scope.
+ Submit a [Jira Ticket][jira] for your issue, assuming one does not already exist.
+ Clearly describe the issue including steps to reproduce when it is a bug.
+ Make sure you fill in the earliest version that you know has the issue.
+ Fork the repository on GitHub.
+ Find the corresponding [repository on GitHub](https://github.com/apache/?query=commons-),
[fork](https://help.github.com/articles/fork-a-repo/) and check out your forked repository.
Making Changes
--------------
+ Create a topic branch from where you want to base your work (this is usually the master/trunk branch).
+ Create a _topic branch_ for your isolated work.
* Usually you should base your branch on the `master` or `trunk` branch.
* A good topic branch name can be the JIRA bug id plus a keyword, e.g. `LANG-123-InputStream`.
* If you have submitted multiple JIRA issues, try to maintain separate branches and pull requests.
+ Make commits of logical units.
* Make sure your commit messages are meaningful and in the proper format. Your commit message should contain the key of the JIRA issue.
* e.g. `LANG-123: Close input stream earlier`
+ Respect the original code style:
+ Only use spaces for indentation.
+ Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change.
+ Check for unnecessary whitespace with git diff --check before committing.
+ Make sure your commit messages are in the proper format. Your commit message should contain the key of the JIRA issue.
+ Make sure you have added the necessary tests for your changes.
+ Create minimal diffs - disable _On Save_ actions like _Reformat Source Code_ or _Organize Imports_. If you feel the source code should be reformatted create a separate PR for this change first.
+ Check for unnecessary whitespace with `git diff` -- check before committing.
+ Make sure you have added the necessary tests for your changes, typically in `src/test/java`.
+ Run all the tests with `mvn clean verify` to assure nothing else was accidentally broken.
Making Trivial Changes
----------------------
The JIRA tickets are used to generate the changelog for the next release.
For changes of a trivial nature to comments and documentation, it is not always necessary to create a new ticket in JIRA.
In this case, it is appropriate to start the first line of a commit with '(doc)' instead of a ticket number.
Submitting Changes
------------------
+ Sign the [Contributor License Agreement][cla] if you haven't already.
+ Sign and submit the Apache [Contributor License Agreement][cla] if you haven't already.
* Note that small patches & typical bug fixes do not require a CLA as
clause 5 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0.html#contributions)
covers them.
+ Push your changes to a topic branch in your fork of the repository.
+ Submit a pull request to the repository in the apache organization.
+ Submit a _Pull Request_ to the corresponding repository in the `apache` organization.
* Verify _Files Changed_ shows only your intended changes and does not
include additional files like `target/*.class`
+ Update your JIRA ticket and include a link to the pull request in the ticket.
If you prefer to not use GitHub, then you can instead use
`git format-patch` (or `svn diff`) and attach the patch file to the JIRA issue.
Additional Resources
--------------------
+ [Contributing patches](https://commons.apache.org/patches.html)
+ [Apache Commons Lang JIRA project page](https://issues.apache.org/jira/browse/LANG)
+ [Apache Commons Lang JIRA project page][jira]
+ [Contributor License Agreement][cla]
+ [General GitHub documentation](https://help.github.com/)
+ [GitHub pull request documentation](https://help.github.com/send-pull-requests/)
+ [GitHub pull request documentation](https://help.github.com/articles/creating-a-pull-request/)
+ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons)
+ #apachecommons IRC channel on freenode.org
+ `#apache-commons` IRC channel on `irc.freenode.net`
[cla]:https://www.apache.org/licenses/#clas
[jira]:https://issues.apache.org/jira/browse/LANG
Apache Commons Lang
Copyright 2001-2017 The Apache Software Foundation
Copyright 2001-2018 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
This product includes software from the Spring Framework,
under the Apache License 2.0 (see: StringUtils.containsWhitespace())
......@@ -43,10 +43,10 @@
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)
[![Build Status](https://travis-ci.org/apache/commons-lang.svg)](https://travis-ci.org/apache/commons-lang)
[![Coverage Status](https://coveralls.io/repos/apache/commons-lang/badge.svg)](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)
[![Javadocs](https://javadoc.io/badge/org.apache.commons/commons-lang3/3.8.svg)](https://javadoc.io/doc/org.apache.commons/commons-lang3/3.8)
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
......@@ -55,13 +55,13 @@ Apache Commons Lang, a package of Java utility classes for the
Documentation
-------------
More information can be found on the [homepage](https://commons.apache.org/proper/commons-lang).
The [JavaDoc](https://commons.apache.org/proper/commons-lang/javadocs/api-release) can be browsed.
More information can be found on the [Apache Commons Lang homepage](https://commons.apache.org/proper/commons-lang3).
The [Javadoc](https://commons.apache.org/proper/commons-lang3/javadocs/api-release) can be browsed.
Questions related to the usage of Apache Commons Lang should be posted to the [user mailing list][ml].
Where can I get the latest release?
-----------------------------------
You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-lang/download_lang.cgi).
You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-lang3/download_lang3.cgi).
Alternatively you can pull it from the central Maven repositories:
......@@ -69,14 +69,14 @@ Alternatively you can pull it from the central Maven repositories:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.6</version>
<version>3.8</version>
</dependency>
```
Contributing
------------
We accept PRs via github. The [developer mailing list][ml] is the main channel of communication for contributors.
We accept Pull Requests via GitHub. The [developer mailing list][ml] is the main channel of communication for contributors.
There are some guidelines which will make applying PRs easier for us:
+ No tabs! Please use spaces for indentation.
+ Respect the code style.
......@@ -88,7 +88,9 @@ You can learn more about contributing via GitHub in our [contribution guidelines
License
-------
Code is under the [Apache Licence v2](https://www.apache.org/licenses/LICENSE-2.0.txt).
This code is under the [Apache Licence v2](https://www.apache.org/licenses/LICENSE-2.0).
See the `NOTICE.txt` file for required notices and attributions.
Donations
---------
......@@ -97,10 +99,9 @@ You like Apache Commons Lang? Then [donate back to the ASF](https://www.apache.o
Additional Resources
--------------------
+ [Apache Commons Lang Homepage](https://commons.apache.org/proper/commons-lang)
+ [Apache Commons Lang Bugtracker (JIRA)](https://issues.apache.org/jira/browse/LANG)
+ [Apache Commons Homepage](https://commons.apache.org/)
+ [Apache Issue Tracker (JIRA)](https://issues.apache.org/jira/browse/LANG)
+ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons)
+ #apachecommons IRC channel on freenode.org
+ `#apache-commons` IRC channel on `irc.freenode.org`
[ml]:https://commons.apache.org/mail-lists.html
This diff is collapsed.
......@@ -22,11 +22,11 @@
<parent>
<groupId>org.apache.commons</groupId>
<artifactId>commons-parent</artifactId>
<version>42</version>
<version>47</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
<version>3.8</version>
<name>Apache Commons Lang</name>
<inceptionYear>2001</inceptionYear>
......@@ -47,7 +47,7 @@
<connection>scm:git:http://git-wip-us.apache.org/repos/asf/commons-lang.git</connection>
<developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/commons-lang.git</developerConnection>
<url>https://git-wip-us.apache.org/repos/asf?p=commons-lang.git</url>
<tag>LANG_3_6</tag>
<tag>LANG_3_8</tag>
</scm>
<developers>
......@@ -525,7 +525,7 @@
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.5</version>
<version>3.6</version>
<scope>test</scope>
</dependency>
......@@ -567,12 +567,14 @@
The above seems to change the download page name but not any other
properties that depend on the componentid.
N.B. The componentid is also used by the parent pom as part of the OSGI symbolic name.
-->
<commons.componentid>lang3</commons.componentid>
<commons.module.name>org.apache.commons.lang3</commons.module.name>
<!-- Current 3.x release series -->
<commons.release.version>3.7</commons.release.version>
<commons.release.desc>(Java 7.0+)</commons.release.desc>
<commons.release.version>3.8</commons.release.version>
<commons.release.desc>(Java 7+)</commons.release.desc>
<!-- Previous 2.x release series -->
<commons.release.2.version>2.6</commons.release.2.version>
<commons.release.2.desc>(Requires Java 1.2 or later)</commons.release.2.desc>
......@@ -586,13 +588,25 @@
<commons.scmPubCheckoutDirectory>site-content</commons.scmPubCheckoutDirectory>
<commons.encoding>utf-8</commons.encoding>
<!-- Override clirr version to be able to build the site on Java 8 -->
<commons.clirr.version>2.8</commons.clirr.version>
<checkstyle.plugin.version>2.17</checkstyle.plugin.version>
<checkstyle.plugin.version>3.0.0</checkstyle.plugin.version>
<japicmp.skip>false</japicmp.skip>
<!-- JMH Benchmark related properties, version, target compiler and name of the benchmarking uber jar. -->
<jmh.version>1.19</jmh.version>
<jmh.version>1.21</jmh.version>
<uberjar.name>benchmarks</uberjar.name>
<!-- generate report even if there are binary incompatible changes -->
<commons.japicmp.breakBuildOnBinaryIncompatibleModifications>false</commons.japicmp.breakBuildOnBinaryIncompatibleModifications>
<!-- 0.12.0 dies with a NullPointerException -->
<commons.japicmp.version>0.11.1</commons.japicmp.version>
<!-- Commons Release Plugin -->
<commons.bc.version>3.7</commons.bc.version>
<commons.rc.version>RC1</commons.rc.version>
<commons.release.isDistModule>true</commons.release.isDistModule>
<commons.distSvnStagingUrl>scm:svn:https://dist.apache.org/repos/dist/dev/commons/lang</commons.distSvnStagingUrl>
<commons.releaseManagerName>Rob Tompkins</commons.releaseManagerName>
<commons.releaseManagerKey>B6E73D84EA4FCC47166087253FAAD2CD5ECBB314</commons.releaseManagerKey>
</properties>
......@@ -613,6 +627,14 @@
</excludes>
</configuration>
</plugin>
<!-- override skip property of parent pom -->
<plugin>
<groupId>com.github.siom79.japicmp</groupId>
<artifactId>japicmp-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
......@@ -654,11 +676,10 @@
</goals>
</execution>
</executions>
<!-- Temporary fix for LANG-1338, remove this after this has implemented in parent pom -->
<configuration>
<archive combine.children="append">
<manifestEntries>
<Automatic-Module-Name>org.apache.commons.lang3</Automatic-Module-Name>
<Automatic-Module-Name>${commons.module.name}</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
......@@ -724,7 +745,7 @@
</plugin>
<plugin>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.8</version>
<version>3.9.0</version>
<configuration>
<targetJdk>${maven.compiler.target}</targetJdk>
</configuration>
......@@ -828,20 +849,29 @@
</profile>
<profile>
<id>java9</id>
<id>java9+</id>
<activation>
<jdk>9</jdk>
<jdk>[9,)</jdk>
</activation>
<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>
<profile>
<id>java11+</id>
<activation>
<jdk>[11,)</jdk>
</activation>
<properties>
<!-- jacoco does not work with java 11 yet, see https://github.com/jacoco/jacoco/issues/663 -->
<jacoco.skip>true</jacoco.skip>
</properties>
</profile>
<profile>
<id>benchmark</id>
<properties>
......
This diff is collapsed.
......@@ -85,13 +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(final String key, final Processor processor) throws IllegalStateException {
if (!ARCH_TO_PROCESSOR.containsKey(key)) {
ARCH_TO_PROCESSOR.put(key, processor);
} else {
final String msg = "Key " + key + " already exists in processor map";
throw new IllegalStateException(msg);
private static void addProcessor(final String key, final Processor processor) {
if (ARCH_TO_PROCESSOR.containsKey(key)) {
throw new IllegalStateException("Key " + key + " already exists in processor map");
}
ARCH_TO_PROCESSOR.put(key, processor);
}
/**
......@@ -101,7 +99,7 @@ private static void addProcessor(final String key, final Processor processor) th
* @param processor The {@link Processor} to add.
* @throws IllegalStateException If the key already exists.
*/
private static void addProcessors(final Processor processor, final String... keys) throws IllegalStateException {
private static void addProcessors(final Processor processor, final String... keys) {
for (final String key : keys) {
addProcessor(key, processor);
}
......
......@@ -3870,7 +3870,7 @@ public static int indexOf(final double[] array, final double valueToFind, final
* {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
*/
public static int indexOf(final double[] array, final double valueToFind, int startIndex) {
if (ArrayUtils.isEmpty(array)) {
if (isEmpty(array)) {
return INDEX_NOT_FOUND;
}
if (startIndex < 0) {
......@@ -3902,7 +3902,7 @@ public static int indexOf(final double[] array, final double valueToFind, int st
* {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
*/
public static int indexOf(final double[] array, final double valueToFind, int startIndex, final double tolerance) {
if (ArrayUtils.isEmpty(array)) {
if (isEmpty(array)) {
return INDEX_NOT_FOUND;
}
if (startIndex < 0) {
......@@ -3964,7 +3964,7 @@ public static int lastIndexOf(final double[] array, final double valueToFind, fi
* {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
*/
public static int lastIndexOf(final double[] array, final double valueToFind, int startIndex) {
if (ArrayUtils.isEmpty(array)) {
if (isEmpty(array)) {
return INDEX_NOT_FOUND;
}
if (startIndex < 0) {
......@@ -3998,7 +3998,7 @@ public static int lastIndexOf(final double[] array, final double valueToFind, in
* {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
*/
public static int lastIndexOf(final double[] array, final double valueToFind, int startIndex, final double tolerance) {
if (ArrayUtils.isEmpty(array)) {
if (isEmpty(array)) {
return INDEX_NOT_FOUND;
}
if (startIndex < 0) {
......@@ -4077,7 +4077,7 @@ public static int indexOf(final float[] array, final float valueToFind) {
* {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
*/
public static int indexOf(final float[] array, final float valueToFind, int startIndex) {
if (ArrayUtils.isEmpty(array)) {
if (isEmpty(array)) {
return INDEX_NOT_FOUND;
}
if (startIndex < 0) {
......@@ -4120,7 +4120,7 @@ public static int lastIndexOf(final float[] array, final float valueToFind) {
* {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
*/
public static int lastIndexOf(final float[] array, final float valueToFind, int startIndex) {
if (ArrayUtils.isEmpty(array)) {
if (isEmpty(array)) {
return INDEX_NOT_FOUND;
}
if (startIndex < 0) {
......@@ -4181,7 +4181,7 @@ public static int indexOf(final boolean[] array, final boolean valueToFind) {
* array input
*/
public static int indexOf(final boolean[] array, final boolean valueToFind, int startIndex) {
if (ArrayUtils.isEmpty(array)) {
if (isEmpty(array)) {
return INDEX_NOT_FOUND;
}
if (startIndex < 0) {
......@@ -4225,7 +4225,7 @@ public static int lastIndexOf(final boolean[] array, final boolean valueToFind)
* {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
*/
public static int lastIndexOf(final boolean[] array, final boolean valueToFind, int startIndex) {
if (ArrayUtils.isEmpty(array)) {
if (isEmpty(array)) {
return INDEX_NOT_FOUND;
}
if (startIndex < 0) {
......@@ -7436,7 +7436,7 @@ static Object removeAll(final Object array, final int... indices) {
*/
// package protected for access by unit tests
static Object removeAll(final Object array, final BitSet indices) {
final int srcLength = ArrayUtils.getLength(array);
final int srcLength = getLength(array);
// No need to check maxIndex here, because method only currently called from removeElements()
// which guarantee to generate on;y valid bit entries.
// final int maxIndex = indices.length();
......@@ -8672,4 +8672,20 @@ public static void shuffle(final double[] array, final Random random) {
swap(array, i - 1, random.nextInt(i), 1);
}
}
/**
* Returns whether a given array can safely be accessed at the given index.
* @param <T> the component type of the array
* @param array the array to inspect, may be null
* @param index the index of the array to be inspected
* @return Whether the given index is safely-accessible in the given array
* @since 3.8
*/
public static <T> boolean isArrayIndexValid(T[] array, int index){
if(getLength(array) == 0 || array.length <= index){
return false;
}
return index >= 0;
}
}
......@@ -84,7 +84,7 @@
*/
public BitField(final int mask) {
_mask = mask;
_shift_count = mask != 0 ? Integer.numberOfTrailingZeros(mask) : 0;
_shift_count = mask == 0 ? 0 : Integer.numberOfTrailingZeros(mask);
}
/**
......
......@@ -30,7 +30,7 @@
private static final String[] CHAR_STRING_ARRAY = new String[128];
private static final char[] HEX_DIGITS = new char[] {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
/**
* {@code \u000a} linefeed LF ('\n').
......
......@@ -429,8 +429,8 @@ public static String getAbbreviatedName(final Class<?> cls, final int len) {
* If enough space is available, rightmost sub-packages will be displayed in full
* length.</p>
*
* <p>The following table illustrates the algorithm:</p>
* <table summary="abbreviation examples">
* <table>
* <caption>Examples</caption>
* <tr><td>className</td><td>len</td><td>return</td></tr>
* <tr><td> null</td><td> 1</td><td>""</td></tr>
* <tr><td>"java.lang.String"</td><td> 5</td><td>"j.l.String"</td></tr>
......@@ -641,7 +641,7 @@ private static void getAllInterfaces(Class<?> cls, final HashSet<Class<?>> inter
* @return {@code true} if assignment possible
*/
public static boolean isAssignable(final Class<?>[] classArray, final Class<?>... toClassArray) {
return isAssignable(classArray, toClassArray, SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_5));
return isAssignable(classArray, toClassArray, true);
}
/**
......@@ -757,7 +757,7 @@ public static boolean isPrimitiveWrapper(final Class<?> type) {
* @return {@code true} if assignment possible
*/
public static boolean isAssignable(final Class<?> cls, final Class<?> toClass) {
return isAssignable(cls, toClass, SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_5));
return isAssignable(cls, toClass, true);
}
/**
......@@ -1084,7 +1084,7 @@ public static boolean isInnerClass(final Class<?> cls) {
* or if the method doesn't conform with the requirements
*/
public static Method getPublicMethod(final Class<?> cls, final String methodName, final Class<?>... parameterTypes)
throws SecurityException, NoSuchMethodException {
throws NoSuchMethodException {
final Method declaredMethod = cls.getMethod(methodName, parameterTypes);
if (Modifier.isPublic(declaredMethod.getDeclaringClass().getModifiers())) {
......@@ -1263,7 +1263,7 @@ public static String getShortCanonicalName(final Class<?> cls) {
* @since 2.4
*/
public static String getShortCanonicalName(final String canonicalName) {
return ClassUtils.getShortClassName(getCanonicalName(canonicalName));
return getShortClassName(getCanonicalName(canonicalName));
}
// Package name
......@@ -1308,7 +1308,7 @@ public static String getPackageCanonicalName(final Class<?> cls) {
* @since 2.4
*/
public static String getPackageCanonicalName(final String canonicalName) {
return ClassUtils.getPackageName(getCanonicalName(canonicalName));
return getPackageName(getCanonicalName(canonicalName));
}
/**
......@@ -1347,7 +1347,7 @@ private static String getCanonicalName(String className) {
? className.length() - 1
: className.length());
} else {
if (className.length() > 0) {
if (!className.isEmpty()) {
className = reverseAbbreviationMap.get(className.substring(0, 1));
}
}
......
......@@ -60,27 +60,27 @@
* so far.
* </p>
*
* @since Lang 3.2
* @since 3.2
*/
public class Conversion {
private static final boolean[] TTTT = new boolean[] { true, true, true, true };
private static final boolean[] FTTT = new boolean[] { false, true, true, true };
private static final boolean[] TFTT = new boolean[] { true, false, true, true };
private static final boolean[] FFTT = new boolean[] { false, false, true, true };
private static final boolean[] TTFT = new boolean[] { true, true, false, true };
private static final boolean[] FTFT = new boolean[] { false, true, false, true };
private static final boolean[] TFFT = new boolean[] { true, false, false, true };
private static final boolean[] FFFT = new boolean[] { false, false, false, true };
private static final boolean[] TTTF = new boolean[] { true, true, true, false };
private static final boolean[] FTTF = new boolean[] { false, true, true, false };
private static final boolean[] TFTF = new boolean[] { true, false, true, false };
private static final boolean[] FFTF = new boolean[] { false, false, true, false };
private static final boolean[] TTFF = new boolean[] { true, true, false, false };
private static final boolean[] FTFF = new boolean[] { false, true, false, false };
private static final boolean[] TFFF = new boolean[] { true, false, false, false };
private static final boolean[] FFFF = new boolean[] { false, false, false, false };
private static final boolean[] TTTT = {true, true, true, true};
private static final boolean[] FTTT = {false, true, true, true};
private static final boolean[] TFTT = {true, false, true, true};
private static final boolean[] FFTT = {false, false, true, true};
private static final boolean[] TTFT = {true, true, false, true};
private static final boolean[] FTFT = {false, true, false, true};
private static final boolean[] TFFT = {true, false, false, true};
private static final boolean[] FFFT = {false, false, false, true};
private static final boolean[] TTTF = {true, true, true, false};
private static final boolean[] FTTF = {false, true, true, false};
private static final boolean[] TFTF = {true, false, true, false};
private static final boolean[] FFTF = {false, false, true, false};
private static final boolean[] TTFF = {true, true, false, false};
private static final boolean[] FTFF = {false, true, false, false};
private static final boolean[] TFFF = {true, false, false, false};
private static final boolean[] FFFF = {false, false, false, false};
/**
* <p>
......
<
......@@ -87,15 +87,24 @@ public EnumUtils() {
* @return true if the enum name is valid, otherwise false
*/
public static <E extends Enum<E>> boolean isValidEnum(final Class<E> enumClass, final String enumName) {
if (enumName == null) {
return false;
}
try {
Enum.valueOf(enumClass, enumName);
return true;
} catch (final IllegalArgumentException ex) {
return false;
}
return getEnum(enumClass, enumName) != null;
}
/**
* <p>Checks if the specified name is a valid enum for the class.</p>
*
* <p>This method differs from {@link Enum#valueOf} in that checks if the name is
* a valid enum without needing to catch the exception
* and performs case insensitive matching of the name.</p>
*
* @param <E> the type of the enumeration
* @param enumClass the class of the enum to query, not null
* @param enumName the enum name, null returns false
* @return true if the enum name is valid, otherwise false
* @since 3.8
*/
public static <E extends Enum<E>> boolean isValidEnumIgnoreCase(final Class<E> enumClass, final String enumName) {
return getEnumIgnoreCase(enumClass, enumName) != null;
}
/**
......@@ -120,6 +129,30 @@ public EnumUtils() {
}
}
/**
* <p>Gets the enum for the class, returning {@code null} if not found.</p>
*
* <p>This method differs from {@link Enum#valueOf} in that it does not throw an exception
* for an invalid enum name and performs case insensitive matching of the name.</p>
*
* @param <E> the type of the enumeration
* @param enumClass the class of the enum to query, not null
* @param enumName the enum name, null returns null
* @return the enum, null if not found
* @since 3.8
*/
public static <E extends Enum<E>> E getEnumIgnoreCase(final Class<E> enumClass, final String enumName) {
if (enumName == null || !enumClass.isEnum()) {
return null;
}
for (final E each : enumClass.getEnumConstants()) {
if (each.name().equalsIgnoreCase(enumName)) {
return each;
}
}
return null;
}
/**