avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1480769 - in /avro/trunk: ./ lang/java/avro/src/main/java/org/apache/avro/generic/ lang/java/avro/src/test/java/org/apache/avro/generic/
Date Thu, 09 May 2013 21:00:45 GMT
Author: cutting
Date: Thu May  9 21:00:45 2013
New Revision: 1480769

URL: http://svn.apache.org/r1480769
Log:
AVRO-1327. Java: Make GenericEnumSymbol implement Comparable.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericEnumSymbol.java
    avro/trunk/lang/java/avro/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=1480769&r1=1480768&r2=1480769&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Thu May  9 21:00:45 2013
@@ -48,6 +48,8 @@ Trunk (not yet released)
     AVRO-1313. Java: Add system property avro.disable.unsafe for disabling
     use of sun.misc.Unsafe. (scottcarey)
 
+    AVRO-1327. Java: Make GenericEnumSymbol implement Comparable. (cutting)
+
   BUG FIXES
 
     AVRO-1296. Python: Fix schemas retrieved from protocol types

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java?rev=1480769&r1=1480768&r2=1480769&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java (original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java Thu May
 9 21:00:45 2013
@@ -302,7 +302,8 @@ public class GenericData {
   }
 
   /** Default implementation of {@link GenericEnumSymbol}. */
-  public static class EnumSymbol implements GenericEnumSymbol {
+  public static class EnumSymbol
+      implements GenericEnumSymbol, Comparable<GenericEnumSymbol>  {
     private Schema schema;
     private String symbol;
 
@@ -325,6 +326,11 @@ public class GenericData {
 
     @Override
     public String toString() { return symbol; }
+
+    @Override
+    public int compareTo(GenericEnumSymbol that) {
+      return GenericData.get().compare(this, that, schema);
+    }
   }
 
   /** Returns a {@link DatumReader} for this kind of data. */

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericEnumSymbol.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericEnumSymbol.java?rev=1480769&r1=1480768&r2=1480769&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericEnumSymbol.java
(original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericEnumSymbol.java
Thu May  9 21:00:45 2013
@@ -18,7 +18,8 @@
 package org.apache.avro.generic;
 
 /** An enum symbol. */
-public interface GenericEnumSymbol extends GenericContainer {
+public interface GenericEnumSymbol
+    extends GenericContainer, Comparable<GenericEnumSymbol> {
   /** Return the symbol. */
   String toString();
 }

Modified: avro/trunk/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericData.java?rev=1480769&r1=1480768&r2=1480769&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericData.java (original)
+++ avro/trunk/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericData.java Thu
May  9 21:00:45 2013
@@ -361,6 +361,16 @@ public class TestGenericData {
   }
   
   @Test
+  public void testEnumCompare() {
+    Schema s = Schema.createEnum("Kind",null,null,Arrays.asList("Z","Y","X"));
+    GenericEnumSymbol z = new GenericData.EnumSymbol(s, "Z");
+    GenericEnumSymbol y = new GenericData.EnumSymbol(s, "Y");
+    assertEquals(0, z.compareTo(z));
+    assertTrue(y.compareTo(z) > 0);
+    assertTrue(z.compareTo(y) < 0);
+  }
+
+  @Test
   public void testByteBufferDeepCopy() {
     // Test that a deep copy of a byte buffer respects the byte buffer
     // limits and capacity.



Mime
View raw message