Here you can find the source of nullToEmpty(byte[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with the empty public static
references in this class.
Parameter | Description |
---|---|
array | the array to check for <code>null</code> or empty |
public static
empty array if null
or empty input
public static byte[] nullToEmpty(byte[] array)
//package com.java2s; /*//from w w w . jav a 2s. c o m * 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. */ public class Main { /** * An empty immutable <code>Object</code> array. */ public static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; /** * An empty immutable <code>String</code> array. */ public static final String[] EMPTY_STRING_ARRAY = new String[0]; /** * An empty immutable <code>long</code> array. */ public static final long[] EMPTY_LONG_ARRAY = new long[0]; /** * An empty immutable <code>Long</code> array. */ public static final Long[] EMPTY_LONG_OBJECT_ARRAY = new Long[0]; /** * An empty immutable <code>int</code> array. */ public static final int[] EMPTY_INT_ARRAY = new int[0]; /** * An empty immutable <code>Integer</code> array. */ public static final Integer[] EMPTY_INTEGER_OBJECT_ARRAY = new Integer[0]; /** * An empty immutable <code>short</code> array. */ public static final short[] EMPTY_SHORT_ARRAY = new short[0]; /** * An empty immutable <code>Short</code> array. */ public static final Short[] EMPTY_SHORT_OBJECT_ARRAY = new Short[0]; /** * An empty immutable <code>byte</code> array. */ public static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; /** * An empty immutable <code>Byte</code> array. */ public static final Byte[] EMPTY_BYTE_OBJECT_ARRAY = new Byte[0]; /** * An empty immutable <code>double</code> array. */ public static final double[] EMPTY_DOUBLE_ARRAY = new double[0]; /** * An empty immutable <code>Double</code> array. */ public static final Double[] EMPTY_DOUBLE_OBJECT_ARRAY = new Double[0]; /** * An empty immutable <code>float</code> array. */ public static final float[] EMPTY_FLOAT_ARRAY = new float[0]; /** * An empty immutable <code>Float</code> array. */ public static final Float[] EMPTY_FLOAT_OBJECT_ARRAY = new Float[0]; /** * An empty immutable <code>boolean</code> array. */ public static final boolean[] EMPTY_BOOLEAN_ARRAY = new boolean[0]; /** * An empty immutable <code>Boolean</code> array. */ public static final Boolean[] EMPTY_BOOLEAN_OBJECT_ARRAY = new Boolean[0]; /** * An empty immutable <code>char</code> array. */ public static final char[] EMPTY_CHAR_ARRAY = new char[0]; /** * An empty immutable <code>Character</code> array. */ public static final Character[] EMPTY_CHARACTER_OBJECT_ARRAY = new Character[0]; /** * <p>Defensive programming technique to change a <code>null</code> * reference to an empty one.</p> * * <p>This method returns an empty array for a <code>null</code> input array.</p> * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty <code>public static</code> references in this class.</p> * * @param array the array to check for <code>null</code> or empty * @return the same array, <code>public static</code> empty array if <code>null</code> or empty input * @since 2.5 */ public static Object[] nullToEmpty(Object[] array) { if (array == null || array.length == 0) { return EMPTY_OBJECT_ARRAY; } return array; } /** * <p>Defensive programming technique to change a <code>null</code> * reference to an empty one.</p> * * <p>This method returns an empty array for a <code>null</code> input array.</p> * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty <code>public static</code> references in this class.</p> * * @param array the array to check for <code>null</code> or empty * @return the same array, <code>public static</code> empty array if <code>null</code> or empty input * @since 2.5 */ public static String[] nullToEmpty(String[] array) { if (array == null || array.length == 0) { return EMPTY_STRING_ARRAY; } return array; } /** * <p>Defensive programming technique to change a <code>null</code> * reference to an empty one.</p> * * <p>This method returns an empty array for a <code>null</code> input array.</p> * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty <code>public static</code> references in this class.</p> * * @param array the array to check for <code>null</code> or empty * @return the same array, <code>public static</code> empty array if <code>null</code> or empty input * @since 2.5 */ public static long[] nullToEmpty(long[] array) { if (array == null || array.length == 0) { return EMPTY_LONG_ARRAY; } return array; } /** * <p>Defensive programming technique to change a <code>null</code> * reference to an empty one.</p> * * <p>This method returns an empty array for a <code>null</code> input array.</p> * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty <code>public static</code> references in this class.</p> * * @param array the array to check for <code>null</code> or empty * @return the same array, <code>public static</code> empty array if <code>null</code> or empty input * @since 2.5 */ public static int[] nullToEmpty(int[] array) { if (array == null || array.length == 0) { return EMPTY_INT_ARRAY; } return array; } /** * <p>Defensive programming technique to change a <code>null</code> * reference to an empty one.</p> * * <p>This method returns an empty array for a <code>null</code> input array.</p> * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty <code>public static</code> references in this class.</p> * * @param array the array to check for <code>null</code> or empty * @return the same array, <code>public static</code> empty array if <code>null</code> or empty input * @since 2.5 */ public static short[] nullToEmpty(short[] array) { if (array == null || array.length == 0) { return EMPTY_SHORT_ARRAY; } return array; } /** * <p>Defensive programming technique to change a <code>null</code> * reference to an empty one.</p> * * <p>This method returns an empty array for a <code>null</code> input array.</p> * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty <code>public static</code> references in this class.</p> * * @param array the array to check for <code>null</code> or empty * @return the same array, <code>public static</code> empty array if <code>null</code> or empty input * @since 2.5 */ public static char[] nullToEmpty(char[] array) { if (array == null || array.length == 0) { return EMPTY_CHAR_ARRAY; } return array; } /** * <p>Defensive programming technique to change a <code>null</code> * reference to an empty one.</p> * * <p>This method returns an empty array for a <code>null</code> input array.</p> * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty <code>public static</code> references in this class.</p> * * @param array the array to check for <code>null</code> or empty * @return the same array, <code>public static</code> empty array if <code>null</code> or empty input * @since 2.5 */ public static byte[] nullToEmpty(byte[] array) { if (array == null || array.length == 0) { return EMPTY_BYTE_ARRAY; } return array; } /** * <p>Defensive programming technique to change a <code>null</code> * reference to an empty one.</p> * * <p>This method returns an empty array for a <code>null</code> input array.</p> * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty <code>public static</code> references in this class.</p> * * @param array the array to check for <code>null</code> or empty * @return the same array, <code>public static</code> empty array if <code>null</code> or empty input * @since 2.5 */ public static double[] nullToEmpty(double[] array) { if (array == null || array.length == 0) { return EMPTY_DOUBLE_ARRAY; } return array; } /** * <p>Defensive programming technique to change a <code>null</code> * reference to an empty one.</p> * * <p>This method returns an empty array for a <code>null</code> input array.</p> * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty <code>public static</code> references in this class.</p> * * @param array the array to check for <code>null</code> or empty * @return the same array, <code>public static</code> empty array if <code>null</code> or empty input * @since 2.5 */ public static float[] nullToEmpty(float[] array) { if (array == null || array.length == 0) { return EMPTY_FLOAT_ARRAY; } return array; } /** * <p>Defensive programming technique to change a <code>null</code> * reference to an empty one.</p> * * <p>This method returns an empty array for a <code>null</code> input array.</p> * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty <code>public static</code> references in this class.</p> * * @param array the array to check for <code>null</code> or empty * @return the same array, <code>public static</code> empty array if <code>null</code> or empty input * @since 2.5 */ public static boolean[] nullToEmpty(boolean[] array) { if (array == null || array.length == 0) { return EMPTY_BOOLEAN_ARRAY; } return array; } /** * <p>Defensive programming technique to change a <code>null</code> * reference to an empty one.</p> * * <p>This method returns an empty array for a <code>null</code> input array.</p> * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty <code>public static</code> references in this class.</p> * * @param array the array to check for <code>null</code> or empty * @return the same array, <code>public static</code> empty array if <code>null</code> or empty input * @since 2.5 */ public static Long[] nullToEmpty(Long[] array) { if (array == null || array.length == 0) { return EMPTY_LONG_OBJECT_ARRAY; } return array; } /** * <p>Defensive programming technique to change a <code>null</code> * reference to an empty one.</p> * * <p>This method returns an empty array for a <code>null</code> input array.</p> * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty <code>public static</code> references in this class.</p> * * @param array the array to check for <code>null</code> or empty * @return the same array, <code>public static</code> empty array if <code>null</code> or empty input * @since 2.5 */ public static Integer[] nullToEmpty(Integer[] array) { if (array == null || array.length == 0) { return EMPTY_INTEGER_OBJECT_ARRAY; } return array; } /** * <p>Defensive programming technique to change a <code>null</code> * reference to an empty one.</p> * * <p>This method returns an empty array for a <code>null</code> input array.</p> * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty <code>public static</code> references in this class.</p> * * @param array the array to check for <code>null</code> or empty * @return the same array, <code>public static</code> empty array if <code>null</code> or empty input * @since 2.5 */ public static Short[] nullToEmpty(Short[] array) { if (array == null || array.length == 0) { return EMPTY_SHORT_OBJECT_ARRAY; } return array; } /** * <p>Defensive programming technique to change a <code>null</code> * reference to an empty one.</p> * * <p>This method returns an empty array for a <code>null</code> input array.</p> * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty <code>public static</code> references in this class.</p> * * @param array the array to check for <code>null</code> or empty * @return the same array, <code>public static</code> empty array if <code>null</code> or empty input * @since 2.5 */ public static Character[] nullToEmpty(Character[] array) { if (array == null || array.length == 0) { return EMPTY_CHARACTER_OBJECT_ARRAY; } return array; } /** * <p>Defensive programming technique to change a <code>null</code> * reference to an empty one.</p> * * <p>This method returns an empty array for a <code>null</code> input array.</p> * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty <code>public static</code> references in this class.</p> * * @param array the array to check for <code>null</code> or empty * @return the same array, <code>public static</code> empty array if <code>null</code> or empty input * @since 2.5 */ public static Byte[] nullToEmpty(Byte[] array) { if (array == null || array.length == 0) { return EMPTY_BYTE_OBJECT_ARRAY; } return array; } /** * <p>Defensive programming technique to change a <code>null</code> * reference to an empty one.</p> * * <p>This method returns an empty array for a <code>null</code> input array.</p> * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty <code>public static</code> references in this class.</p> * * @param array the array to check for <code>null</code> or empty * @return the same array, <code>public static</code> empty array if <code>null</code> or empty input * @since 2.5 */ public static Double[] nullToEmpty(Double[] array) { if (array == null || array.length == 0) { return EMPTY_DOUBLE_OBJECT_ARRAY; } return array; } /** * <p>Defensive programming technique to change a <code>null</code> * reference to an empty one.</p> * * <p>This method returns an empty array for a <code>null</code> input array.</p> * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty <code>public static</code> references in this class.</p> * * @param array the array to check for <code>null</code> or empty * @return the same array, <code>public static</code> empty array if <code>null</code> or empty input * @since 2.5 */ public static Float[] nullToEmpty(Float[] array) { if (array == null || array.length == 0) { return EMPTY_FLOAT_OBJECT_ARRAY; } return array; } /** * <p>Defensive programming technique to change a <code>null</code> * reference to an empty one.</p> * * <p>This method returns an empty array for a <code>null</code> input array.</p> * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty <code>public static</code> references in this class.</p> * * @param array the array to check for <code>null</code> or empty * @return the same array, <code>public static</code> empty array if <code>null</code> or empty input * @since 2.5 */ public static Boolean[] nullToEmpty(Boolean[] array) { if (array == null || array.length == 0) { return EMPTY_BOOLEAN_OBJECT_ARRAY; } return array; } }