一、前言
关于jcommon包(1.0.9)定义org.jfree.util.ArrayUtilities数组工具类,实现对象数组clone克隆、对象equal相当判断、重复对象hasDuplicateItems判断及版本compareVersionArrays比较,详情参见源码说明。
二、源码说明
package org.jfree.util;@b@@b@import java.util.Arrays;@b@@b@public class ArrayUtilities@b@{@b@ public static float[][] clone(float[][] array)@b@ {@b@ if (array == null)@b@ return ((float[][])null);@b@@b@ float[][] result = new float[array.length][];@b@ System.arraycopy(array, 0, result, 0, array.length);@b@@b@ for (int i = 0; i < array.length; ++i) {@b@ float[] child = array[i];@b@ float[] copychild = new float[child.length];@b@ System.arraycopy(child, 0, copychild, 0, child.length);@b@ result[i] = copychild;@b@ }@b@@b@ return result;@b@ }@b@@b@ public static boolean equalReferencesInArrays(Object[] array1, Object[] array2)@b@ {@b@ if (array1 == null)@b@ return (array2 == null);@b@@b@ if (array2 == null)@b@ return false;@b@@b@ if (array1.length != array2.length)@b@ return false;@b@@b@ for (int i = 0; i < array1.length; ++i) {@b@ if ((array1[i] == null) && @b@ (array2[i] != null)) {@b@ return false;@b@ }@b@@b@ if ((array2[i] == null) && @b@ (array1[i] != null)) {@b@ return false;@b@ }@b@@b@ if (array1[i] != array2[i])@b@ return false;@b@ }@b@@b@ return true;@b@ }@b@@b@ public static boolean equal(float[][] array1, float[][] array2)@b@ {@b@ if (array1 == null) {@b@ return (array2 == null);@b@ }@b@@b@ if (array2 == null) {@b@ return false;@b@ }@b@@b@ if (array1.length != array2.length) {@b@ return false;@b@ }@b@@b@ for (int i = 0; i < array1.length; ++i)@b@ if (!(Arrays.equals(array1[i], array2[i])))@b@ return false;@b@@b@@b@ return true;@b@ }@b@@b@ public static boolean hasDuplicateItems(Object[] array)@b@ {@b@ for (int i = 0; i < array.length; ++i)@b@ for (int j = 0; j < i; ++j) {@b@ Object o1 = array[i];@b@ Object o2 = array[j];@b@ if ((o1 != null) && (o2 != null) && @b@ (o1.equals(o2)))@b@ return true;@b@@b@ }@b@@b@@b@ return false;@b@ }@b@@b@ public static int compareVersionArrays(Comparable[] a1, Comparable[] a2)@b@ {@b@ int length = Math.min(a1.length, a2.length);@b@ for (int i = 0; i < length; ++i)@b@ {@b@ Comparable o1 = a1[i];@b@ Comparable o2 = a2[i];@b@ if ((o1 == null) && (o2 == null))@b@ {@b@ break label71:@b@ }@b@ if (o1 == null)@b@ {@b@ return 1;@b@ }@b@ if (o2 == null)@b@ {@b@ return -1;@b@ }@b@ int retval = o1.compareTo(o2);@b@ if (retval != 0)@b@ {@b@ return retval;@b@ }@b@ }@b@ label71: return 0;@b@ }@b@}