Add IntToIntFunction
This commit is contained in:
parent
accde3be23
commit
120d3489aa
|
@ -216,6 +216,7 @@ The <action> type attribute can be add,update,fix,remove.
|
|||
<action issue="LANG-1647" type="add" dev="ggregory" due-to="Arturo Bernal, Dimitrios Efthymiou, Gary Gregory">Add and ExceptionUtils.isChecked() and isUnchecked() #1069</action>
|
||||
<action type="add" dev="ggregory" due-to="Gary Gregory">Add and use ExceptionUtils.throwUnchecked(throwable).</action>
|
||||
<action type="add" dev="ggregory" due-to="Gary Gregory">Add LockingVisitors.create(O, ReadWriteLock).</action>
|
||||
<action type="add" dev="ggregory" due-to="Gary Gregory">Add IntToIntFunction.</action>
|
||||
<!-- UPDATE -->
|
||||
<action type="update" dev="ggregory" due-to="Dependabot, XenoAmess, Gary Gregory">Bump actions/cache from 2.1.4 to 3.0.10 #742, #752, #764, #833, #867, #959, #964.</action>
|
||||
<action type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump actions/checkout from 2 to 3.1.0 #819, #825, #859, #963.</action>
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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 an int-valued result. This is the {@code int}-to-{@code int} primitive specialization
|
||||
* for {@link Function}.
|
||||
*
|
||||
* <p>
|
||||
* This is a <a href="package-summary.html">functional interface</a> whose functional method is {@link #applyAsInt(int)}.
|
||||
* </p>
|
||||
*
|
||||
* @see Function
|
||||
* @since 3.13.0
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface IntToIntFunction {
|
||||
|
||||
/**
|
||||
* Returns a function that always returns its input argument.
|
||||
*
|
||||
* @return a function that always returns its input argument
|
||||
*/
|
||||
static IntToIntFunction identity() {
|
||||
return i -> i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this function to the given argument.
|
||||
*
|
||||
* @param value the function argument
|
||||
* @return the function result
|
||||
*/
|
||||
int applyAsInt(int value);
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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.apache.commons.lang3.AbstractLangTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link IntToIntFunction}.
|
||||
*/
|
||||
public class IntToIntFunctionTest extends AbstractLangTest {
|
||||
|
||||
@Test
|
||||
public void testApply() {
|
||||
final IntToIntFunction func = i -> i + 1;
|
||||
assertEquals(66, func.applyAsInt(65));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIdentity() {
|
||||
assertEquals(65, IntToIntFunction.identity().applyAsInt(65));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue