You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2009/01/09 23:35:18 UTC
svn commit: r733177 -
/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ArrayUtil.java
Author: gerdogdu
Date: Fri Jan 9 14:35:18 2009
New Revision: 733177
URL: http://svn.apache.org/viewvc?rev=733177&view=rev
Log:
Adding array related utility class.
Added:
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ArrayUtil.java (with props)
Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ArrayUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ArrayUtil.java?rev=733177&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ArrayUtil.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ArrayUtil.java Fri Jan 9 14:35:18 2009
@@ -0,0 +1,98 @@
+/*
+ * 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.
+ */
+package org.apache.webbeans.util;
+
+public final class ArrayUtil
+{
+
+ private ArrayUtil()
+ {
+
+ }
+
+ /**
+ * TODO please review this function and move to some place where all tests
+ * can use it! See also
+ * EJBInterceptComponentTest#testMultipleInterceptedComponent and other test
+ * functions
+ *
+ * Compare two arrays regardless of the position of the elements in the
+ * arrays.
+ * The complex handling with temporary flags is necessary due to the
+ * possibility of having multiple occurrences of the same element in the
+ * arrays. In this case both arrays have to contain the exactly same amount
+ * of those elements.
+ *
+ * This is only suited for smaller arrays (e.g. count < 100) since the
+ * algorithm uses a product of both arrays.
+ *
+ * If one likes to use this for larger arrays, we'd have to use hashes.
+ *
+ * @param arr1
+ * @param arr2
+ * @return
+ */
+ public static boolean equalsIgnorePosition(Object[] arr1, Object[] arr2)
+ {
+ if (arr1 == null && arr2 == null)
+ {
+ return true;
+ }
+
+ if (arr1 == null || arr2 == null)
+ {
+ return false;
+ }
+
+ if (arr1.length != arr2.length)
+ {
+ return false;
+ }
+
+ boolean[] found1 = new boolean[arr1.length];
+ boolean[] found2 = new boolean[arr2.length];
+
+ for (int i1 = 0; i1 < arr1.length; i1++)
+ {
+ Object o1 = arr1[i1];
+
+ for (int i2 = 0; i2 < arr2.length; i2++)
+ {
+ Object o2 = arr2[i2];
+
+ // if they are equal and not found already
+ if (o1.equals(o2) && found2[i2] == false)
+ {
+ // mark the entries in both arrays as found
+ found1[i1] = true;
+ found2[i2] = true;
+ break;
+ }
+ }
+ }
+
+ for (int i = 0; i < found1.length; i++)
+ {
+ if (!found1[i] || !found2[i])
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+}
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ArrayUtil.java
------------------------------------------------------------------------------
svn:eol-style = native