avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r944026 - in /avro/trunk: ./ lang/java/ lang/java/src/java/org/apache/avro/generic/ lang/java/src/test/java/org/apache/avro/generic/
Date Thu, 13 May 2010 21:56:35 GMT
Author: cutting
Date: Thu May 13 21:56:34 2010
New Revision: 944026

URL: http://svn.apache.org/viewvc?rev=944026&view=rev
Log:
AVRO-540. Java: Make GenericArray reversible.  Contributed by Eric Evans.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/build.xml
    avro/trunk/lang/java/src/java/org/apache/avro/generic/GenericArray.java
    avro/trunk/lang/java/src/java/org/apache/avro/generic/GenericData.java
    avro/trunk/lang/java/src/test/java/org/apache/avro/generic/TestGenericData.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=944026&r1=944025&r2=944026&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Thu May 13 21:56:34 2010
@@ -36,6 +36,8 @@ Avro 1.4.0 (unreleased)
     AVRO-526. Fall back to pure Python StringIO if cStringIO is not available
     (Esteve Fernandez via hammer)
 
+    AVRO-540. Java: Make GenericArray reversible.  (Eric Evans via cutting)
+
   BUG FIXES
     AVRO-461. Skipping primitives in the ruby side (jmhodges)
 

Modified: avro/trunk/lang/java/build.xml
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/build.xml?rev=944026&r1=944025&r2=944026&view=diff
==============================================================================
--- avro/trunk/lang/java/build.xml (original)
+++ avro/trunk/lang/java/build.xml Thu May 13 21:56:34 2010
@@ -339,8 +339,7 @@
       <junit showoutput="yes"
              printsummary="withOutAndErr"
              haltonfailure="no"
-             fork="yes" forkMode="once"
-             maxmemory="128m"
+             fork="yes"
              errorProperty="tests.failed" failureProperty="tests.failed">
         <sysproperty key="test.count" value="${test.count}"/>
         <sysproperty key="test.dir" value="@{test.dir}"/>

Modified: avro/trunk/lang/java/src/java/org/apache/avro/generic/GenericArray.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/java/org/apache/avro/generic/GenericArray.java?rev=944026&r1=944025&r2=944026&view=diff
==============================================================================
--- avro/trunk/lang/java/src/java/org/apache/avro/generic/GenericArray.java (original)
+++ avro/trunk/lang/java/src/java/org/apache/avro/generic/GenericArray.java Thu May 13 21:56:34
2010
@@ -33,5 +33,8 @@ public interface GenericArray<T> extends
    * store an element, if any.  This permits reuse of arrays and their elements
    * without allocating new objects. */
   T peek();
+  
+  /** Reverses the order of the elements in this array. */
+  void reverse();
 }
 

Modified: avro/trunk/lang/java/src/java/org/apache/avro/generic/GenericData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/java/org/apache/avro/generic/GenericData.java?rev=944026&r1=944025&r2=944026&view=diff
==============================================================================
--- avro/trunk/lang/java/src/java/org/apache/avro/generic/GenericData.java (original)
+++ avro/trunk/lang/java/src/java/org/apache/avro/generic/GenericData.java Thu May 13 21:56:34
2010
@@ -131,6 +131,19 @@ public class GenericData {
     public int compareTo(Array<T> that) {
       return GenericData.get().compare(this, that, this.getSchema());
     }
+    public void reverse() {
+      int left = 0;
+      int right = elements.length - 1;
+      
+      while (left < right) {
+        Object tmp = elements[left];
+        elements[left] = elements[right];
+        elements[right] = tmp;
+        
+        left++;
+        right--;
+      }
+    }
     public String toString() {
       StringBuffer buffer = new StringBuffer();
       buffer.append("[");

Modified: avro/trunk/lang/java/src/test/java/org/apache/avro/generic/TestGenericData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/test/java/org/apache/avro/generic/TestGenericData.java?rev=944026&r1=944025&r2=944026&view=diff
==============================================================================
--- avro/trunk/lang/java/src/test/java/org/apache/avro/generic/TestGenericData.java (original)
+++ avro/trunk/lang/java/src/test/java/org/apache/avro/generic/TestGenericData.java Thu May
13 21:56:34 2010
@@ -68,5 +68,20 @@ public class TestGenericData {
     GenericData.Record record = new GenericData.Record(schema);
     assertNull(record.get("does not exist"));
   }
+  
+  @Test
+  public void testArrayReversal() {
+      Schema schema = Schema.createArray(Schema.create(Schema.Type.INT));
+      GenericArray<Integer> forward = new GenericData.Array<Integer>(10, schema);
+      GenericArray<Integer> backward = new GenericData.Array<Integer>(10, schema);
+      for (int i = 0; i <= 9; i++) {
+        forward.add(i);
+      }
+      for (int i = 9; i >= 0; i--) {
+        backward.add(i);
+      }
+      forward.reverse();
+      assertTrue(forward.equals(backward));
+  }
     
 }



Mime
View raw message