Add IntStreams.
This commit is contained in:
parent
3f9422aec4
commit
94ffa01a03
|
@ -72,6 +72,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[], Supplier).</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 BooleanConsumer.</action>
|
||||||
<action type="add" dev="ggregory" due-to="Gary Gregory">Add IntToCharFunction.</action>
|
<action type="add" dev="ggregory" due-to="Gary Gregory">Add IntToCharFunction.</action>
|
||||||
|
<action type="add" dev="ggregory" due-to="Gary Gregory">Add IntStreams.</action>
|
||||||
<!-- UPDATE -->
|
<!-- 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, 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>
|
<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>
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* 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.stream;
|
||||||
|
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory for {@link IntStream}.
|
||||||
|
* <p>
|
||||||
|
* <small> Only a factory for now but could hold other functionality.</small>
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @since 3.13.0
|
||||||
|
*/
|
||||||
|
public class IntStreams {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shorthand for {@code IntStream.range(0, i)}.
|
||||||
|
*
|
||||||
|
* @param endExclusive the exclusive upper bound.
|
||||||
|
* @return a sequential {@code IntStream} for the range of {@code int} elements.
|
||||||
|
*/
|
||||||
|
public static IntStream range(final int endExclusive) {
|
||||||
|
return IntStream.range(0, endExclusive);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shorthand for {@code IntStream.rangeClosed(0, i)}.
|
||||||
|
*
|
||||||
|
* @param endInclusive the inclusive upper bound.
|
||||||
|
* @return a sequential {@code IntStream} for the range of {@code int} elements.
|
||||||
|
*/
|
||||||
|
public static IntStream rangeClosed(final int endInclusive) {
|
||||||
|
return IntStream.rangeClosed(0, endInclusive);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* 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.stream;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests {@link IntStreams}.
|
||||||
|
*/
|
||||||
|
public class IntStreamsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRange() {
|
||||||
|
assertArrayEquals(new int[] {0, 1}, IntStreams.range(2).toArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRangeClosed() {
|
||||||
|
assertArrayEquals(new int[] {0, 1, 2}, IntStreams.rangeClosed(2).toArray());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue