View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.lang3;
19  
20  import java.util.Arrays;
21  
22  /**
23   * Fills and returns arrays in the fluent style.
24   *
25   * @since 3.14.0
26   */
27  public final class ArrayFill {
28  
29      /**
30       * Fills and returns the given array.
31       *
32       * @param a   the array to be filled.
33       * @param val the value to be stored in all elements of the array.
34       * @return the given array.
35       * @see Arrays#fill(byte[],byte)
36       */
37      public static byte[] fill(final byte[] a, final byte val) {
38          Arrays.fill(a, val);
39          return a;
40      }
41  
42      /**
43       * Fills and returns the given array.
44       *
45       * @param a   the array to be filled.
46       * @param val the value to be stored in all elements of the array.
47       * @return the given array.
48       * @see Arrays#fill(char[],char)
49       */
50      public static char[] fill(final char[] a, final char val) {
51          Arrays.fill(a, val);
52          return a;
53      }
54  
55      /**
56       * Fills and returns the given array.
57       *
58       * @param a   the array to be filled.
59       * @param val the value to be stored in all elements of the array.
60       * @return the given array.
61       * @see Arrays#fill(double[],double)
62       */
63      public static double[] fill(final double[] a, final double val) {
64          Arrays.fill(a, val);
65          return a;
66      }
67  
68      /**
69       * Fills and returns the given array.
70       *
71       * @param a   the array to be filled.
72       * @param val the value to be stored in all elements of the array.
73       * @return the given array.
74       * @see Arrays#fill(float[],float)
75       */
76      public static float[] fill(final float[] a, final float val) {
77          Arrays.fill(a, val);
78          return a;
79      }
80  
81      /**
82       * Fills and returns the given array.
83       *
84       * @param a   the array to be filled.
85       * @param val the value to be stored in all elements of the array.
86       * @return the given array.
87       * @see Arrays#fill(int[],int)
88       */
89      public static int[] fill(final int[] a, final int val) {
90          Arrays.fill(a, val);
91          return a;
92      }
93  
94      /**
95       * Fills and returns the given array.
96       *
97       * @param a   the array to be filled.
98       * @param val the value to be stored in all elements of the array.
99       * @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 }