├── RELEASE-NOTES.txt ├── src ├── media │ ├── logo.png │ ├── commons-logo-component.xcf │ └── commons-logo-component-100.xcf ├── site │ ├── resources │ │ ├── images │ │ │ └── logo.png │ │ ├── release-notes │ │ │ ├── RELEASE-NOTES-3.8.txt │ │ │ ├── RELEASE-NOTES-3.9.txt │ │ │ └── RELEASE-NOTES-3.8.1.txt │ │ ├── download_lang.cgi │ │ ├── profile.jacoco │ │ ├── .htaccess │ │ └── checkstyle │ │ │ └── checkstyle-suppressions.xml │ └── xdoc │ │ └── userguide.xml ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── lang3 │ │ ├── doc-files │ │ └── logo.png │ │ ├── event │ │ └── package-info.java │ │ ├── arch │ │ └── package-info.java │ │ ├── util │ │ └── package-info.java │ │ ├── tuple │ │ └── package-info.java │ │ ├── compare │ │ └── package-info.java │ │ ├── reflect │ │ ├── package-info.java │ │ └── Typed.java │ │ ├── concurrent │ │ ├── locks │ │ │ └── package-info.java │ │ ├── UncheckedTimeoutException.java │ │ ├── UncheckedExecutionException.java │ │ ├── FutureTasks.java │ │ └── Computable.java │ │ ├── mutable │ │ └── package-info.java │ │ ├── stream │ │ └── package-info.java │ │ ├── function │ │ ├── ByteSupplier.java │ │ ├── FailableRunnable.java │ │ ├── FailableIntSupplier.java │ │ ├── package-info.java │ │ ├── FailableLongSupplier.java │ │ ├── FailableByteSupplier.java │ │ ├── FailableCallable.java │ │ ├── FailableDoubleSupplier.java │ │ ├── FailableBooleanSupplier.java │ │ ├── FailableShortSupplier.java │ │ ├── FailableIntBinaryOperator.java │ │ ├── FailableLongBinaryOperator.java │ │ ├── FailableDoubleBinaryOperator.java │ │ ├── IntToCharFunction.java │ │ ├── ToBooleanBiFunction.java │ │ ├── FailableLongToIntFunction.java │ │ ├── FailableIntToLongFunction.java │ │ ├── FailableDoubleToIntFunction.java │ │ ├── FailableDoubleToLongFunction.java │ │ ├── FailableIntToDoubleFunction.java │ │ ├── FailableLongToDoubleFunction.java │ │ ├── FailableIntFunction.java │ │ ├── FailableLongFunction.java │ │ ├── FailableIntToFloatFunction.java │ │ ├── FailableDoubleFunction.java │ │ ├── FailableToBooleanFunction.java │ │ └── FailableToIntFunction.java │ │ ├── builder │ │ ├── DiffExclude.java │ │ ├── ToStringExclude.java │ │ ├── EqualsExclude.java │ │ ├── HashCodeExclude.java │ │ ├── ToStringSummary.java │ │ ├── Reflection.java │ │ ├── package-info.java │ │ └── AbstractSupplier.java │ │ ├── exception │ │ ├── package-info.java │ │ ├── UncheckedInterruptedException.java │ │ ├── UncheckedIllegalAccessException.java │ │ ├── UncheckedReflectiveOperationException.java │ │ ├── UncheckedException.java │ │ └── CloneFailedException.java │ │ ├── time │ │ └── package-info.java │ │ ├── text │ │ ├── translate │ │ │ └── package-info.java │ │ ├── FormatFactory.java │ │ └── package-info.java │ │ └── NumberRange.java ├── test │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── lang3 │ │ ├── reflect │ │ ├── testbed │ │ │ ├── Grandchild.java │ │ │ ├── AnotherChild.java │ │ │ ├── GenericConsumer.java │ │ │ ├── Bar.java │ │ │ ├── StaticContainerChild.java │ │ │ ├── AnotherParent.java │ │ │ ├── Foo.java │ │ │ ├── Ambig.java │ │ │ ├── PubliclyShadowedChild.java │ │ │ ├── PrivatelyShadowedChild.java │ │ │ ├── Annotated.java │ │ │ ├── GenericParent.java │ │ │ ├── Parent.java │ │ │ ├── PublicChild.java │ │ │ ├── StringParameterizedChild.java │ │ │ ├── PackageBeanOtherPackage.java │ │ │ ├── PublicSubBeanOtherPackage.java │ │ │ └── GenericTypeHolder.java │ │ ├── Lang1703Test.java │ │ ├── Lang1792Test.java │ │ ├── PackageBean.java │ │ └── PublicSubBean.java │ │ ├── function │ │ ├── AnnotationTestFixture.java │ │ ├── ByteSupplierTest.java │ │ ├── IntToCharFunctionTest.java │ │ ├── ToBooleanBiFunctionTest.java │ │ ├── SuppliersTest.java │ │ ├── FailableSupplierTest.java │ │ ├── MethodInvokersFailableSupplierTest.java │ │ ├── PredicatesTest.java │ │ └── MethodInvokersSupplierTest.java │ │ ├── time │ │ ├── FastDateFormat_PrinterTest.java │ │ └── TimeZonesTest.java │ │ ├── builder │ │ ├── IDKeyTest.java │ │ ├── ReflectionToStringBuilderTest.java │ │ ├── ReflectionToStringBuilderSummaryTest.java │ │ └── ConversionTest.java │ │ ├── exception │ │ ├── UncheckedExceptionTest.java │ │ ├── UncheckedInterruptedExceptionTest.java │ │ ├── UncheckedIllegalAccessExceptionTest.java │ │ ├── CustomCheckedException.java │ │ ├── UncheckedReflectiveOperationExceptionTest.java │ │ ├── CustomUncheckedException.java │ │ └── AbstractExceptionTest.java │ │ ├── concurrent │ │ ├── UncheckedTimeoutExceptionTest.java │ │ ├── UncheckedExecutionExceptionTest.java │ │ ├── FutureTasksTest.java │ │ ├── LazyInitializerSupplierTest.java │ │ ├── AtomicInitializerSupplierTest.java │ │ ├── ConcurrentRuntimeExceptionTest.java │ │ └── LazyInitializerAnonClassTest.java │ │ ├── ObjectToStringRuntimeException.java │ │ ├── AbstractLangTest.java │ │ ├── StringUtilsValueOfTest.java │ │ ├── mutable │ │ └── PrintAtomicVsMutable.java │ │ ├── test │ │ └── NotVisibleExceptionFactory.java │ │ └── stream │ │ └── IntStreamsTest.java ├── conf │ ├── checkstyle │ │ └── import-control.xml │ ├── pmd-ruleset.xml │ └── pmd-exclude.properties └── assembly │ ├── bin.xml │ └── src.xml ├── .mvn └── .gitignore ├── NOTICE.txt ├── .gitignore ├── SECURITY.md ├── CODE_OF_CONDUCT.md ├── .github ├── GH-ROBOTS.txt ├── dependabot.yml ├── workflows │ └── dependency-review.yml └── pull_request_template.md ├── .gitattributes └── .asf.yaml /RELEASE-NOTES.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-lang/HEAD/RELEASE-NOTES.txt -------------------------------------------------------------------------------- /src/media/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-lang/HEAD/src/media/logo.png -------------------------------------------------------------------------------- /src/site/resources/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-lang/HEAD/src/site/resources/images/logo.png -------------------------------------------------------------------------------- /src/media/commons-logo-component.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-lang/HEAD/src/media/commons-logo-component.xcf -------------------------------------------------------------------------------- /.mvn/.gitignore: -------------------------------------------------------------------------------- 1 | # 2 | # Empty file (Maven 4 wants the directory .mvn to be present, 3 | # and we want Git to create it.) 4 | # 5 | -------------------------------------------------------------------------------- /src/media/commons-logo-component-100.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-lang/HEAD/src/media/commons-logo-component-100.xcf -------------------------------------------------------------------------------- /src/site/resources/release-notes/RELEASE-NOTES-3.8.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-lang/HEAD/src/site/resources/release-notes/RELEASE-NOTES-3.8.txt -------------------------------------------------------------------------------- /src/site/resources/release-notes/RELEASE-NOTES-3.9.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-lang/HEAD/src/site/resources/release-notes/RELEASE-NOTES-3.9.txt -------------------------------------------------------------------------------- /src/site/resources/release-notes/RELEASE-NOTES-3.8.1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-lang/HEAD/src/site/resources/release-notes/RELEASE-NOTES-3.8.1.txt -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/doc-files/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-lang/HEAD/src/main/java/org/apache/commons/lang3/doc-files/logo.png -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | Apache Commons Lang 2 | Copyright 2001-2025 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (https://www.apache.org/). 6 | -------------------------------------------------------------------------------- /src/site/resources/download_lang.cgi: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Just call the standard mirrors.cgi script. It will use download.html 3 | # as the input template. 4 | exec /www/www.apache.org/dyn/mirrors/mirrors.cgi $* -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Maven build files 2 | target 3 | *.log 4 | maven-eclipse.xml 5 | build.properties 6 | site-content 7 | *~ 8 | 9 | # IntelliJ IDEA files 10 | .idea 11 | .iws 12 | *.iml 13 | *.ipr 14 | 15 | # Eclipse files 16 | .settings 17 | .classpath 18 | .project 19 | .externalToolBuilders 20 | .checkstyle 21 | 22 | # jenv's version file 23 | .java-version 24 | /.DS_Store 25 | 26 | # NetBeans files 27 | nb-configuration.xml 28 | nbactions.xml 29 | -------------------------------------------------------------------------------- /src/site/resources/profile.jacoco: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // https://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | -------------------------------------------------------------------------------- /src/site/resources/.htaccess: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | AddCharset utf-8 .txt .html 17 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 17 | The Apache Commons security page is [https://commons.apache.org/security.html](https://commons.apache.org/security.html). 18 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 17 | The Apache code of conduct page is [https://www.apache.org/foundation/policies/conduct.html](https://www.apache.org/foundation/policies/conduct.html). 18 | -------------------------------------------------------------------------------- /.github/GH-ROBOTS.txt: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # Keeps on creating FUD PRs in test code 17 | # Does not follow Apache disclosure policies 18 | User-agent: JLLeitschuh/security-research 19 | Disallow: * 20 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | # Auto detect text files and perform LF normalization 18 | * text=auto 19 | 20 | *.java text diff=java 21 | *.html text diff=html 22 | *.css text 23 | *.js text 24 | *.sql text 25 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/testbed/Grandchild.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.reflect.testbed; 18 | 19 | /** 20 | */ 21 | public class Grandchild extends AnotherChild { 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/event/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Provides some useful event-based utilities. 20 | * 21 | * @since 3.0 22 | */ 23 | package org.apache.commons.lang3.event; 24 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/testbed/AnotherChild.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.reflect.testbed; 18 | 19 | /** 20 | */ 21 | public class AnotherChild extends AnotherParent { 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/testbed/GenericConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.reflect.testbed; 18 | 19 | public interface GenericConsumer { 20 | void consume(T t); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/arch/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Provides classes to work with the values of the os.arch system property. 20 | * @since 3.6 21 | */ 22 | package org.apache.commons.lang3.arch; 23 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/util/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Provides classes that work with the Java {@link java.util} package. 20 | * 21 | * @since 3.13.0 22 | */ 23 | package org.apache.commons.lang3.util; 24 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/testbed/Bar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.reflect.testbed; 18 | 19 | /** 20 | */ 21 | public interface Bar { 22 | String VALUE = "bar"; 23 | 24 | void doIt(); 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/testbed/StaticContainerChild.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.reflect.testbed; 18 | 19 | /** 20 | */ 21 | public class StaticContainerChild extends StaticContainer { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/testbed/AnotherParent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.reflect.testbed; 18 | 19 | /** 20 | * An empty public class. 21 | */ 22 | public class AnotherParent { 23 | // keep empty. 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/tuple/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Provides tuple classes, both mutable and immutable {@link Pair} and {@link Triple}. 20 | * 21 | * @since 3.0 22 | */ 23 | package org.apache.commons.lang3.tuple; 24 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/testbed/Foo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.reflect.testbed; 18 | 19 | /** 20 | */ 21 | public interface Foo { 22 | String VALUE = "foo"; 23 | 24 | @Annotated 25 | void doIt(); 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/testbed/Ambig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.reflect.testbed; 18 | 19 | /** 20 | */ 21 | public class Ambig implements Foo, Bar { 22 | 23 | @Override 24 | public void doIt() { 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | version: 2 17 | updates: 18 | - package-ecosystem: "maven" 19 | directory: "/" 20 | schedule: 21 | interval: "quarterly" 22 | - package-ecosystem: "github-actions" 23 | directory: "/" 24 | schedule: 25 | interval: "quarterly" 26 | 27 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/compare/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Provides classes to work with the {@link Comparable} and {@link java.util.Comparator} interfaces. 20 | * 21 | * @since 3.10 22 | */ 23 | package org.apache.commons.lang3.compare; 24 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/reflect/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Provides high-level uses of the {@code java.lang.reflect} APIs. 20 | *

