You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2009/05/18 22:22:28 UTC

svn commit: r776079 - in /xerces/java/trunk/src/org/apache/xerces/impl/xs: XSModelImpl.java util/XSObjectListImpl.java

Author: mrglavas
Date: Mon May 18 20:22:27 2009
New Revision: 776079

URL: http://svn.apache.org/viewvc?rev=776079&view=rev
Log:
Adding native implementations of toArray() and toArray(Object[]).

Modified:
    xerces/java/trunk/src/org/apache/xerces/impl/xs/XSModelImpl.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/util/XSObjectListImpl.java

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/XSModelImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/XSModelImpl.java?rev=776079&r1=776078&r2=776079&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/XSModelImpl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/XSModelImpl.java Mon May 18 20:22:27 2009
@@ -17,6 +17,7 @@
 
 package org.apache.xerces.impl.xs;
 
+import java.lang.reflect.Array;
 import java.util.AbstractList;
 import java.util.Iterator;
 import java.util.ListIterator;
@@ -590,6 +591,31 @@
         return new XSNamespaceItemListIterator(index);
     }
     
+    public Object[] toArray() {
+        Object[] a = new Object[fGrammarCount];
+        toArray0(a);
+        return a;
+    }
+    
+    public Object[] toArray(Object[] a) {
+        if (a.length < fGrammarCount) {
+            Class arrayClass = a.getClass();
+            Class componentType = arrayClass.getComponentType();
+            a = (Object[]) Array.newInstance(componentType, fGrammarCount);
+        }
+        toArray0(a);
+        if (a.length > fGrammarCount) {
+            a[fGrammarCount] = null;
+        }
+        return a;
+    }
+    
+    private void toArray0(Object[] a) {
+        if (fGrammarCount > 0) {
+            System.arraycopy(fGrammarList, 0, a, 0, fGrammarCount);
+        }
+    }
+    
     private final class XSNamespaceItemListIterator implements ListIterator {
         private int index;
         public XSNamespaceItemListIterator(int index) {

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/util/XSObjectListImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/util/XSObjectListImpl.java?rev=776079&r1=776078&r2=776079&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/util/XSObjectListImpl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/util/XSObjectListImpl.java Mon May 18 20:22:27 2009
@@ -17,6 +17,7 @@
 
 package org.apache.xerces.impl.xs.util;
 
+import java.lang.reflect.Array;
 import java.util.AbstractList;
 import java.util.Iterator;
 import java.util.ListIterator;
@@ -195,6 +196,31 @@
         return false;
     }
     
+    public Object[] toArray() {
+        Object[] a = new Object[fLength];
+        toArray0(a);
+        return a;
+    }
+    
+    public Object[] toArray(Object[] a) {
+        if (a.length < fLength) {
+            Class arrayClass = a.getClass();
+            Class componentType = arrayClass.getComponentType();
+            a = (Object[]) Array.newInstance(componentType, fLength);
+        }
+        toArray0(a);
+        if (a.length > fLength) {
+            a[fLength] = null;
+        }
+        return a;
+    }
+    
+    private void toArray0(Object[] a) {
+        if (fLength > 0) {
+            System.arraycopy(fArray, 0, a, 0, fLength);
+        }
+    }
+    
     private final class XSObjectListIterator implements ListIterator {
         private int index;
         public XSObjectListIterator(int index) {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org