From 3f9422aec44c31536d101e8088112d27ded5c1d7 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 27 Aug 2021 11:16:49 -0400 Subject: [PATCH] Add IntToCharFunction. --- src/changes/changes.xml | 1 + .../lang3/function/IntToCharFunction.java | 44 +++++++++++++++++++ .../lang3/function/IntToCharFunctionTest.java | 34 ++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 src/main/java/org/apache/commons/lang3/function/IntToCharFunction.java create mode 100644 src/test/java/org/apache/commons/lang3/function/IntToCharFunctionTest.java diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 4b0e27db3..d6818399d 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -71,6 +71,7 @@ The type attribute can be add,update,fix,remove. Add and use ArrayUtils.setAll(T[], IntFunction). Add and use ArrayUtils.setAll(T[], Supplier). Add BooleanConsumer. + Add IntToCharFunction. Bump spotbugs-maven-plugin from 4.2.0 to 4.2.3 #735. Bump Bump actions/cache from v2.1.4 to v2.1.6 #742, #752, #764. 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 000000000..f3da38451 --- /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}. + * + *

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

+ * + * @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 000000000..63bb53ea1 --- /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)); + } +}