These classes are immutable and thread-safe.

21 | * 22 | * @since 3.0 23 | */ 24 | package org.apache.commons.lang3.reflect; 25 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/concurrent/locks/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Provides support classes for multi-threaded programming. This package is intended to be an extension to 20 | * {@link java.util.concurrent.locks}. 21 | * 22 | * @since 3.11 23 | */ 24 | package org.apache.commons.lang3.concurrent.locks; 25 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/testbed/PubliclyShadowedChild.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.reflect.testbed; 18 | 19 | /** 20 | */ 21 | public class PubliclyShadowedChild extends Parent { 22 | public String s = "ss"; 23 | public boolean b = true; 24 | public int i = 1; 25 | public double d = 1.0; 26 | } 27 | -------------------------------------------------------------------------------- /src/conf/checkstyle/import-control.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/mutable/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Provides typed mutable wrappers to primitive values and Object. 20 | * These wrappers are similar to the wrappers provided by the Java API, but allow the wrapped value to be changed without needing to create a separate wrapper object. 21 | * These classes are not thread-safe. 22 | * 23 | * @since 2.1 24 | */ 25 | package org.apache.commons.lang3.mutable; 26 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/testbed/PrivatelyShadowedChild.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.reflect.testbed; 18 | 19 | /** 20 | */ 21 | @SuppressWarnings({ "unused" }) // deliberate re-use of variable names 22 | public class PrivatelyShadowedChild extends Parent { 23 | private final String s = "ss"; 24 | private final boolean b = true; 25 | private final int i = 1; 26 | private final double d = 1.0; 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/testbed/Annotated.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.reflect.testbed; 19 | 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | @Retention(RetentionPolicy.RUNTIME) 26 | @Target({ElementType.FIELD, ElementType.METHOD}) 27 | public @interface Annotated { 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/stream/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Provides utility classes to complement those in {@link java.util.stream}. 20 | * 21 | *

Contains utilities to allow streaming of failable functional interfaces from the 22 | * {@code org.apache.commons.lang3.functions} package allowing streaming of functional expressions 23 | * that may raise an Exception. 24 | * 25 | * @since 3.11 26 | */ 27 | package org.apache.commons.lang3.stream; 28 | -------------------------------------------------------------------------------- /.github/workflows/dependency-review.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | name: 'Dependency Review' 19 | on: [pull_request] 20 | 21 | permissions: 22 | contents: read 23 | 24 | jobs: 25 | dependency-review: 26 | runs-on: ubuntu-latest 27 | steps: 28 | - name: 'Checkout Repository' 29 | uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 30 | - name: 'Dependency Review PR' 31 | uses: actions/dependency-review-action@3c4e3dcb1aa7874d2c16be7d79418e9b7efd6261 # v4.8.2 32 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/function/AnnotationTestFixture.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | @Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD }) 26 | @Retention(RetentionPolicy.RUNTIME) 27 | @interface AnnotationTestFixture { 28 | // empty 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/ByteSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.IntSupplier; 21 | 22 | /** 23 | * A functional interface like {@link IntSupplier}, but for a byte. 24 | * 25 | * @since 3.19 26 | */ 27 | @FunctionalInterface 28 | public interface ByteSupplier { 29 | 30 | /** 31 | * Supplies a byte. 32 | * 33 | * @return a result. 34 | */ 35 | byte getAsByte(); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/reflect/Typed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.reflect; 18 | 19 | import java.lang.reflect.Type; 20 | 21 | /** 22 | * Generalization of "has a type." 23 | * 24 | * @param the type 25 | * @see TypeLiteral 26 | * @since 3.2 27 | */ 28 | @FunctionalInterface 29 | public interface Typed { 30 | 31 | /** 32 | * Gets the {@link Type} represented by this entity. 33 | * 34 | * @return Type 35 | */ 36 | Type getType(); 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/Lang1703Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.reflect; 19 | 20 | import org.junit.jupiter.api.Test; 21 | 22 | /** 23 | * A top-level class is parameterised using itself. 24 | * 25 | * @param itself 26 | */ 27 | public class Lang1703Test> { 28 | 29 | @Test 30 | void testStackOverflowError() { 31 | // causes a java.lang.StackOverflowError 32 | TypeUtils.toString(Lang1703Test.class); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/testbed/GenericParent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.reflect.testbed; 18 | 19 | /** 20 | * Class declaring a parameter variable. 21 | */ 22 | public class GenericParent implements GenericConsumer { 23 | 24 | @Override 25 | public void consume(final T t) { 26 | } 27 | 28 | public void parentNotAnnotatedMethod(final T t) { 29 | } 30 | 31 | @Annotated 32 | protected void parentProtectedAnnotatedMethod(final T t) { 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/time/FastDateFormat_PrinterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.time; 18 | 19 | import java.util.Locale; 20 | import java.util.TimeZone; 21 | 22 | /** 23 | * Tests for the print methods of FastDateFormat 24 | */ 25 | class FastDateFormat_PrinterTest extends FastDatePrinterTest { 26 | 27 | @Override 28 | protected DatePrinter getInstance(final String format, final TimeZone timeZone, final Locale locale) { 29 | return FastDateFormat.getInstance(format, timeZone, locale); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/builder/DiffExclude.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.builder; 19 | 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Excludes a field from being used by the {@link ReflectionDiffBuilder}. 27 | * 28 | * @since 3.13.0 29 | */ 30 | @Retention(RetentionPolicy.RUNTIME) 31 | @Target(ElementType.FIELD) 32 | public @interface DiffExclude { 33 | // empty 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableRunnable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | /** 21 | * A functional interface like {@link Runnable} that declares a kind of {@link Throwable}. 22 | * 23 | * @param The kind of {@link Throwable}. 24 | * @since 3.11 25 | */ 26 | @FunctionalInterface 27 | public interface FailableRunnable { 28 | 29 | /** 30 | * Runs the function. 31 | * 32 | * @throws E Thrown when the function fails. 33 | */ 34 | void run() throws E; 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/builder/ToStringExclude.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.builder; 19 | 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Excludes a field from being used by the {@link ReflectionToStringBuilder}. 27 | * 28 | * @since 3.5 29 | */ 30 | @Retention(RetentionPolicy.RUNTIME) 31 | @Target(ElementType.FIELD) 32 | public @interface ToStringExclude { 33 | // empty 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/testbed/Parent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.reflect.testbed; 18 | 19 | /** 20 | */ 21 | class Parent implements Foo { 22 | 23 | public String s = "s"; 24 | protected boolean b; 25 | int i; 26 | 27 | @SuppressWarnings("unused") 28 | private final double d = 0.0; 29 | 30 | @Override 31 | public void doIt() { 32 | } 33 | 34 | public void parentNotAnnotatedMethod() { 35 | } 36 | 37 | @Annotated 38 | protected void parentProtectedAnnotatedMethod() { 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/testbed/PublicChild.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.reflect.testbed; 18 | 19 | /** 20 | */ 21 | public class PublicChild extends Parent { 22 | static final String VALUE = "child"; 23 | 24 | @Override 25 | public void parentNotAnnotatedMethod() { 26 | } 27 | 28 | @Override 29 | public void parentProtectedAnnotatedMethod() { 30 | } 31 | 32 | @Annotated 33 | private void privateAnnotatedMethod() { 34 | } 35 | 36 | @Annotated 37 | public void publicAnnotatedMethod() { 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/function/ByteSupplierTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | /** 25 | * Tests {@link ByteSupplier}. 26 | */ 27 | class ByteSupplierTest { 28 | 29 | @Test 30 | void testGetAsByte() { 31 | assertEquals(1, new ByteSupplier() { 32 | @Override 33 | public byte getAsByte() { 34 | return 1; 35 | } 36 | }.getAsByte()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/function/IntToCharFunctionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; 21 | 22 | import org.apache.commons.lang3.AbstractLangTest; 23 | import org.junit.jupiter.api.Test; 24 | 25 | /** 26 | * Tests {@link IntToCharFunction}. 27 | */ 28 | class IntToCharFunctionTest extends AbstractLangTest { 29 | 30 | @Test 31 | void test() { 32 | final IntToCharFunction func = i -> (char) i; 33 | assertEquals('A', func.applyAsChar(65)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/builder/EqualsExclude.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.builder; 19 | 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Excludes a field from being used by the various {@code reflectionEquals} methods defined on {@link EqualsBuilder}. 27 | * 28 | * @since 3.5 29 | */ 30 | @Retention(RetentionPolicy.RUNTIME) 31 | @Target(ElementType.FIELD) 32 | public @interface EqualsExclude { 33 | // empty 34 | } 35 | -------------------------------------------------------------------------------- /src/conf/pmd-ruleset.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 20 | Excludes from default PMD rules. 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/builder/HashCodeExclude.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.builder; 19 | 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Exclude a field from being used by the various {@code reflectionHashcode} methods defined on {@link HashCodeBuilder}. 27 | * 28 | * @since 3.5 29 | */ 30 | @Retention(RetentionPolicy.RUNTIME) 31 | @Target(ElementType.FIELD) 32 | public @interface HashCodeExclude { 33 | // empty 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/builder/IDKeyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.builder; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; 21 | import static org.junit.jupiter.api.Assertions.assertNotEquals; 22 | 23 | import org.junit.jupiter.api.Test; 24 | 25 | /** 26 | * Tests {@link IDKey}. 27 | */ 28 | class IDKeyTest { 29 | 30 | @Test 31 | void testEquals() { 32 | assertEquals(new IDKey("1"), new IDKey("1")); 33 | assertNotEquals(new IDKey("1"), new IDKey("2")); 34 | assertNotEquals(new IDKey("1"), "2"); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/exception/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Provides functionality for Exceptions. 20 | *

