[jboss-svn-commits] JBoss Common SVN: r3176 - jboss-logmanager/trunk/src/main/java/org/jboss/logmanager.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu May 14 16:37:41 EDT 2009


Author: david.lloyd at jboss.com
Date: 2009-05-14 16:37:41 -0400 (Thu, 14 May 2009)
New Revision: 3176

Modified:
   jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/AtomicArray.java
Log:
Remove dep on JDK1.6 class...

Modified: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/AtomicArray.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/AtomicArray.java	2009-05-13 20:09:00 UTC (rev 3175)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/AtomicArray.java	2009-05-14 20:37:41 UTC (rev 3176)
@@ -27,6 +27,8 @@
 import java.util.Comparator;
 import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
 
+import java.util.logging.Handler;
+
 /**
  * Utility for snapshot/copy-on-write arrays.  To use these methods, two things are required: an immutable array
  * stored on a volatile field, and an instance of
@@ -98,6 +100,13 @@
         return updater.getAndSet(instance, value);
     }
 
+    @SuppressWarnings({ "unchecked" })
+    private static <V> V[] copyOf(final Class<V> componentType, V[] old, int newLen) {
+        final V[] target = newInstance(componentType, newLen);
+        System.arraycopy(old, 0, target, 0, Math.min(old.length, newLen));
+        return target;
+    }
+
     /**
      * Atomically replace the array with a new array which is one element longer, and which includes the given value.
      *
@@ -109,7 +118,7 @@
         for (;;) {
             final V[] oldVal = updater.get(instance);
             final int oldLen = oldVal.length;
-            final V[] newVal = Arrays.copyOf(oldVal, oldLen + 1);
+            final V[] newVal = copyOf(componentType, oldVal, oldLen + 1);
             newVal[oldLen] = value;
             if (updater.compareAndSet(instance, oldVal, newVal)) {
                 return;
@@ -144,7 +153,7 @@
                     }
                 }
             }
-            final V[] newVal = Arrays.copyOf(oldVal, oldLen + 1);
+            final V[] newVal = copyOf(componentType, oldVal, oldLen + 1);
             newVal[oldLen] = value;
             if (updater.compareAndSet(instance, oldVal, newVal)) {
                 return true;
@@ -360,6 +369,10 @@
 
     @SuppressWarnings({ "unchecked" })
     private static <V> V[] newInstance(Class<V> componentType, int length) {
-        return (V[]) Array.newInstance(componentType, length);
+        if (componentType == Handler.class) {
+            return (V[]) new Handler[length];
+        } else {
+            return (V[]) Array.newInstance(componentType, length);
+        }
     }
 }




More information about the jboss-svn-commits mailing list