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 *      http://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 */
017
018package org.apache.commons.lang3;
019
020import java.util.Arrays;
021
022/**
023 * Fills and returns arrays in the fluent style.
024 *
025 * @since 3.14.0
026 */
027public final class ArrayFill {
028
029    /**
030     * Fills and returns the given array.
031     *
032     * @param a   the array to be filled.
033     * @param val the value to be stored in all elements of the array.
034     * @return the given array.
035     * @see Arrays#fill(byte[],byte)
036     */
037    public static byte[] fill(final byte[] a, final byte val) {
038        Arrays.fill(a, val);
039        return a;
040    }
041
042    /**
043     * Fills and returns the given array.
044     *
045     * @param a   the array to be filled.
046     * @param val the value to be stored in all elements of the array.
047     * @return the given array.
048     * @see Arrays#fill(char[],char)
049     */
050    public static char[] fill(final char[] a, final char val) {
051        Arrays.fill(a, val);
052        return a;
053    }
054
055    /**
056     * Fills and returns the given array.
057     *
058     * @param a   the array to be filled.
059     * @param val the value to be stored in all elements of the array.
060     * @return the given array.
061     * @see Arrays#fill(double[],double)
062     */
063    public static double[] fill(final double[] a, final double val) {
064        Arrays.fill(a, val);
065        return a;
066    }
067
068    /**
069     * Fills and returns the given array.
070     *
071     * @param a   the array to be filled.
072     * @param val the value to be stored in all elements of the array.
073     * @return the given array.
074     * @see Arrays#fill(float[],float)
075     */
076    public static float[] fill(final float[] a, final float val) {
077        Arrays.fill(a, val);
078        return a;
079    }
080
081    /**
082     * Fills and returns the given array.
083     *
084     * @param a   the array to be filled.
085     * @param val the value to be stored in all elements of the array.
086     * @return the given array.
087     * @see Arrays#fill(int[],int)
088     */
089    public static int[] fill(final int[] a, final int val) {
090        Arrays.fill(a, val);
091        return a;
092    }
093
094    /**
095     * Fills and returns the given array.
096     *
097     * @param a   the array to be filled.
098     * @param val the value to be stored in all elements of the array.
099     * @return the given array.
100     * @see Arrays#fill(long[],long)
101     */
102    public static long[] fill(final long[] a, final long val) {
103        Arrays.fill(a, val);
104        return a;
105    }
106
107    /**
108     * Fills and returns the given array.
109     *
110     * @param a   the array to be filled.
111     * @param val the value to be stored in all elements of the array.
112     * @return the given array.
113     * @see Arrays#fill(short[],short)
114     */
115    public static short[] fill(final short[] a, final short val) {
116        Arrays.fill(a, val);
117        return a;
118    }
119
120    /**
121     * Fills and returns the given array.
122     *
123     * @param <T> the array type.
124     * @param a   the array to be filled.
125     * @param val the value to be stored in all elements of the array.
126     * @return the given array.
127     * @see Arrays#fill(Object[],Object)
128     */
129    public static <T> T[] fill(final T[] a, final T val) {
130        Arrays.fill(a, val);
131        return a;
132    }
133
134    private ArrayFill() {
135        // no instances
136    }
137
138}