You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/08/27 15:16:53 UTC

[commons-lang] branch master updated: Add IntToCharFunction.

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git


The following commit(s) were added to refs/heads/master by this push:
     new 3f9422a  Add IntToCharFunction.
3f9422a is described below

commit 3f9422aec44c31536d101e8088112d27ded5c1d7
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Aug 27 11:16:49 2021 -0400

    Add IntToCharFunction.
---
 src/changes/changes.xml                            |  1 +
 .../commons/lang3/function/IntToCharFunction.java  | 44 ++++++++++++++++++++++
 .../lang3/function/IntToCharFunctionTest.java      | 34 +++++++++++++++++
 3 files changed, 79 insertions(+)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 4b0e27d..d681839 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -71,6 +71,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add and use ArrayUtils.setAll(T[], IntFunction).</action>
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add and use ArrayUtils.setAll(T[], Supplier).</action>
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add BooleanConsumer.</action>
+    <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add IntToCharFunction.</action>
     <!-- UPDATE -->
     <action                   type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump spotbugs-maven-plugin from 4.2.0 to 4.2.3 #735.</action>
     <action                   type="update" dev="ggregory" due-to="Dependabot, XenoAmess">Bump Bump actions/cache from v2.1.4 to v2.1.6 #742, #752, #764.</action>
diff --git a/src/main/java/org/apache/commons/lang3/function/IntToCharFunction.java b/src/main/java/org/apache/commons/lang3/function/IntToCharFunction.java
new file mode 100644
index 0000000..f3da384
--- /dev/null
+++ b/src/main/java/org/apache/commons/lang3/function/IntToCharFunction.java
@@ -0,0 +1,44 @@
+/*
+ * 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.Function;
+
+/**
+ * Represents a function that accepts an int-valued argument and produces a long-valued result. This is the
+ * {@code int}-to-{@code long} primitive specialization for {@link Function}.
+ *
+ * <p>
+ * This is a <a href="package-summary.html">functional interface</a> whose functional method is
+ * {@link #applyAsChar(int)}.
+ * </p>
+ *
+ * @see Function
+ * @since 3.13.0
+ */
+@FunctionalInterface
+public interface IntToCharFunction {
+
+    /**
+     * Applies this function to the given argument.
+     *
+     * @param value the function argument.
+     * @return the function result.
+     */
+    char applyAsChar(int value);
+}
diff --git a/src/test/java/org/apache/commons/lang3/function/IntToCharFunctionTest.java b/src/test/java/org/apache/commons/lang3/function/IntToCharFunctionTest.java
new file mode 100644
index 0000000..63bb53e
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/function/IntToCharFunctionTest.java
@@ -0,0 +1,34 @@
+/*
+ * 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 static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link IntToCharFunction}.
+ */
+public class IntToCharFunctionTest {
+
+    @Test
+    public void test() {
+        final IntToCharFunction func = i -> (char) i;
+        assertEquals('A', func.applyAsChar(65));
+    }
+}