aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/apache/commons/lang3/function
diff options
context:
space:
mode:
authorGary Gregory <garydgregory@gmail.com>2020-12-24 10:02:37 -0500
committerGary Gregory <garydgregory@gmail.com>2020-12-24 10:02:37 -0500
commit45bec219d2e039e85e71711e01d4543a85c1756b (patch)
tree4b045a81c1b7704ed102736e8d470c5d1daf09fc /src/main/java/org/apache/commons/lang3/function
parentb5bb3e6d3a4ea3b6908e858bbbfbe30931ff3583 (diff)
downloadapache-commons-lang-45bec219d2e039e85e71711e01d4543a85c1756b.tar.gz
Add FailableShortSupplier, handy for JDBC APIs.
Diffstat (limited to 'src/main/java/org/apache/commons/lang3/function')
-rw-r--r--src/main/java/org/apache/commons/lang3/function/Failable.java21
-rw-r--r--src/main/java/org/apache/commons/lang3/function/FailableShortSupplier.java38
2 files changed, 56 insertions, 3 deletions
diff --git a/src/main/java/org/apache/commons/lang3/function/Failable.java b/src/main/java/org/apache/commons/lang3/function/Failable.java
index 04e128e40..164f6aad9 100644
--- a/src/main/java/org/apache/commons/lang3/function/Failable.java
+++ b/src/main/java/org/apache/commons/lang3/function/Failable.java
@@ -324,7 +324,7 @@ public class Failable {
*
* @param supplier The double supplier to invoke.
* @param <E> The type of checked exception, which the supplier can throw.
- * @return The boolean, which has been created by the supplier
+ * @return The double, which has been created by the supplier
*/
public static <E extends Throwable> double getAsDouble(final FailableDoubleSupplier<E> supplier) {
try {
@@ -339,7 +339,7 @@ public class Failable {
*
* @param supplier The int supplier to invoke.
* @param <E> The type of checked exception, which the supplier can throw.
- * @return The boolean, which has been created by the supplier
+ * @return The int, which has been created by the supplier
*/
public static <E extends Throwable> int getAsInt(final FailableIntSupplier<E> supplier) {
try {
@@ -354,7 +354,7 @@ public class Failable {
*
* @param supplier The long supplier to invoke.
* @param <E> The type of checked exception, which the supplier can throw.
- * @return The boolean, which has been created by the supplier
+ * @return The long, which has been created by the supplier
*/
public static <E extends Throwable> long getAsLong(final FailableLongSupplier<E> supplier) {
try {
@@ -365,6 +365,21 @@ public class Failable {
}
/**
+ * Invokes a short supplier, and returns the result.
+ *
+ * @param supplier The short supplier to invoke.
+ * @param <E> The type of checked exception, which the supplier can throw.
+ * @return The short, which has been created by the supplier
+ */
+ public static <E extends Throwable> short getAsShort(final FailableShortSupplier<E> supplier) {
+ try {
+ return supplier.getAsShort();
+ } catch (final Throwable t) {
+ throw rethrow(t);
+ }
+ }
+
+ /**
* <p>
* Rethrows a {@link Throwable} as an unchecked exception. If the argument is already unchecked, namely a
* {@code RuntimeException} or {@code Error} then the argument will be rethrown without modification. If the
diff --git a/src/main/java/org/apache/commons/lang3/function/FailableShortSupplier.java b/src/main/java/org/apache/commons/lang3/function/FailableShortSupplier.java
new file mode 100644
index 000000000..f27cf3430
--- /dev/null
+++ b/src/main/java/org/apache/commons/lang3/function/FailableShortSupplier.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import java.util.function.IntSupplier;
+
+/**
+ * A functional interface like {@link IntSupplier} but for {@code short} that declares a {@code Throwable}.
+ *
+ * @param <E> Thrown exception.
+ * @since 3.12
+ */
+@FunctionalInterface
+public interface FailableShortSupplier<E extends Throwable> {
+
+ /**
+ * Supplies an int.
+ *
+ * @return a result
+ * @throws E if the supplier fails
+ */
+ short getAsShort() throws E;
+}