Contains the concept of an exception with context i.e. such an exception will contain a map with keys and values. 21 | * This provides an easy way to pass valuable state information at exception time in useful form to a calling process.

22 | *

Lastly, {@link org.apache.commons.lang3.exception.ExceptionUtils} also contains {@link Throwable} manipulation 23 | * and examination routines.

24 | * 25 | * @since 1.0 26 | */ 27 | package org.apache.commons.lang3.exception; 28 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/exception/UncheckedExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.exception; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertSame; 20 | 21 | import org.apache.commons.lang3.AbstractLangTest; 22 | import org.junit.jupiter.api.Test; 23 | 24 | /** 25 | * Tests {@link UncheckedException}. 26 | */ 27 | class UncheckedExceptionTest extends AbstractLangTest { 28 | 29 | @Test 30 | void testConstructWithCause() { 31 | final Exception e = new Exception(); 32 | assertSame(e, new UncheckedException(e).getCause()); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/function/ToBooleanBiFunctionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertTrue; 21 | 22 | import org.apache.commons.lang3.AbstractLangTest; 23 | import org.junit.jupiter.api.Test; 24 | 25 | /** 26 | * Tests {@link ToBooleanBiFunction}. 27 | */ 28 | class ToBooleanBiFunctionTest extends AbstractLangTest { 29 | 30 | @Test 31 | void test() { 32 | final ToBooleanBiFunction func = (t, u) -> Integer.valueOf(t).equals(u); 33 | assertTrue(func.applyAsBoolean("1", 1)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableIntSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.IntSupplier; 21 | 22 | /** 23 | * A functional interface like {@link IntSupplier} that declares a {@link Throwable}. 24 | * 25 | * @param The kind of thrown exception or error. 26 | * @since 3.11 27 | */ 28 | @FunctionalInterface 29 | public interface FailableIntSupplier { 30 | 31 | /** 32 | * Supplies an int. 33 | * 34 | * @return a result 35 | * @throws E if the supplier fails 36 | */ 37 | int getAsInt() throws E; 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Provides functional interfaces to complement those in {@code java.lang.function} and utilities for working with Java 20 | * 8 lambdas. 21 | * 22 | *

23 | * Contains failable functional interfaces that address the fact that lambdas are supposed not to throw Exceptions, at 24 | * least not checked Exceptions, A.K.A. instances of {@link Exception}. A failable functional interface 25 | * declares a type of Exception that may be raised if the function fails. 26 | *

27 | * 28 | * @since 3.11 29 | */ 30 | package org.apache.commons.lang3.function; 31 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/concurrent/UncheckedTimeoutExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.concurrent; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertSame; 20 | 21 | import org.apache.commons.lang3.AbstractLangTest; 22 | import org.junit.jupiter.api.Test; 23 | 24 | /** 25 | * Tests {@link UncheckedTimeoutException}. 26 | */ 27 | class UncheckedTimeoutExceptionTest extends AbstractLangTest { 28 | 29 | @Test 30 | void testConstructWithCause() { 31 | final Exception e = new Exception(); 32 | assertSame(e, new UncheckedTimeoutException(e).getCause()); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableLongSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.LongSupplier; 21 | 22 | /** 23 | * A functional interface like {@link LongSupplier} that declares a {@link Throwable}. 24 | * 25 | * @param The kind of thrown exception or error. 26 | * @since 3.11 27 | */ 28 | @FunctionalInterface 29 | public interface FailableLongSupplier { 30 | 31 | /** 32 | * Supplies a long. 33 | * 34 | * @return a result 35 | * @throws E if the supplier fails 36 | */ 37 | long getAsLong() throws E; 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/concurrent/UncheckedExecutionExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.concurrent; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertSame; 20 | 21 | import org.apache.commons.lang3.AbstractLangTest; 22 | import org.junit.jupiter.api.Test; 23 | 24 | /** 25 | * Tests {@link UncheckedExecutionException}. 26 | */ 27 | class UncheckedExecutionExceptionTest extends AbstractLangTest { 28 | 29 | @Test 30 | void testConstructWithCause() { 31 | final Exception e = new Exception(); 32 | assertSame(e, new UncheckedExecutionException(e).getCause()); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.builder; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | 21 | import org.apache.commons.lang3.AbstractLangTest; 22 | import org.junit.jupiter.api.Test; 23 | 24 | /** 25 | * Tests {@link ReflectionToStringBuilder}. 26 | */ 27 | class ReflectionToStringBuilderTest extends AbstractLangTest { 28 | 29 | @Test 30 | void testConstructorWithNullObject() { 31 | assertEquals("", new ReflectionToStringBuilder(null, ToStringStyle.DEFAULT_STYLE, new StringBuffer()).toString()); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/exception/UncheckedInterruptedExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.exception; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertSame; 20 | 21 | import org.apache.commons.lang3.AbstractLangTest; 22 | import org.junit.jupiter.api.Test; 23 | 24 | /** 25 | * Tests {@link UncheckedInterruptedException}. 26 | */ 27 | class UncheckedInterruptedExceptionTest extends AbstractLangTest { 28 | 29 | @Test 30 | void testConstructWithCause() { 31 | final Exception e = new Exception(); 32 | assertSame(e, new UncheckedInterruptedException(e).getCause()); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableByteSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.IntSupplier; 21 | 22 | /** 23 | * A functional interface like {@link IntSupplier}, but for a byte, that declares a {@link Throwable}. 24 | * 25 | * @param The kind of thrown exception or error. 26 | * @since 3.19 27 | */ 28 | @FunctionalInterface 29 | public interface FailableByteSupplier { 30 | 31 | /** 32 | * Supplies a byte. 33 | * 34 | * @return a result 35 | * @throws E if the supplier fails 36 | */ 37 | byte getAsByte() throws E; 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableCallable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | /** 21 | * A functional interface like {@link java.util.concurrent.Callable} that declares a {@link Throwable}. 22 | * 23 | * @param Return type. 24 | * @param The kind of thrown exception or error. 25 | * @since 3.11 26 | */ 27 | @FunctionalInterface 28 | public interface FailableCallable { 29 | 30 | /** 31 | * Calls the callable. 32 | * 33 | * @return The value returned from the callable 34 | * @throws E if the callable fails 35 | */ 36 | R call() throws E; 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableDoubleSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.DoubleSupplier; 21 | 22 | /** 23 | * A functional interface like {@link DoubleSupplier} that declares a {@link Throwable}. 24 | * 25 | * @param The kind of thrown exception or error. 26 | * @since 3.11 27 | */ 28 | @FunctionalInterface 29 | public interface FailableDoubleSupplier { 30 | 31 | /** 32 | * Supplies a double. 33 | * 34 | * @return a result 35 | * @throws E if the supplier fails 36 | */ 37 | double getAsDouble() throws E; 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/time/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Provides classes and methods to work with dates and durations. 20 | * These classes are immutable (and therefore thread-safe) apart from {@link org.apache.commons.lang3.time.StopWatch}. 21 | * 22 | *

The time package contains some basic utilities for manipulating time (a delorean, police box and grandfather clock?). 23 | * These include a {@link org.apache.commons.lang3.time.StopWatch} for simple performance measurements and an optimized {@link org.apache.commons.lang3.time.FastDateFormat} class.

24 | * 25 | * @since 2.0 26 | */ 27 | package org.apache.commons.lang3.time; 28 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/exception/UncheckedIllegalAccessExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.exception; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertSame; 20 | 21 | import org.apache.commons.lang3.AbstractLangTest; 22 | import org.junit.jupiter.api.Test; 23 | 24 | /** 25 | * Tests {@link UncheckedIllegalAccessException}. 26 | */ 27 | class UncheckedIllegalAccessExceptionTest extends AbstractLangTest { 28 | 29 | @Test 30 | void testConstructWithCause() { 31 | final Exception e = new Exception(); 32 | assertSame(e, new UncheckedIllegalAccessException(e).getCause()); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableBooleanSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.BooleanSupplier; 21 | 22 | /** 23 | * A functional interface like {@link BooleanSupplier} that declares a {@link Throwable}. 24 | * 25 | * @param The kind of thrown exception or error. 26 | * @since 3.11 27 | */ 28 | @FunctionalInterface 29 | public interface FailableBooleanSupplier { 30 | 31 | /** 32 | * Supplies a boolean. 33 | * 34 | * @return a result 35 | * @throws E if the supplier fails 36 | */ 37 | boolean getAsBoolean() throws E; 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/Lang1792Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.reflect; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | /** 25 | * Tests https://issues.apache.org/jira/browse/LANG-1792 26 | * 27 | * @param See https://issues.apache.org/jira/browse/LANG-1792 28 | */ 29 | public class Lang1792Test { 30 | 31 | @Test 32 | void testStackOverflowError() { 33 | assertEquals("org.apache.commons.lang3.reflect.Lang1792Test", TypeUtils.toString(Lang1792Test.class)); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableShortSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.IntSupplier; 21 | 22 | /** 23 | * A functional interface like {@link IntSupplier} but for {@code short} that declares a {@link Throwable}. 24 | * 25 | * @param The kind of thrown exception or error. 26 | * @since 3.12.0 27 | */ 28 | @FunctionalInterface 29 | public interface FailableShortSupplier { 30 | 31 | /** 32 | * Supplies an int. 33 | * 34 | * @return a result 35 | * @throws E if the supplier fails 36 | */ 37 | short getAsShort() throws E; 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/exception/CustomCheckedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.exception; 19 | 20 | public class CustomCheckedException extends Exception { 21 | 22 | private static final long serialVersionUID = 1L; 23 | 24 | public CustomCheckedException() { 25 | } 26 | 27 | public CustomCheckedException(final String message) { 28 | super(message); 29 | } 30 | 31 | public CustomCheckedException(final String message, final Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public CustomCheckedException(final Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /.asf.yaml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | github: 17 | description: "Apache Commons Lang" 18 | homepage: https://commons.apache.org/lang/ 19 | 20 | notifications: 21 | commits: commits@commons.apache.org 22 | issues: issues@commons.apache.org 23 | pullrequests: issues@commons.apache.org 24 | jira_options: link label 25 | jobs: notifications@commons.apache.org 26 | # commits_bot_dependabot: dependabot@commons.apache.org 27 | issues_bot_dependabot: dependabot@commons.apache.org 28 | pullrequests_bot_dependabot: dependabot@commons.apache.org 29 | issues_bot_codecov-commenter: notifications@commons.apache.org 30 | pullrequests_bot_codecov-commenter: notifications@commons.apache.org 31 | -------------------------------------------------------------------------------- /src/site/xdoc/userguide.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 22 | 23 | Commons Lang - User guide 24 | Apache Commons Team 25 | 26 | 27 | 28 | 29 |
30 |

31 | The User Guide has moved to the package Javadoc. 32 |

33 |
34 | 35 | 36 |
37 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/exception/UncheckedReflectiveOperationExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.exception; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertSame; 20 | 21 | import org.apache.commons.lang3.AbstractLangTest; 22 | import org.junit.jupiter.api.Test; 23 | 24 | /** 25 | * Tests {@link UncheckedReflectiveOperationException}. 26 | */ 27 | class UncheckedReflectiveOperationExceptionTest extends AbstractLangTest { 28 | 29 | @Test 30 | void testConstructWithCause() { 31 | final Exception e = new Exception(); 32 | assertSame(e, new UncheckedReflectiveOperationException(e).getCause()); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/exception/CustomUncheckedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.exception; 19 | 20 | public class CustomUncheckedException extends RuntimeException { 21 | 22 | private static final long serialVersionUID = 1L; 23 | 24 | public CustomUncheckedException() { 25 | } 26 | 27 | public CustomUncheckedException(final String message) { 28 | super(message); 29 | } 30 | 31 | public CustomUncheckedException(final String message, final Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public CustomUncheckedException(final Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/conf/pmd-exclude.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # We have ThreadGroup utilities 17 | org.apache.commons.lang3.ThreadUtils = AvoidThreadGroup 18 | 19 | # TODO? 20 | # violation beginline="2900" endline="2900" begincolumn="13" endcolumn="21" rule="AvoidBranchingStatementAsLastInLoop" ruleset="Error Prone" package="org.apache.commons.lang3" class="StringUtils" method="indexOfAnyBut" 21 | org.apache.commons.lang3.StringUtils = AvoidBranchingStatementAsLastInLoop 22 | 23 | # Bug in PMD when the same class name exists in different packages 24 | # Unnecessary use of fully qualified name 'org.apache.commons.lang3.function.FailableRunnable' due to existing same package import 'org.apache.commons.lang3.*' 25 | org.apache.commons.lang3.Functions = UnnecessaryFullyQualifiedName 26 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/ObjectToStringRuntimeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3; 19 | 20 | /** 21 | * An object that throws a runtime exception when you call {@link #toString()}. 22 | */ 23 | public class ObjectToStringRuntimeException { 24 | 25 | private final String message; 26 | 27 | public ObjectToStringRuntimeException(final String message) { 28 | this.message = message; 29 | } 30 | 31 | /** 32 | * Throws {@link IllegalStateException}. 33 | * 34 | * @throws IllegalStateException always thrown. 35 | */ 36 | @Override 37 | public String toString() { 38 | throw new IllegalStateException(new NullPointerException(message)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/AbstractLangTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertTrue; 20 | 21 | import org.apache.commons.lang3.builder.ToStringStyle; 22 | import org.junit.jupiter.api.AfterEach; 23 | 24 | /** 25 | * All tests subclass this test. 26 | */ 27 | public class AbstractLangTest { 28 | 29 | /** 30 | * All tests should leave the {@link ToStringStyle} registry empty. 31 | */ 32 | @AfterEach 33 | public void after() { 34 | assertTrue(ToStringStyle.getRegistry().isEmpty(), "Expected null, actual: " + ToStringStyle.getRegistry()); 35 | // TODO Do more to make sure memory is not retained, maybe like Log4j checks for it. 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/time/TimeZonesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.time; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; 21 | 22 | import java.util.TimeZone; 23 | 24 | import org.junit.jupiter.api.Test; 25 | 26 | /** 27 | * Tests {@link TimeZones}. 28 | */ 29 | class TimeZonesTest { 30 | 31 | static final String TIME_ZONE_GET_AVAILABLE_IDS = "java.util.TimeZone#getAvailableIDs()"; 32 | 33 | @Test 34 | void testToTimeZone() { 35 | assertEquals(TimeZone.getDefault(), TimeZones.toTimeZone(null)); 36 | assertEquals(TimeZone.getDefault(), TimeZones.toTimeZone(TimeZone.getDefault())); 37 | assertEquals(TimeZones.GMT, TimeZones.toTimeZone(TimeZones.GMT)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/builder/ToStringSummary.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.builder; 19 | 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Use this annotation on the fields to get the summary instead of the detailed 27 | * information when using {@link ReflectionToStringBuilder}. 28 | * 29 | *

30 | * Notice that not all {@link ToStringStyle} implementations support the 31 | * appendSummary method. 32 | *

33 | * 34 | * @since 3.8 35 | */ 36 | @Retention(RetentionPolicy.RUNTIME) 37 | @Target(ElementType.FIELD) 38 | public @interface ToStringSummary { 39 | // empty 40 | } 41 | -------------------------------------------------------------------------------- /src/site/resources/checkstyle/checkstyle-suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/exception/AbstractExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.exception; 18 | 19 | import org.apache.commons.lang3.AbstractLangTest; 20 | 21 | /** 22 | * Base class for testing {@link Exception} descendants 23 | */ 24 | public abstract class AbstractExceptionTest extends AbstractLangTest { 25 | 26 | protected static final String CAUSE_MESSAGE = "Cause message"; 27 | protected static final String EXCEPTION_MESSAGE = "Exception message"; 28 | 29 | protected static final String WRONG_EXCEPTION_MESSAGE = "Wrong exception message"; 30 | protected static final String WRONG_CAUSE_MESSAGE = "Wrong cause message"; 31 | 32 | protected Exception generateCause() { 33 | return new Exception(CAUSE_MESSAGE); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/StringUtilsValueOfTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3; 18 | 19 | import org.junit.jupiter.api.Assertions; 20 | import org.junit.jupiter.api.Test; 21 | 22 | /** 23 | * Tests {@link StringUtils}'s valueOf() methods. 24 | */ 25 | class StringUtilsValueOfTest extends AbstractLangTest { 26 | 27 | @Test 28 | void testValueOfChar() { 29 | Assertions.assertEquals("ABC", StringUtils.valueOf(new char[] {'A', 'B', 'C' })); 30 | } 31 | 32 | @Test 33 | void testValueOfCharEmpty() { 34 | Assertions.assertEquals(StringUtils.EMPTY, StringUtils.valueOf(ArrayUtils.EMPTY_CHAR_ARRAY)); 35 | } 36 | 37 | @Test 38 | void testValueOfCharNull() { 39 | Assertions.assertNull(StringUtils.valueOf(null)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableIntBinaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.IntBinaryOperator; 21 | 22 | /** 23 | * A functional interface like {@link IntBinaryOperator} that declares a {@link Throwable}. 24 | * 25 | * @param The kind of thrown exception or error. 26 | * @since 3.11 27 | */ 28 | @FunctionalInterface 29 | public interface FailableIntBinaryOperator { 30 | 31 | /** 32 | * Applies this operator to the given operands. 33 | * 34 | * @param left the first operand 35 | * @param right the second operand 36 | * @return the operator result 37 | * @throws E if the operation fails 38 | */ 39 | int applyAsInt(int left, int right) throws E; 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderSummaryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.builder; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | 21 | import org.apache.commons.lang3.AbstractLangTest; 22 | import org.junit.jupiter.api.Test; 23 | 24 | class ReflectionToStringBuilderSummaryTest extends AbstractLangTest { 25 | 26 | @SuppressWarnings("unused") 27 | private final String stringField = "string"; 28 | 29 | @ToStringSummary 30 | private final String summaryString = "summary"; 31 | 32 | @Test 33 | void testSummary() { 34 | assertEquals("[stringField=string,summaryString=]", 35 | new ReflectionToStringBuilder(this, ToStringStyle.NO_CLASS_NAME_STYLE).build()); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/exception/UncheckedInterruptedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.exception; 18 | 19 | /** 20 | * Unchecked {@link InterruptedException}. 21 | * 22 | * @since 3.13.0 23 | */ 24 | public class UncheckedInterruptedException extends UncheckedException { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | /** 29 | * Constructs an instance initialized to the given {@code cause}. 30 | * 31 | * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A {@code null} value 32 | * is permitted, and indicates that the cause is nonexistent or unknown.) 33 | */ 34 | public UncheckedInterruptedException(final Throwable cause) { 35 | super(cause); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableLongBinaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.LongBinaryOperator; 21 | 22 | /** 23 | * A functional interface like {@link LongBinaryOperator} that declares a {@link Throwable}. 24 | * 25 | * @param The kind of thrown exception or error. 26 | * @since 3.11 27 | */ 28 | @FunctionalInterface 29 | public interface FailableLongBinaryOperator { 30 | 31 | /** 32 | * Applies this operator to the given operands. 33 | * 34 | * @param left the first operand 35 | * @param right the second operand 36 | * @return the operator result 37 | * @throws E if the operation fails 38 | */ 39 | long applyAsLong(long left, long right) throws E; 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/text/translate/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Deprecated: Provides text translation routines from a set of smaller building blocks. Initially created to make it possible for the user to 20 | * customize the rules in the StringEscapeUtils class. 21 | *

22 | * These classes are immutable, and therefore thread-safe. 23 | *

24 | *

25 | * Deprecated: As of 3.6, use the Apache Commons Text 26 | * translate package. 27 | *

28 | * 29 | * @since 3.0 30 | */ 31 | package org.apache.commons.lang3.text.translate; 32 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableDoubleBinaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.DoubleBinaryOperator; 21 | 22 | /** 23 | * A functional interface like {@link DoubleBinaryOperator} that declares a {@link Throwable}. 24 | * 25 | * @param The kind of thrown exception or error. 26 | * @since 3.11 27 | */ 28 | @FunctionalInterface 29 | public interface FailableDoubleBinaryOperator { 30 | 31 | /** 32 | * Applies this operator to the given operands. 33 | * 34 | * @param left the first operand 35 | * @param right the second operand 36 | * @return the operator result 37 | * @throws E if the operation fails 38 | */ 39 | double applyAsDouble(double left, double right) throws E; 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/testbed/StringParameterizedChild.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.reflect.testbed; 18 | 19 | /** 20 | * {@link GenericParent} subclass that explicitly specifies <T> as {@link String}. 21 | */ 22 | public class StringParameterizedChild extends GenericParent { 23 | @Override 24 | public void consume(final String t) { 25 | super.consume(t); 26 | } 27 | 28 | @Override 29 | public void parentNotAnnotatedMethod(final String t) { 30 | } 31 | 32 | @Override 33 | public void parentProtectedAnnotatedMethod(final String t) { 34 | } 35 | 36 | @Annotated 37 | private void privateAnnotatedMethod(final String t) { 38 | } 39 | 40 | @Annotated 41 | public void publicAnnotatedMethod(final String t) { 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/exception/UncheckedIllegalAccessException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.exception; 19 | 20 | /** 21 | * Unchecked {@link IllegalAccessException}. 22 | * 23 | * @since 3.13.0 24 | */ 25 | public class UncheckedIllegalAccessException extends UncheckedReflectiveOperationException { 26 | 27 | private static final long serialVersionUID = 1L; 28 | 29 | /** 30 | * Constructs an instance initialized to the given {@code cause}. 31 | * 32 | * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A {@code null} value 33 | * is permitted, and indicates that the cause is nonexistent or unknown.) 34 | */ 35 | public UncheckedIllegalAccessException(final Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/exception/UncheckedReflectiveOperationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.exception; 18 | 19 | /** 20 | * Unchecked {@link ReflectiveOperationException}. 21 | * 22 | * @since 3.13.0 23 | */ 24 | public class UncheckedReflectiveOperationException extends UncheckedException { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | /** 29 | * Constructs an instance initialized to the given {@code cause}. 30 | * 31 | * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A {@code null} value 32 | * is permitted, and indicates that the cause is nonexistent or unknown.) 33 | */ 34 | public UncheckedReflectiveOperationException(final Throwable cause) { 35 | super(cause); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/function/SuppliersTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; 21 | import static org.junit.jupiter.api.Assertions.assertNull; 22 | 23 | import java.util.function.Supplier; 24 | 25 | import org.apache.commons.lang3.AbstractLangTest; 26 | import org.junit.jupiter.api.Test; 27 | 28 | /** 29 | * Tests {@link Suppliers}. 30 | */ 31 | class SuppliersTest extends AbstractLangTest { 32 | 33 | /** 34 | * Tests {@link Suppliers#get(Supplier)}. 35 | */ 36 | @Test 37 | void testGet() { 38 | assertNull(Suppliers.get(null)); 39 | assertNull(Suppliers.get(() -> null)); 40 | assertNull(Suppliers.get(Suppliers.nul())); 41 | assertEquals("foo", Suppliers.get(() -> "foo")); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/concurrent/FutureTasksTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.concurrent; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | import static org.junit.jupiter.api.Assertions.assertTrue; 21 | 22 | import java.util.concurrent.ExecutionException; 23 | import java.util.concurrent.FutureTask; 24 | 25 | import org.apache.commons.lang3.AbstractLangTest; 26 | import org.junit.jupiter.api.Test; 27 | 28 | /** 29 | * Tests {@link FutureTask}. 30 | */ 31 | class FutureTasksTest extends AbstractLangTest { 32 | 33 | @Test 34 | void testRun() throws InterruptedException, ExecutionException { 35 | final String data = "Hello"; 36 | final FutureTask f = FutureTasks.run(() -> data); 37 | assertTrue(f.isDone()); 38 | assertEquals(data, f.get()); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/PackageBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.reflect; 19 | 20 | /** 21 | * This class is designed to test the default access JVM problem workaround. The issue is that public methods of a public subclass contained in a default access 22 | * superclass are returned by reflection but an IllegalAccessException is thrown when they are invoked. 23 | *

24 | * This is the default access superclass. 25 | *

26 | */ 27 | class PackageBean { 28 | 29 | private String bar = "This is bar"; 30 | 31 | /** 32 | * Package private constructor, can only use factory method to create beans. 33 | */ 34 | PackageBean() { 35 | } 36 | 37 | public String getBar() { 38 | return this.bar; 39 | } 40 | 41 | public void setBar(final String bar) { 42 | this.bar = bar; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/IntToCharFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.Function; 21 | 22 | /** 23 | * Represents a function that accepts an int-valued argument and produces a char-valued result. This is the {@code int}-to-{@code char} primitive specialization 24 | * for {@link Function}. 25 | * 26 | *

27 | * This is a functional interface whose functional method is {@link #applyAsChar(int)}. 28 | *

29 | * 30 | * @see Function 31 | * @since 3.13.0 32 | */ 33 | @FunctionalInterface 34 | public interface IntToCharFunction { 35 | 36 | /** 37 | * Applies this function to the given argument. 38 | * 39 | * @param value the function argument. 40 | * @return the function result. 41 | */ 42 | char applyAsChar(int value); 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/exception/UncheckedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.exception; 18 | 19 | /** 20 | * Abstracts the concept of wrapping a checked exception as unchecked. 21 | *

22 | * Subclasses should only be used to wrap checked exception. 23 | *

24 | * 25 | * @since 3.13.0 26 | */ 27 | public class UncheckedException extends RuntimeException { 28 | 29 | private static final long serialVersionUID = 1L; 30 | 31 | /** 32 | * Constructs an instance initialized to the given {@code cause}. 33 | * 34 | * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A {@code null} value 35 | * is permitted, and indicates that the cause is nonexistent or unknown.) 36 | */ 37 | public UncheckedException(final Throwable cause) { 38 | super(cause); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/ToBooleanBiFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.BiFunction; 21 | 22 | /** 23 | * A function that accepts two arguments and produces a boolean result. This is the {@code boolean}-producing primitive 24 | * specialization for {@link BiFunction}. 25 | * 26 | * @param the type of the first argument to the function. 27 | * @param the type of the second argument to the function. 28 | * @see BiFunction 29 | * @since 3.12.0 30 | */ 31 | @FunctionalInterface 32 | public interface ToBooleanBiFunction { 33 | 34 | /** 35 | * Applies this function to the given arguments. 36 | * 37 | * @param t the first function argument. 38 | * @param u the second function argument. 39 | * @return the function result. 40 | */ 41 | boolean applyAsBoolean(T t, U u); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/concurrent/UncheckedTimeoutException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.concurrent; 18 | 19 | import java.util.concurrent.TimeoutException; 20 | 21 | import org.apache.commons.lang3.exception.UncheckedException; 22 | 23 | /** 24 | * Unchecked {@link TimeoutException}. 25 | * 26 | * @since 3.13.0 27 | */ 28 | public class UncheckedTimeoutException extends UncheckedException { 29 | 30 | private static final long serialVersionUID = 1L; 31 | 32 | /** 33 | * Constructs an instance initialized to the given {@code cause}. 34 | * 35 | * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A {@code null} value 36 | * is permitted, and indicates that the cause is nonexistent or unknown.) 37 | */ 38 | public UncheckedTimeoutException(final Throwable cause) { 39 | super(cause); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/testbed/PackageBeanOtherPackage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.reflect.testbed; 19 | 20 | /** 21 | * This class is designed to test the default access JVM problem workaround. The issue is that public methods of a public subclass contained in a default access 22 | * superclass are returned by reflection but an IllegalAccessException is thrown when they are invoked. 23 | *

24 | * This is the default access superclass 25 | *

26 | */ 27 | class PackageBeanOtherPackage { 28 | 29 | private String bar = "This is bar"; 30 | 31 | /** 32 | * Package private constructor, can only use factory method to create beans. 33 | */ 34 | PackageBeanOtherPackage() { 35 | } 36 | 37 | public String getBar() { 38 | return this.bar; 39 | } 40 | 41 | public void setBar(final String bar) { 42 | this.bar = bar; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/concurrent/UncheckedExecutionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.concurrent; 18 | 19 | import java.util.concurrent.ExecutionException; 20 | 21 | import org.apache.commons.lang3.exception.UncheckedException; 22 | 23 | /** 24 | * Unchecked {@link ExecutionException}. 25 | * 26 | * @since 3.13.0 27 | */ 28 | public class UncheckedExecutionException extends UncheckedException { 29 | 30 | private static final long serialVersionUID = 1L; 31 | 32 | /** 33 | * Constructs an instance initialized to the given {@code cause}. 34 | * 35 | * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A {@code null} value 36 | * is permitted, and indicates that the cause is nonexistent or unknown.) 37 | */ 38 | public UncheckedExecutionException(final Throwable cause) { 39 | super(cause); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertNull; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | /** 25 | * Tests {@link FailableSupplier}. 26 | */ 27 | class FailableSupplierTest { 28 | 29 | @Test 30 | void testNULL() throws Throwable { 31 | assertNull(FailableSupplier.NUL.get()); 32 | } 33 | 34 | @Test 35 | void testNullSupplierDefaultException() throws Exception { 36 | assertNull(FailableSupplier.nul().get()); 37 | } 38 | 39 | @Test 40 | void testNullSupplierException() throws Exception { 41 | assertNull(FailableSupplier.nul().get()); 42 | } 43 | 44 | @Test 45 | void testNullSupplierRuntimeException() { 46 | assertNull(FailableSupplier.nul().get()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/concurrent/FutureTasks.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.concurrent; 18 | 19 | import java.util.concurrent.Callable; 20 | import java.util.concurrent.FutureTask; 21 | 22 | /** 23 | * Consists of utility methods that work with {@link FutureTask}. 24 | * 25 | * @since 3.13.0 26 | */ 27 | public class FutureTasks { 28 | 29 | /** 30 | * Creates a {@link FutureTask} and runs the given {@link Callable}. 31 | * 32 | * @param The result type returned by this FutureTask's {@code get} methods. 33 | * @param callable the Callable task. 34 | * @return a new FutureTask. 35 | */ 36 | public static FutureTask run(final Callable callable) { 37 | final FutureTask futureTask = new FutureTask<>(callable); 38 | futureTask.run(); 39 | return futureTask; 40 | } 41 | 42 | private FutureTasks() { 43 | // No instances needed. 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/PublicSubBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.reflect; 19 | 20 | /** 21 | * This class is designed to test the default access JVM problem workaround. The issue is that public methods of a public subclass contained in a default access 22 | * superclass are returned by reflection but an IllegalAccessException is thrown when they are invoked. 23 | *

24 | * This is the default access superclass. 25 | *

26 | */ 27 | public class PublicSubBean extends PackageBean { 28 | 29 | /** 30 | * A directly implemented property. 31 | */ 32 | private String foo = "This is foo"; 33 | 34 | /** 35 | * Package private constructor, can only use factory method to create beans. 36 | */ 37 | public PublicSubBean() { 38 | } 39 | 40 | public String getFoo() { 41 | return this.foo; 42 | } 43 | 44 | public void setFoo(final String foo) { 45 | this.foo = foo; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/builder/Reflection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.builder; 19 | 20 | import java.lang.reflect.Field; 21 | import java.util.Objects; 22 | 23 | /** 24 | * Package-private reflection code. 25 | */ 26 | final class Reflection { 27 | 28 | /** 29 | * Delegates to {@link Field#get(Object)} and rethrows {@link IllegalAccessException} as {@link IllegalArgumentException}. 30 | * 31 | * @param field The receiver of the get call. 32 | * @param obj The argument of the get call. 33 | * @return The result of the get call. 34 | * @throws IllegalArgumentException Thrown after catching {@link IllegalAccessException}. 35 | */ 36 | static Object getUnchecked(final Field field, final Object obj) { 37 | try { 38 | return Objects.requireNonNull(field, "field").get(obj); 39 | } catch (final IllegalAccessException e) { 40 | throw new IllegalArgumentException(e); 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/mutable/PrintAtomicVsMutable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.mutable; 19 | 20 | import java.util.concurrent.atomic.AtomicInteger; 21 | 22 | import org.apache.commons.lang3.time.DurationUtils; 23 | 24 | /** 25 | * Prints out the difference time working with {@link MutableInt} and {@link AtomicInteger}. 26 | */ 27 | public class PrintAtomicVsMutable { 28 | 29 | public static void main(final String[] args) { 30 | final MutableInt mInt = new MutableInt(); 31 | final int max = 100_000_000; 32 | System.out.println("MutableInt " + DurationUtils.of(() -> { 33 | for (int i = 0; i < max; i++) { 34 | mInt.incrementAndGet(); 35 | } 36 | })); 37 | final AtomicInteger aInt = new AtomicInteger(); 38 | System.out.println("AtomicInteger " + DurationUtils.of(() -> { 39 | for (int i = 0; i < max; i++) { 40 | aInt.incrementAndGet(); 41 | } 42 | })); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/builder/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Provides classes to create consistent {@code equals(Object)}, {@code toString()}, {@code hashCode()}, and {@code compareTo(Object)} methods. 20 | * These classes are not thread-safe. 21 | * 22 | *

When you write a {@link Object#hashCode() hashCode()}, do you check Bloch's Effective Java? No? 23 | * You just hack in a quick number? 24 | * Well {@link org.apache.commons.lang3.builder.HashCodeBuilder} will save your day. 25 | * It, and its buddies ({@link org.apache.commons.lang3.builder.EqualsBuilder}, {@link org.apache.commons.lang3.builder.CompareToBuilder}, {@link org.apache.commons.lang3.builder.ToStringBuilder}), take care of the nasty bits while you focus on the important bits, like which fields will go into making up the hash code.

26 | * 27 | * @see Object#equals(Object) 28 | * @see Object#toString() 29 | * @see Object#hashCode() 30 | * @see Comparable#compareTo(Object) 31 | * @since 1.0 32 | */ 33 | package org.apache.commons.lang3.builder; 34 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/testbed/PublicSubBeanOtherPackage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.reflect.testbed; 19 | 20 | /** 21 | * This class is designed to test the default access JVM problem workaround. The issue is that public methods of a public subclass contained in a default access 22 | * superclass are returned by reflection but an IllegalAccessException is thrown when they are invoked. 23 | *

24 | * This is the default access superclass. 25 | *

26 | */ 27 | public class PublicSubBeanOtherPackage extends PackageBeanOtherPackage { 28 | 29 | /** 30 | * A directly implemented property. 31 | */ 32 | private String foo = "This is foo"; 33 | 34 | /** 35 | * Package private constructor, can only use factory method to create beans. 36 | */ 37 | public PublicSubBeanOtherPackage() { 38 | } 39 | 40 | public String getFoo() { 41 | return this.foo; 42 | } 43 | 44 | public void setFoo(final String foo) { 45 | this.foo = foo; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/NumberRange.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3; 19 | 20 | import java.util.Comparator; 21 | 22 | /** 23 | * Specializes {@link Range} for {@link Number}s. 24 | *

25 | * We only offer specializations for Integer, Long, and Double (like Java Streams). 26 | *

27 | * 28 | * @param The Number class. 29 | * @since 3.13.0 30 | */ 31 | public class NumberRange extends Range { 32 | 33 | private static final long serialVersionUID = 1L; 34 | 35 | /** 36 | * Creates an instance. 37 | * 38 | * @param number1 the first element, not null 39 | * @param number2 the second element, not null 40 | * @param comp the comparator to be used, null for natural ordering 41 | * @throws NullPointerException when element1 is null. 42 | * @throws NullPointerException when element2 is null. 43 | */ 44 | public NumberRange(final N number1, final N number2, final Comparator comp) { 45 | super(number1, number2, comp); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/builder/ConversionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.builder; 18 | 19 | import static org.apache.commons.lang3.LangAssertions.assertIllegalArgumentException; 20 | import static org.apache.commons.lang3.LangAssertions.assertNullPointerException; 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | 23 | import org.apache.commons.lang3.Conversion; 24 | import org.junit.jupiter.api.Test; 25 | 26 | class ConversionTest { 27 | 28 | @Test 29 | void testHexToByte() { 30 | assertEquals((byte) 0, Conversion.hexToByte("00", 0, (byte) 0, 0, 0)); 31 | assertEquals((byte) 0, Conversion.hexToByte("00", 0, (byte) 0, 0, 2)); 32 | } 33 | 34 | @Test 35 | void testHexToByte_IllegalArgument() { 36 | assertIllegalArgumentException(() -> Conversion.hexToByte("A0", 0, (byte) 0, 4, 2)); 37 | } 38 | 39 | @Test 40 | void testHexToByte_nullString() { 41 | assertNullPointerException(() -> Conversion.hexToByte(null, 0, (byte) 0, 0, 2)); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/text/FormatFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.text; 19 | 20 | import java.text.Format; 21 | import java.util.Locale; 22 | 23 | /** 24 | * Format factory. 25 | * 26 | * @since 2.4 27 | * @deprecated As of 3.6, use Apache Commons Text 28 | * FormatFactory. 29 | */ 30 | @Deprecated 31 | public interface FormatFactory { 32 | 33 | /** 34 | * Create or retrieve a format instance. 35 | * 36 | * @param name The format type name. 37 | * @param arguments Arguments used to create the format instance. This allows the {@link FormatFactory} to implement the "format style" concept from 38 | * {@link java.text.MessageFormat}. 39 | * @param locale The locale, may be null. 40 | * @return The format instance. 41 | */ 42 | Format getFormat(String name, String arguments, Locale locale); 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/function/MethodInvokersFailableSupplierTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; 21 | import static org.junit.jupiter.api.Assertions.assertFalse; 22 | 23 | import java.lang.reflect.Method; 24 | 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * Tests {@link MethodInvokers#asFailableSupplier(Method)}. 29 | */ 30 | class MethodInvokersFailableSupplierTest extends MethodFixtures { 31 | 32 | @Test 33 | void testSupplierStatic() throws Throwable { 34 | assertEquals(staticGetString(), MethodInvokers.asFailableSupplier(getMethodForStaticGetString()).get()); 35 | assertEquals(staticGetString(), MethodInvokers.asFailableSupplier(getMethodForStaticGetString()).get()); 36 | } 37 | 38 | @Test 39 | void testSupplierToString() throws SecurityException, ReflectiveOperationException { 40 | // Should not blow up and must return _something_ 41 | assertFalse(MethodInvokers.asFailableSupplier(getMethodForStaticGetString()).toString().isEmpty()); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/reflect/testbed/GenericTypeHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.reflect.testbed; 18 | 19 | import java.util.List; 20 | 21 | /** 22 | * Holds generic testbed types. 23 | */ 24 | @SuppressWarnings("rawtypes") 25 | public class GenericTypeHolder { 26 | public GenericParent stringParent; 27 | public GenericParent integerParent; 28 | public List foos; 29 | public GenericParent[] barParents; 30 | public List rawList; 31 | public List objectList; 32 | public List unboundList; 33 | public List superObjectList; 34 | public List stringList; 35 | public List subStringList; 36 | public List superStringList; 37 | public List[] rawListArray; 38 | public List[] objectListArray; 39 | public List[] unboundListArray; 40 | public List[] superObjectListArray; 41 | public List[] stringListArray; 42 | public List[] subStringListArray; 43 | public List[] superStringListArray; 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/concurrent/LazyInitializerSupplierTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.concurrent; 18 | 19 | import org.apache.commons.lang3.function.FailableConsumer; 20 | import org.apache.commons.lang3.function.FailableSupplier; 21 | 22 | /** 23 | * Tests {@code LazyInitializer}. 24 | */ 25 | class LazyInitializerSupplierTest extends AbstractConcurrentInitializerCloseAndExceptionsTest { 26 | 27 | /** 28 | * Creates the initializer to be tested. 29 | * 30 | * @return the initializer to be tested 31 | */ 32 | @Override 33 | protected ConcurrentInitializer createInitializer() { 34 | return LazyInitializer.builder().setInitializer(Object::new).get(); 35 | } 36 | 37 | @Override 38 | protected ConcurrentInitializer createInitializerThatThrowsException( 39 | final FailableSupplier supplier, 40 | final FailableConsumer closer) { 41 | return LazyInitializer.builder().setInitializer(supplier).setCloser(closer).get(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/concurrent/Computable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.concurrent; 18 | 19 | import org.apache.commons.lang3.function.FailableFunction; 20 | 21 | /** 22 | * Definition of an interface for a wrapper around a calculation that takes a single parameter and returns a result. 23 | * 24 | *

This interface allows for wrapping a calculation into a class so that it maybe passed around an application.

25 | * 26 | *

See also {@code FailableFunction}.

27 | * 28 | * @param the type of the input to the calculation 29 | * @param the type of the output of the calculation 30 | * @see FailableFunction 31 | * @since 3.6 32 | */ 33 | @FunctionalInterface 34 | public interface Computable { 35 | 36 | /** 37 | * This method carries out the given operation with the provided argument. 38 | * 39 | * @param arg 40 | * the argument for the calculation 41 | * @return the result of the calculation 42 | * @throws InterruptedException 43 | * thrown if the calculation is interrupted 44 | */ 45 | O compute(I arg) throws InterruptedException; 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/concurrent/AtomicInitializerSupplierTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.concurrent; 18 | 19 | import org.apache.commons.lang3.function.FailableConsumer; 20 | import org.apache.commons.lang3.function.FailableSupplier; 21 | 22 | /** 23 | * Test class for {@code AtomicInitializer}. 24 | */ 25 | class AtomicInitializerSupplierTest extends AbstractConcurrentInitializerCloseAndExceptionsTest { 26 | /** 27 | * Returns the initializer to be tested. 28 | * 29 | * @return the {@code AtomicInitializer} 30 | */ 31 | @Override 32 | protected ConcurrentInitializer createInitializer() { 33 | return AtomicInitializer.builder().setInitializer(Object::new).get(); 34 | } 35 | 36 | @Override 37 | protected ConcurrentInitializer createInitializerThatThrowsException( 38 | final FailableSupplier supplier, 39 | final FailableConsumer closer) { 40 | return AtomicInitializer.builder().setInitializer(supplier).setCloser(closer).get(); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 19 | 20 | Thanks for your contribution to [Apache Commons](https://commons.apache.org/)! Your help is appreciated! 21 | 22 | Before you push a pull request, review this list: 23 | 24 | - [ ] Read the [contribution guidelines](CONTRIBUTING.md) for this project. 25 | - [ ] Read the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) if you use Artificial Intelligence (AI). 26 | - [ ] I used AI to create any part of, or all of, this pull request. Which AI tool was used to create this pull request, and to what extent did it contribute? 27 | - [ ] Run a successful build using the default [Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command line by itself. 28 | - [ ] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice. 29 | - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. 30 | - [ ] Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process. 31 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/test/NotVisibleExceptionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.test; 18 | 19 | /** 20 | * Allows for testing an exception that is not visible to {@link org.apache.commons.lang3.exception.ExceptionUtils} 21 | */ 22 | public class NotVisibleExceptionFactory { 23 | 24 | private static final class NotVisibleException extends Exception { 25 | 26 | private static final long serialVersionUID = 1L; // avoid warning 27 | 28 | private final Throwable cause; 29 | 30 | private NotVisibleException(final Throwable cause) { 31 | this.cause = cause; 32 | } 33 | 34 | @Override 35 | public synchronized Throwable getCause() { 36 | return cause; 37 | } 38 | } 39 | 40 | /** 41 | * Create a new Exception whose getCause method returns the provided cause. 42 | * 43 | * @param cause the cause of the exception 44 | * @return a new {@link Exception} 45 | */ 46 | public static Exception createException(final Throwable cause) { 47 | return new NotVisibleException(cause); 48 | } 49 | 50 | private NotVisibleExceptionFactory() { 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/concurrent/ConcurrentRuntimeExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.concurrent; 19 | 20 | import static org.apache.commons.lang3.LangAssertions.assertIllegalArgumentException; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | /** 25 | * Tests {@link ConcurrentRuntimeException}. 26 | */ 27 | class ConcurrentRuntimeExceptionTest { 28 | 29 | /** 30 | * Tries to create a ConcurrentRuntimeException with an error as cause. 31 | */ 32 | @Test 33 | void testCauseError() { 34 | assertIllegalArgumentException(() -> new ConcurrentRuntimeException("An error", new Error())); 35 | } 36 | 37 | /** 38 | * Tries to create a ConcurrentRuntimeException with null as cause. 39 | */ 40 | @Test 41 | void testCauseNull() { 42 | assertIllegalArgumentException(() -> new ConcurrentRuntimeException(null)); 43 | } 44 | 45 | /** 46 | * Tries to create a ConcurrentRuntimeException with a runtime as cause. 47 | */ 48 | @Test 49 | void testCauseUnchecked() { 50 | assertIllegalArgumentException(() -> new ConcurrentRuntimeException(new RuntimeException())); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/function/PredicatesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertFalse; 21 | import static org.junit.jupiter.api.Assertions.assertTrue; 22 | 23 | import java.util.function.Predicate; 24 | 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * Tests {@link Predicates}. 29 | */ 30 | class PredicatesTest { 31 | 32 | @Test 33 | void testFalsePredicate() { 34 | assertFalse(Predicates.falsePredicate().test(null)); 35 | assertFalse(Predicates.falsePredicate().test(new Object())); 36 | final Predicate stringPredicate = Predicates.falsePredicate(); 37 | assertFalse(stringPredicate.test(null)); 38 | assertFalse(stringPredicate.test("")); 39 | } 40 | 41 | @Test 42 | void testTruePredicate() { 43 | assertTrue(Predicates.truePredicate().test(null)); 44 | assertTrue(Predicates.truePredicate().test(new Object())); 45 | final Predicate stringPredicate = Predicates.truePredicate(); 46 | assertTrue(stringPredicate.test(null)); 47 | assertTrue(stringPredicate.test("")); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableLongToIntFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.LongToIntFunction; 21 | 22 | /** 23 | * A functional interface like {@link LongToIntFunction} that declares a {@link Throwable}. 24 | * 25 | * @param The kind of thrown exception or error. 26 | * @since 3.11 27 | */ 28 | @FunctionalInterface 29 | public interface FailableLongToIntFunction { 30 | 31 | /** NOP singleton */ 32 | @SuppressWarnings("rawtypes") 33 | FailableLongToIntFunction NOP = t -> 0; 34 | 35 | /** 36 | * Gets the NOP singleton. 37 | * 38 | * @param The kind of thrown exception or error. 39 | * @return The NOP singleton. 40 | */ 41 | @SuppressWarnings("unchecked") 42 | static FailableLongToIntFunction nop() { 43 | return NOP; 44 | } 45 | 46 | /** 47 | * Applies this function to the given argument. 48 | * 49 | * @param value the function argument 50 | * @return the function result 51 | * @throws E Thrown when the function fails. 52 | */ 53 | int applyAsInt(long value) throws E; 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/builder/AbstractSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.builder; 19 | 20 | import org.apache.commons.lang3.function.FailableSupplier; 21 | 22 | /** 23 | * Abstracts supplying an instance of {@code T}. Use to implement the builder pattern. 24 | * 25 | * @param The type of results supplied by this supplier. 26 | * @param the type of builder. 27 | * @param The kind of thrown exception or error. 28 | * @since 3.14.0 29 | */ 30 | public abstract class AbstractSupplier, E extends Throwable> implements FailableSupplier { 31 | 32 | /** 33 | * Constructs a new instance. 34 | */ 35 | public AbstractSupplier() { 36 | // empty 37 | } 38 | 39 | /** 40 | * Returns this instance typed as the subclass type {@code B}. 41 | *

42 | * This is the same as the expression: 43 | *

44 | *
45 |      * (B) this
46 |      * 
47 | * 48 | * @return {@code this} instance typed as the subclass type {@code B}. 49 | */ 50 | @SuppressWarnings("unchecked") 51 | protected B asThis() { 52 | return (B) this; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableIntToLongFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.IntToLongFunction; 21 | 22 | /** 23 | * A functional interface like {@link IntToLongFunction} that declares a {@link Throwable}. 24 | * 25 | * @param The kind of thrown exception or error. 26 | * @since 3.11 27 | */ 28 | @FunctionalInterface 29 | public interface FailableIntToLongFunction { 30 | 31 | /** NOP singleton */ 32 | @SuppressWarnings("rawtypes") 33 | FailableIntToLongFunction NOP = t -> 0L; 34 | 35 | /** 36 | * Gets the NOP singleton. 37 | * 38 | * @param The kind of thrown exception or error. 39 | * @return The NOP singleton. 40 | */ 41 | @SuppressWarnings("unchecked") 42 | static FailableIntToLongFunction nop() { 43 | return NOP; 44 | } 45 | 46 | /** 47 | * Applies this function to the given argument. 48 | * 49 | * @param value the function argument 50 | * @return the function result 51 | * @throws E Thrown when the function fails. 52 | */ 53 | long applyAsLong(int value) throws E; 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableDoubleToIntFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.DoubleToIntFunction; 21 | 22 | /** 23 | * A functional interface like {@link DoubleToIntFunction} that declares a {@link Throwable}. 24 | * 25 | * @param The kind of thrown exception or error. 26 | * @since 3.11 27 | */ 28 | @FunctionalInterface 29 | public interface FailableDoubleToIntFunction { 30 | 31 | /** NOP singleton */ 32 | @SuppressWarnings("rawtypes") 33 | FailableDoubleToIntFunction NOP = t -> 0; 34 | 35 | /** 36 | * Gets the NOP singleton. 37 | * 38 | * @param The kind of thrown exception or error. 39 | * @return The NOP singleton. 40 | */ 41 | @SuppressWarnings("unchecked") 42 | static FailableDoubleToIntFunction nop() { 43 | return NOP; 44 | } 45 | 46 | /** 47 | * Applies this function to the given argument. 48 | * 49 | * @param value the function argument 50 | * @return the function result 51 | * @throws E Thrown when the function fails. 52 | */ 53 | int applyAsInt(double value) throws E; 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableDoubleToLongFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.DoubleToLongFunction; 21 | 22 | /** 23 | * A functional interface like {@link DoubleToLongFunction} that declares a {@link Throwable}. 24 | * 25 | * @param The kind of thrown exception or error. 26 | * @since 3.11 27 | */ 28 | @FunctionalInterface 29 | public interface FailableDoubleToLongFunction { 30 | 31 | /** NOP singleton */ 32 | @SuppressWarnings("rawtypes") 33 | FailableDoubleToLongFunction NOP = t -> 0; 34 | 35 | /** 36 | * Gets the NOP singleton. 37 | * 38 | * @param The kind of thrown exception or error. 39 | * @return The NOP singleton. 40 | */ 41 | @SuppressWarnings("unchecked") 42 | static FailableDoubleToLongFunction nop() { 43 | return NOP; 44 | } 45 | 46 | /** 47 | * Applies this function to the given argument. 48 | * 49 | * @param value the function argument 50 | * @return the function result 51 | * @throws E if the operation fails 52 | */ 53 | int applyAsLong(double value) throws E; 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableIntToDoubleFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.IntToDoubleFunction; 21 | 22 | /** 23 | * A functional interface like {@link IntToDoubleFunction} that declares a {@link Throwable}. 24 | * 25 | * @param The kind of thrown exception or error. 26 | * @since 3.11 27 | */ 28 | @FunctionalInterface 29 | public interface FailableIntToDoubleFunction { 30 | 31 | /** NOP singleton */ 32 | @SuppressWarnings("rawtypes") 33 | FailableIntToDoubleFunction NOP = t -> 0d; 34 | 35 | /** 36 | * Gets the NOP singleton. 37 | * 38 | * @param The kind of thrown exception or error. 39 | * @return The NOP singleton. 40 | */ 41 | @SuppressWarnings("unchecked") 42 | static FailableIntToDoubleFunction nop() { 43 | return NOP; 44 | } 45 | 46 | /** 47 | * Applies this function to the given argument. 48 | * 49 | * @param value the function argument 50 | * @return the function result 51 | * @throws E Thrown when the function fails. 52 | */ 53 | double applyAsDouble(int value) throws E; 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableLongToDoubleFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.LongToDoubleFunction; 21 | 22 | /** 23 | * A functional interface like {@link LongToDoubleFunction} that declares a {@link Throwable}. 24 | * 25 | * @param The kind of thrown exception or error. 26 | * @since 3.11 27 | */ 28 | @FunctionalInterface 29 | public interface FailableLongToDoubleFunction { 30 | 31 | /** NOP singleton */ 32 | @SuppressWarnings("rawtypes") 33 | FailableLongToDoubleFunction NOP = t -> 0d; 34 | 35 | /** 36 | * Gets the NOP singleton. 37 | * 38 | * @param The kind of thrown exception or error. 39 | * @return The NOP singleton. 40 | */ 41 | @SuppressWarnings("unchecked") 42 | static FailableLongToDoubleFunction nop() { 43 | return NOP; 44 | } 45 | 46 | /** 47 | * Applies this function to the given argument. 48 | * 49 | * @param value the function argument 50 | * @return the function result 51 | * @throws E Thrown when the function fails. 52 | */ 53 | double applyAsDouble(long value) throws E; 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/stream/IntStreamsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.stream; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertArrayEquals; 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | import static org.junit.jupiter.api.Assertions.assertNotNull; 23 | 24 | import org.apache.commons.lang3.AbstractLangTest; 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * Tests {@link IntStreams}. 29 | */ 30 | class IntStreamsTest extends AbstractLangTest { 31 | 32 | @SuppressWarnings("deprecation") 33 | @Test 34 | void testDeprecatedConstructor() { 35 | assertNotNull(new IntStreams().toString()); 36 | } 37 | 38 | @Test 39 | void testOfArray() { 40 | assertEquals(0, IntStreams.of((int[]) null).count()); 41 | assertEquals(1, IntStreams.of(1).count()); 42 | assertEquals(2, IntStreams.of(1, 2).count()); 43 | } 44 | 45 | @Test 46 | void testRange() { 47 | assertArrayEquals(new int[] { 0, 1 }, IntStreams.range(2).toArray()); 48 | } 49 | 50 | @Test 51 | void testRangeClosed() { 52 | assertArrayEquals(new int[] { 0, 1, 2 }, IntStreams.rangeClosed(2).toArray()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableIntFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.IntFunction; 21 | 22 | /** 23 | * A functional interface like {@link IntFunction} that declares a {@link Throwable}. 24 | * 25 | * @param Return type. 26 | * @param The kind of thrown exception or error. 27 | * @since 3.11 28 | */ 29 | @FunctionalInterface 30 | public interface FailableIntFunction { 31 | 32 | /** NOP singleton */ 33 | @SuppressWarnings("rawtypes") 34 | FailableIntFunction NOP = t -> null; 35 | 36 | /** 37 | * Gets the NOP singleton. 38 | * 39 | * @param Return type. 40 | * @param The kind of thrown exception or error. 41 | * @return The NOP singleton. 42 | */ 43 | @SuppressWarnings("unchecked") 44 | static FailableIntFunction nop() { 45 | return NOP; 46 | } 47 | 48 | /** 49 | * Applies this function. 50 | * 51 | * @param input the input for the function 52 | * @return the result of the function 53 | * @throws E Thrown when the function fails. 54 | */ 55 | R apply(int input) throws E; 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableLongFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.LongFunction; 21 | 22 | /** 23 | * A functional interface like {@link LongFunction} that declares a {@link Throwable}. 24 | * 25 | * @param Return type. 26 | * @param The kind of thrown exception or error. 27 | * @since 3.11 28 | */ 29 | @FunctionalInterface 30 | public interface FailableLongFunction { 31 | 32 | /** NOP singleton */ 33 | @SuppressWarnings("rawtypes") 34 | FailableLongFunction NOP = t -> null; 35 | 36 | /** 37 | * Gets the NOP singleton. 38 | * 39 | * @param Return type. 40 | * @param The kind of thrown exception or error. 41 | * @return The NOP singleton. 42 | */ 43 | @SuppressWarnings("unchecked") 44 | static FailableLongFunction nop() { 45 | return NOP; 46 | } 47 | 48 | /** 49 | * Applies this function. 50 | * 51 | * @param input the input for the function 52 | * @return the result of the function 53 | * @throws E Thrown when the function fails. 54 | */ 55 | R apply(long input) throws E; 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/exception/CloneFailedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.exception; 18 | 19 | /** 20 | * Exception thrown when a clone cannot be created. In contrast to 21 | * {@link CloneNotSupportedException} this is a {@link RuntimeException}. 22 | * 23 | * @since 3.0 24 | */ 25 | public class CloneFailedException extends RuntimeException { 26 | 27 | private static final long serialVersionUID = 20091223L; 28 | 29 | /** 30 | * Constructs a CloneFailedException. 31 | * 32 | * @param message description of the exception 33 | */ 34 | public CloneFailedException(final String message) { 35 | super(message); 36 | } 37 | 38 | /** 39 | * Constructs a CloneFailedException. 40 | * 41 | * @param message description of the exception 42 | * @param cause cause of the exception 43 | */ 44 | public CloneFailedException(final String message, final Throwable cause) { 45 | super(message, cause); 46 | } 47 | 48 | /** 49 | * Constructs a CloneFailedException. 50 | * 51 | * @param cause cause of the exception 52 | */ 53 | public CloneFailedException(final Throwable cause) { 54 | super(cause); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableIntToFloatFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.IntToDoubleFunction; 21 | 22 | /** 23 | * A functional interface like {@link IntToDoubleFunction} but for {@code float} that declares a {@link Throwable}. 24 | * 25 | * @param The kind of thrown exception or error. 26 | * @since 3.18.0 27 | */ 28 | @FunctionalInterface 29 | public interface FailableIntToFloatFunction { 30 | 31 | /** NOP singleton */ 32 | @SuppressWarnings("rawtypes") 33 | FailableIntToFloatFunction NOP = t -> 0f; 34 | 35 | /** 36 | * Gets the NOP singleton. 37 | * 38 | * @param The kind of thrown exception or error. 39 | * @return The NOP singleton. 40 | */ 41 | @SuppressWarnings("unchecked") 42 | static FailableIntToFloatFunction nop() { 43 | return NOP; 44 | } 45 | 46 | /** 47 | * Applies this function to the given argument. 48 | * 49 | * @param value the function argument 50 | * @return the function result 51 | * @throws E Thrown when the function fails. 52 | */ 53 | float applyAsFloat(int value) throws E; 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableDoubleFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.DoubleFunction; 21 | 22 | /** 23 | * A functional interface like {@link DoubleFunction} that declares a {@link Throwable}. 24 | * 25 | * @param Return type. 26 | * @param The kind of thrown exception or error. 27 | * @since 3.11 28 | */ 29 | @FunctionalInterface 30 | public interface FailableDoubleFunction { 31 | 32 | /** NOP singleton */ 33 | @SuppressWarnings("rawtypes") 34 | FailableDoubleFunction NOP = t -> null; 35 | 36 | /** 37 | * Gets the NOP singleton. 38 | * 39 | * @param Return type. 40 | * @param The kind of thrown exception or error. 41 | * @return The NOP singleton. 42 | */ 43 | @SuppressWarnings("unchecked") 44 | static FailableDoubleFunction nop() { 45 | return NOP; 46 | } 47 | 48 | /** 49 | * Applies this function. 50 | * 51 | * @param input the input for the function 52 | * @return the result of the function 53 | * @throws E Thrown when the function fails. 54 | */ 55 | R apply(double input) throws E; 56 | } 57 | -------------------------------------------------------------------------------- /src/assembly/bin.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | bin 21 | 22 | tar.gz 23 | zip 24 | 25 | false 26 | 27 | 28 | 29 | LICENSE.txt 30 | NOTICE.txt 31 | RELEASE-NOTES.txt 32 | README.md 33 | CONTRIBUTING.md 34 | 35 | 36 | 37 | target 38 | 39 | 40 | *.jar 41 | 42 | 644 43 | 44 | 45 | target/site/apidocs 46 | apidocs 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/assembly/src.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | src 21 | 22 | tar.gz 23 | zip 24 | 25 | ${project.artifactId}-${commons.release.version}-src 26 | 27 | 28 | 29 | .travis.yml 30 | checkstyle.xml 31 | checkstyle-suppressions.xml 32 | spotbugs-exclude-filter.xml 33 | LICENSE.txt 34 | NOTICE.txt 35 | pom.xml 36 | PROPOSAL.html 37 | RELEASE-NOTES.txt 38 | README.md 39 | CONTRIBUTING.md 40 | 41 | 42 | 43 | src 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableToBooleanFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | /** 21 | * A functional interface like a {@code ToBooleanFunction} that declares a {@link Throwable}. 22 | * 23 | * @param the type of the argument to the function 24 | * @param The kind of thrown exception or error. 25 | * @since 3.18 26 | */ 27 | @FunctionalInterface 28 | public interface FailableToBooleanFunction { 29 | 30 | /** NOP singleton */ 31 | @SuppressWarnings("rawtypes") 32 | FailableToBooleanFunction NOP = t -> false; 33 | 34 | /** 35 | * Gets the NOP singleton. 36 | * 37 | * @param the type of the argument to the function 38 | * @param The kind of thrown exception or error. 39 | * @return The NOP singleton. 40 | */ 41 | @SuppressWarnings("unchecked") 42 | static FailableToBooleanFunction nop() { 43 | return NOP; 44 | } 45 | 46 | /** 47 | * Applies this function to the given arguments. 48 | * 49 | * @param t the first function argument 50 | * @return the function result 51 | * @throws E Thrown when the function fails. 52 | */ 53 | boolean applyAsBoolean(T t) throws E; 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/concurrent/LazyInitializerAnonClassTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.lang3.concurrent; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertFalse; 20 | import static org.junit.jupiter.api.Assertions.assertTrue; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | /** 25 | * Tests {@code LazyInitializer}. 26 | */ 27 | class LazyInitializerAnonClassTest extends AbstractConcurrentInitializerTest { 28 | 29 | /** 30 | * Creates the initializer to be tested. This implementation returns the {@code LazyInitializer} created in the {@code setUp()} method. 31 | * 32 | * @return the initializer to be tested 33 | */ 34 | @Override 35 | protected LazyInitializer createInitializer() { 36 | return new LazyInitializer() { 37 | @Override 38 | protected Object initialize() { 39 | return new Object(); 40 | } 41 | }; 42 | } 43 | 44 | @Test 45 | void testIsInitialized() throws ConcurrentException { 46 | final LazyInitializer initializer = createInitializer(); 47 | assertFalse(initializer.isInitialized()); 48 | initializer.get(); 49 | assertTrue(initializer.isInitialized()); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/lang3/function/MethodInvokersSupplierTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; 21 | import static org.junit.jupiter.api.Assertions.assertFalse; 22 | 23 | import java.lang.reflect.Method; 24 | import java.util.function.Supplier; 25 | 26 | import org.junit.jupiter.api.Test; 27 | 28 | /** 29 | * Tests {@link MethodInvokers#asSupplier(Method)}. 30 | */ 31 | class MethodInvokersSupplierTest extends MethodFixtures { 32 | 33 | @Test 34 | void testSupplierStaticGetMethod() throws NoSuchMethodException, SecurityException { 35 | final Supplier supplier = MethodInvokers.asSupplier(getMethodForStaticGetString()); 36 | assertEquals(staticGetString(), supplier.get()); 37 | assertEquals(staticGetString(), supplier.get()); 38 | } 39 | 40 | @Test 41 | void testSupplierStaticGetMethodToString() throws SecurityException, ReflectiveOperationException { 42 | // Should not blow up and must return _something_ 43 | final Supplier supplier = MethodInvokers.asSupplier(getMethodForStaticGetString()); 44 | assertFalse(supplier.toString().isEmpty()); 45 | assertFalse(supplier.toString().isEmpty()); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/function/FailableToIntFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.lang3.function; 19 | 20 | import java.util.function.ToIntFunction; 21 | 22 | /** 23 | * A functional interface like {@link ToIntFunction} that declares a {@link Throwable}. 24 | * 25 | * @param the type of the argument to the function 26 | * @param The kind of thrown exception or error. 27 | * @since 3.11 28 | */ 29 | @FunctionalInterface 30 | public interface FailableToIntFunction { 31 | 32 | /** NOP singleton */ 33 | @SuppressWarnings("rawtypes") 34 | FailableToIntFunction NOP = t -> 0; 35 | 36 | /** 37 | * Gets the NOP singleton. 38 | * 39 | * @param the type of the argument to the function 40 | * @param The kind of thrown exception or error. 41 | * @return The NOP singleton. 42 | */ 43 | @SuppressWarnings("unchecked") 44 | static FailableToIntFunction nop() { 45 | return NOP; 46 | } 47 | 48 | /** 49 | * Applies this function to the given arguments. 50 | * 51 | * @param t the first function argument 52 | * @return the function result 53 | * @throws E Thrown when the function fails. 54 | */ 55 | int applyAsInt(T t) throws E; 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/lang3/text/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Deprecated: Provides classes for handling and manipulating text, partly as an extension to {@link java.text}. The classes in this package 20 | * are, for the most part, intended to be instantiated (i.e. they are not utility classes with lots of static methods). 21 | * 22 | *

23 | * Amongst other classes, the text package provides a replacement for {@link StringBuffer} named {@link org.apache.commons.lang3.text.StrBuilder}, a class for 24 | * substituting variables within a String named {@link org.apache.commons.lang3.text.StrSubstitutor} and a replacement for {@link java.util.StringTokenizer} 25 | * named {@link org.apache.commons.lang3.text.StrTokenizer}. While somewhat ungainly, the {@code Str} prefix has been used to ensure we don't clash with any 26 | * current or future standard Java classes. 27 | *

28 | *

29 | * Deprecated: As of 3.6, use the Apache Commons Text 30 | * text package. 31 | *

32 | * 33 | * @since 2.1 34 | */ 35 | package org.apache.commons.lang3.text; 36 | --------------------------------------------------------------------------------