001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * https://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.lang3.stream; 018 019import java.util.stream.IntStream; 020 021/** 022 * Factory for {@link IntStream}. 023 * <p> 024 * <small> Only a factory for now but could hold other functionality.</small> 025 * </p> 026 * 027 * @since 3.13.0 028 */ 029public class IntStreams { 030 031 /** 032 * Null-safe version of {@link IntStream#of(int[])}. 033 * 034 * @param values the elements of the new stream, may be {@code null}. 035 * @return the new stream on {@code values} or {@link IntStream#empty()}. 036 * @since 3.18.0 037 */ 038 @SafeVarargs // Creating a stream from an array is safe 039 public static IntStream of(final int... values) { 040 return values == null ? IntStream.empty() : IntStream.of(values); 041 } 042 043 /** 044 * Shorthand for {@code IntStream.range(0, i)}. 045 * 046 * @param endExclusive the exclusive upper bound. 047 * @return a sequential {@link IntStream} for the range of {@code int} elements. 048 */ 049 public static IntStream range(final int endExclusive) { 050 return IntStream.range(0, endExclusive); 051 } 052 053 /** 054 * Shorthand for {@code IntStream.rangeClosed(0, i)}. 055 * 056 * @param endInclusive the inclusive upper bound. 057 * @return a sequential {@link IntStream} for the range of {@code int} elements. 058 */ 059 public static IntStream rangeClosed(final int endInclusive) { 060 return IntStream.rangeClosed(0, endInclusive); 061 } 062 063 /** 064 * Make private in 4.0. 065 * 066 * @deprecated TODO Make private in 4.0. 067 */ 068 @Deprecated 069 public IntStreams() { 070 // empty 071 } 072}