View Javadoc

    1   package sharin.util;
    2
    3   public class ArrayUtils {
    4
    5       public static final Boolean[] EMPTY_BOOLEAN_WRAPPERS = new Boolean[0];
    6
    7       public static final Byte[] EMPTY_BYTE_WRAPPERS = new Byte[0];
    8
    9       public static final Character[] EMPTY_CHARACTER_WRAPPERS = new Character[0];
    10
    11      public static final Short[] EMPTY_SHORT_WRAPPERS = new Short[0];
    12
    13      public static final Integer[] EMPTY_INTEGER_WRAPPERS = new Integer[0];
    14
    15      public static final Long[] EMPTY_LONG_WRAPPERS = new Long[0];
    16
    17      public static final Float[] EMPTY_FLOAT_WRAPPERS = new Float[0];
    18
    19      public static final Double[] EMPTY_DOUBLE_WRAPPERS = new Double[0];
    20
    21      public static Boolean[] toWrappers(boolean... values) {
    22
    23          if (values == null) {
    24              return EMPTY_BOOLEAN_WRAPPERS;
    25          }
    26
    27          Boolean[] wrappers = new Boolean[values.length];
    28
    29          for (int i = 0; i < values.length; i++) {
    30              wrappers[i] = values[i];
    31          }
    32
    33          return wrappers;
    34      }
    35
    36      public static Byte[] toWrappers(byte... values) {
    37
    38          if (values == null) {
    39              return EMPTY_BYTE_WRAPPERS;
    40          }
    41
    42          Byte[] wrappers = new Byte[values.length];
    43
    44          for (int i = 0; i < values.length; i++) {
    45              wrappers[i] = values[i];
    46          }
    47
    48          return wrappers;
    49      }
    50
    51      public static Character[] toWrappers(char... values) {
    52
    53          if (values == null) {
    54              return EMPTY_CHARACTER_WRAPPERS;
    55          }
    56
    57          Character[] wrappers = new Character[values.length];
    58
    59          for (int i = 0; i < values.length; i++) {
    60              wrappers[i] = values[i];
    61          }
    62
    63          return wrappers;
    64      }
    65
    66      public static Short[] toWrappers(short... values) {
    67
    68          if (values == null) {
    69              return EMPTY_SHORT_WRAPPERS;
    70          }
    71
    72          Short[] wrappers = new Short[values.length];
    73
    74          for (int i = 0; i < values.length; i++) {
    75              wrappers[i] = values[i];
    76          }
    77
    78          return wrappers;
    79      }
    80
    81      public static Integer[] toWrappers(int... values) {
    82
    83          if (values == null) {
    84              return EMPTY_INTEGER_WRAPPERS;
    85          }
    86
    87          Integer[] wrappers = new Integer[values.length];
    88
    89          for (int i = 0; i < values.length; i++) {
    90              wrappers[i] = values[i];
    91          }
    92
    93          return wrappers;
    94      }
    95
    96      public static Long[] toWrappers(long... values) {
    97
    98          if (values == null) {
    99              return EMPTY_LONG_WRAPPERS;
    100         }
    101
    102         Long[] wrappers = new Long[values.length];
    103
    104         for (int i = 0; i < values.length; i++) {
    105             wrappers[i] = values[i];
    106         }
    107
    108         return wrappers;
    109     }
    110
    111     public static Float[] toWrappers(float... values) {
    112
    113         if (values == null) {
    114             return EMPTY_FLOAT_WRAPPERS;
    115         }
    116
    117         Float[] wrappers = new Float[values.length];
    118
    119         for (int i = 0; i < values.length; i++) {
    120             wrappers[i] = values[i];
    121         }
    122
    123         return wrappers;
    124     }
    125
    126     public static Double[] toWrappers(double... values) {
    127
    128         if (values == null) {
    129             return EMPTY_DOUBLE_WRAPPERS;
    130         }
    131
    132         Double[] wrappers = new Double[values.length];
    133
    134         for (int i = 0; i < values.length; i++) {
    135             wrappers[i] = values[i];
    136         }
    137
    138         return wrappers;
    139     }
    140 }