Clover coverage report - brownies library - 1.0-beta-1
Coverage timestamp: 月 8 16 2004 17:14:42 GMT+09:00
file stats: LOC: 190   Methods: 13
NCLOC: 149   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
ArrayUtils.java 39.7% 43% 53.8% 42.4%
coverage coverage
 1   
 /*
 2   
  * Joey and its relative products are published under the terms
 3   
  * of the Apache Software License.
 4   
  */
 5   
 package org.asyrinx.brownie.core.lang;
 6   
 
 7   
 import java.util.ArrayList;
 8   
 import java.util.Collection;
 9   
 import java.util.Iterator;
 10   
 import java.util.List;
 11   
 import java.util.Vector;
 12   
 
 13   
 /**
 14   
  * @author Akima
 15   
  *  
 16   
  */
 17   
 public final class ArrayUtils extends org.apache.commons.lang.ArrayUtils {
 18   
 
 19  0
     public static boolean equals(Object[] array1, Object[] array2) {
 20  0
         if (array1 == array2)
 21  0
             return true;
 22  0
         if (ObjectUtils.eitherIsNull(array1, array2))
 23  0
             return false;
 24  0
         if (array1.length != array2.length)
 25  0
             return false;
 26  0
         for (int i = 0; i < array1.length; i++) {
 27  0
             if (!ObjectUtils.equals(array1[i], array2[i]))
 28  0
                 return false;
 29   
         }
 30  0
         return true;
 31   
     }
 32   
 
 33  2
     public static void addToList(List dest, Object[] objects) {
 34  2
         for (int i = 0; i < objects.length; i++)
 35  12
             dest.add(objects[i]);
 36   
     }
 37   
 
 38  2
     public static ArrayList toArrayList(Object[] objects) {
 39  2
         final ArrayList result = new ArrayList();
 40  2
         addToList(result, objects);
 41  2
         return result;
 42   
     }
 43   
 
 44  0
     public static Vector toVector(Object[] objects) {
 45  0
         final Vector result = new Vector();
 46  0
         addToList(result, objects);
 47  0
         return result;
 48   
     }
 49   
 
 50  0
     public static Object getFirst(Object[] objects) {
 51  0
         if (objects == null) {
 52  0
             return null;
 53  0
         } else if (objects.length == 0) {
 54  0
             return null;
 55   
         } else {
 56  0
             return objects[0];
 57   
         }
 58   
     }
 59   
 
 60  16
     public static Object getLast(Object[] objects) {
 61  16
         if (objects == null) {
 62  0
             return null;
 63  16
         } else if (objects.length == 0) {
 64  0
             return null;
 65   
         } else {
 66  16
             return objects[objects.length - 1];
 67   
         }
 68   
     }
 69   
 
 70   
     /**
 71   
      * 引数のCollectionの各要素をStringの配列に変換します。 <br>
 72   
      * 
 73   
      * @param sources
 74   
      * @return String[]
 75   
      */
 76  0
     public static String[] toStringArray(Collection sources) {
 77  0
         final String[] result = new String[sources.size()];
 78  0
         final Iterator iterator = sources.iterator();
 79  0
         int idx = 0;
 80  0
         while (iterator.hasNext()) {
 81  0
             Object element = iterator.next();
 82  0
             result[idx] = (element != null) ? element.toString() : null;
 83  0
             idx++;
 84   
         }
 85  0
         return result;
 86   
     }
 87   
 
 88   
     /**
 89   
      * Objectの配列の各要素をStringの配列に変換します。 <br>
 90   
      * 
 91   
      * @param sources
 92   
      * @return String[]
 93   
      */
 94  0
     public static String[] toStringArray(Object[] sources) {
 95  0
         final String[] result = new String[sources.length];
 96  0
         for (int idx = 0; idx < sources.length; idx++)
 97  0
             result[idx] = (sources[idx] != null) ? sources[idx].toString()
 98   
                     : null;
 99  0
         return result;
 100   
     }
 101   
 
 102  38
     public static Object[] subArray(Object[] source, int beginIdx, int length) {
 103  38
         if (source == null)
 104  1
             return null;
 105  37
         final Object[] result = new Object[length];
 106  37
         for (int i = beginIdx;; i++) {
 107  112
             if (i > source.length - 1)
 108  0
                 break;
 109  112
             if (i - beginIdx > result.length - 1)
 110  37
                 break;
 111  75
             result[i - beginIdx] = source[i];
 112   
         }
 113  37
         return result;
 114   
     }
 115   
 
 116  0
     public static char[] toPrimitive(final Character[] array) {
 117  0
         if (array == null) {
 118  0
             return null;
 119  0
         } else if (array.length == 0) {
 120  0
             return EMPTY_CHAR_ARRAY;
 121   
         }
 122  0
         final char[] result = new char[array.length];
 123  0
         for (int i = 0; i < array.length; i++) {
 124  0
             result[i] = array[i].charValue();
 125   
         }
 126  0
         return result;
 127   
     }
 128   
 
 129   
     /**
 130   
      * @param array
 131   
      * @return
 132   
      */
 133  2
     public static Character[] toObject(char[] array) {
 134  2
         if (array == null) {
 135  0
             return null;
 136  2
         } else if (array.length == 0) {
 137  0
             return EMPTY_CHARACTER_OBJECT_ARRAY;
 138   
         }
 139  2
         final Character[] result = new Character[array.length];
 140  2
         for (int i = 0; i < array.length; i++) {
 141  6
             result[i] = new Character(array[i]);
 142   
         }
 143  2
         return result;
 144   
     }
 145   
 
 146  7
     public static Object[] toObjectArray(Object primitiveArray) {
 147  7
         if (primitiveArray instanceof boolean[]) {
 148  1
             return toObject((boolean[]) primitiveArray);
 149  6
         } else if (primitiveArray instanceof byte[]) {
 150  0
             return toObject((byte[]) primitiveArray);
 151  6
         } else if (primitiveArray instanceof short[]) {
 152  0
             return toObject((short[]) primitiveArray);
 153  6
         } else if (primitiveArray instanceof int[]) {
 154  3
             return toObject((int[]) primitiveArray);
 155  3
         } else if (primitiveArray instanceof long[]) {
 156  1
             return toObject((long[]) primitiveArray);
 157  2
         } else if (primitiveArray instanceof double[]) {
 158  0
             return toObject((double[]) primitiveArray);
 159  2
         } else if (primitiveArray instanceof float[]) {
 160  0
             return toObject((float[]) primitiveArray);
 161  2
         } else if (primitiveArray instanceof char[]) {
 162  2
             return toObject((char[]) primitiveArray);
 163   
         }
 164  0
         throw new UnsupportedClassRuntimeException(primitiveArray.getClass()
 165   
                 .getName());
 166   
     }
 167   
 
 168  3
     public static Object toPrimitiveArray(Object[] objectArray) {
 169  3
         if (objectArray instanceof Boolean[]) {
 170  1
             return toPrimitive((Boolean[]) objectArray);
 171  2
         } else if (objectArray instanceof Byte[]) {
 172  0
             return toPrimitive((Byte[]) objectArray);
 173  2
         } else if (objectArray instanceof Short[]) {
 174  0
             return toPrimitive((Short[]) objectArray);
 175  2
         } else if (objectArray instanceof Integer[]) {
 176  1
             return toPrimitive((Integer[]) objectArray);
 177  1
         } else if (objectArray instanceof Long[]) {
 178  1
             return toPrimitive((Long[]) objectArray);
 179  0
         } else if (objectArray instanceof Double[]) {
 180  0
             return toPrimitive((Double[]) objectArray);
 181  0
         } else if (objectArray instanceof Float[]) {
 182  0
             return toPrimitive((Float[]) objectArray);
 183  0
         } else if (objectArray instanceof Character[]) {
 184  0
             return toPrimitive((Character[]) objectArray);
 185   
         }
 186  0
         throw new UnsupportedClassRuntimeException(objectArray.getClass()
 187   
                 .getName());
 188   
     }
 189   
 
 190   
 }