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
commit e56ce0fedb4cfbd2a39f956f2e8074d5aa16e000 Author: Gary D. Gregory <[email protected]> AuthorDate: Tue Sep 9 16:37:29 2025 -0700 Add ByteSupplier --- src/changes/changes.xml | 1 + .../commons/lang3/function/ByteSupplier.java | 36 ++++++++++++++++++++ .../commons/lang3/function/ByteSupplierTest.java | 38 ++++++++++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index fb8fa75a7..292cb016d 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -85,6 +85,7 @@ The <action> type attribute can be add,update,fix,remove. <action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.lang3.time.DateUtils.toOffsetDateTime(Date[, TimeZone]).</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.lang3.time.DateUtils.toZonedDateTime(Date[, TimeZone]).</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add ByteConsumer.</action> + <action type="add" dev="ggregory" due-to="Gary Gregory">Add ByteSupplier.</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add FailableByteConsumer.</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add FailableByteSupplier.</action> <!-- UPDATE --> diff --git a/src/main/java/org/apache/commons/lang3/function/ByteSupplier.java b/src/main/java/org/apache/commons/lang3/function/ByteSupplier.java new file mode 100644 index 000000000..22eb4ef92 --- /dev/null +++ b/src/main/java/org/apache/commons/lang3/function/ByteSupplier.java @@ -0,0 +1,36 @@ +/* + * 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 + * + * https://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 a byte. + * + * @since 3.19 + */ +@FunctionalInterface +public interface ByteSupplier { + + /** + * Supplies a byte. + * + * @return a result. + */ + byte getAsByte(); +} diff --git a/src/test/java/org/apache/commons/lang3/function/ByteSupplierTest.java b/src/test/java/org/apache/commons/lang3/function/ByteSupplierTest.java new file mode 100644 index 000000000..b520a49fa --- /dev/null +++ b/src/test/java/org/apache/commons/lang3/function/ByteSupplierTest.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 + * + * https://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 ByteSupplier}. + */ +class ByteSupplierTest { + + @Test + void testGetAsByte() { + assertEquals(1, new ByteSupplier() { + @Override + public byte getAsByte() { + return 1; + } + }.getAsByte()); + } +}
