1 43 44 package org.jfree.util; 45 46 import java.util.Arrays ; 47 48 53 public class ArrayUtilities { 54 55 58 private ArrayUtilities() { 59 } 60 61 68 public static float[][] clone(final float[][] array) { 69 70 if (array == null) { 71 return null; 72 } 73 final float[][] result = new float[array.length][]; 74 System.arraycopy(array, 0, result, 0, array.length); 75 76 for (int i = 0; i < array.length; i++) { 77 final float[] child = array[i]; 78 final float[] copychild = new float[child.length]; 79 System.arraycopy(child, 0, copychild, 0, child.length); 80 result[i] = copychild; 81 } 82 83 return result; 84 85 } 86 87 97 public static boolean equalReferencesInArrays(final Object [] array1, 98 final Object [] array2) { 99 if (array1 == null) { 100 return (array2 == null); 101 } 102 if (array2 == null) { 103 return false; 104 } 105 if (array1.length != array2.length) { 106 return false; 107 } 108 for (int i = 0; i < array1.length; i++) { 109 if (array1[i] == null) { 110 if (array2[i] != null) { 111 return false; 112 } 113 } 114 if (array2[i] == null) { 115 if (array1[i] != null) { 116 return false; 117 } 118 } 119 if (array1[i] != array2[i]) { 120 return false; 121 } 122 } 123 return true; 124 } 125 126 134 public static boolean equal(final float[][] array1, 135 final float[][] array2) { 136 if (array1 == null) { 137 return (array2 == null); 138 } 139 140 if (array2 == null) { 141 return false; 142 } 143 144 if (array1.length != array2.length) { 145 return false; 146 } 147 148 for (int i = 0; i < array1.length; i++) { 149 if (!Arrays.equals(array1[i], array2[i])) { 150 return false; 151 } 152 } 153 return true; 154 } 155 156 164 public static boolean hasDuplicateItems(final Object [] array) { 165 for (int i = 0; i < array.length; i++) { 166 for (int j = 0; j < i; j++) { 167 final Object o1 = array[i]; 168 final Object o2 = array[j]; 169 if (o1 != null && o2 != null) { 170 if (o1.equals(o2)) { 171 return true; 172 } 173 } 174 } 175 } 176 return false; 177 } 178 179 public static int compareVersionArrays (Comparable [] a1, Comparable [] a2) 180 { 181 int length = Math.min (a1.length, a2.length); 182 for (int i = 0; i < length; i++) 183 { 184 Comparable o1 = a1[i]; 185 Comparable o2 = a2[i]; 186 if (o1 == null && o2 == null) 187 { 188 continue; 190 } 191 if (o1 == null) 192 { 193 return 1; 194 } 195 if (o2 == null) 196 { 197 return -1; 198 } 199 int retval = o1.compareTo(o2); 200 if (retval != 0) 201 { 202 return retval; 203 } 204 } 205 return 0; 206 } 207 208 } 209 | Popular Tags |