Thrift generation for Java

Summary: Java works, benchmark roundtrip at around 3ms, so right in between C++ and PHP


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664775 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/test/java/src/TestClient.java b/test/java/src/TestClient.java
index cbcd802..686920c 100644
--- a/test/java/src/TestClient.java
+++ b/test/java/src/TestClient.java
@@ -1,11 +1,11 @@
 package com.facebook.thrift.test;
 
-import ThriftTest.*;
-import com.facebook.thrift.types.*;
+// Generated code
+import thrift.test.*;
+
 import com.facebook.thrift.transport.TSocket;
 import com.facebook.thrift.transport.TTransportException;
 import com.facebook.thrift.protocol.TBinaryProtocol;
-import com.facebook.thrift.protocol.TString;
 
 import java.util.HashMap;
 import java.util.HashSet;
@@ -39,8 +39,8 @@
         new TSocket(host, port);
       TBinaryProtocol binaryProtocol =
         new TBinaryProtocol();
-      ThriftTestClient testClient =
-        new ThriftTestClient(tSocket, binaryProtocol);
+      ThriftTest.Client testClient =
+        new ThriftTest.Client(tSocket, binaryProtocol);
 
       for (int test = 0; test < numTests; ++test) {
 
@@ -69,154 +69,154 @@
          * STRING TEST
          */
         System.out.print("testString(\"Test\")");
-        TString s = testClient.testString(new TString("Test"));
-        System.out.print(" = \"" + s.value + "\"\n");
-   
+        String s = testClient.testString("Test");
+        System.out.print(" = \"" + s + "\"\n");
+
         /**
          * BYTE TEST
          */
         System.out.print("testByte(1)");
-        UInt8 u8 = testClient.testByte(new UInt8((short)1));
-        System.out.print(" = " + u8.get() + "\n");
+        byte i8 = testClient.testByte((byte)1);
+        System.out.print(" = " + i8 + "\n");
   
         /**
          * I32 TEST
          */
         System.out.print("testI32(-1)");
-        Int32 i32 = testClient.testI32(new Int32(-1));
-        System.out.print(" = " + i32.get() + "\n");
+        int i32 = testClient.testI32(-1);
+        System.out.print(" = " + i32 + "\n");
 
         /**
          * I64 TEST
          */
         System.out.print("testI64(-34359738368)");
-        Int64 i64 = testClient.testI64(new Int64(-34359738368L));
-        System.out.print(" = " + i64.get() + "\n");
+        long i64 = testClient.testI64(-34359738368L);
+        System.out.print(" = " + i64 + "\n");
 
         /**
          * STRUCT TEST
          */
         System.out.print("testStruct({\"Zero\", 1, -3, -5})");
         Xtruct out = new Xtruct();
-        out.string_thing.value = "Zero";
-        out.byte_thing.set((short)1);
-        out.i32_thing.set(-3);
-        out.i64_thing.set(-5);
+        out.string_thing = "Zero";
+        out.byte_thing = (byte) 1;
+        out.i32_thing = -3;
+        out.i64_thing = -5;
         Xtruct in = testClient.testStruct(out);
         System.out.print(" = {" +
-                         "\"" + in.string_thing.value + "\", " +
-                         in.byte_thing.get() + ", " +
-                         in.i32_thing.get() + ", " +
-                         in.i64_thing.get() + "}\n");
+                         "\"" + in.string_thing + "\", " +
+                         in.byte_thing + ", " +
+                         in.i32_thing + ", " +
+                         in.i64_thing + "}\n");
 
         /**
          * NESTED STRUCT TEST
          */
         System.out.print("testNest({1, {\"Zero\", 1, -3, -5}), 5}");
         Xtruct2 out2 = new Xtruct2();
-        out2.byte_thing.set((short)1);
+        out2.byte_thing = (short)1;
         out2.struct_thing = out;
-        out2.i32_thing.set(5);
+        out2.i32_thing = 5;
         Xtruct2 in2 = testClient.testNest(out2);
         in = in2.struct_thing;
         System.out.print(" = {" +
-                         in2.byte_thing.get() + ", {" +
-                         "\"" + in.string_thing.value + "\", " +
-                         in.byte_thing.get() + ", " +
-                         in.i32_thing.get() + ", " +
-                         in.i64_thing.get() + "}, " +
-                         in2.i32_thing.get() + "}\n");
+                         in2.byte_thing + ", {" +
+                         "\"" + in.string_thing + "\", " +
+                         in.byte_thing + ", " +
+                         in.i32_thing + ", " +
+                         in.i64_thing + "}, " +
+                         in2.i32_thing + "}\n");
 
         /**
          * MAP TEST
          */
-        HashMap<Int32,Int32> mapout = new HashMap<Int32,Int32>();
+        HashMap<Integer,Integer> mapout = new HashMap<Integer,Integer>();
         for (int i = 0; i < 5; ++i) {
-          mapout.put(new Int32(i), new Int32(i-10));
+          mapout.put(i, i-10);
         }
         System.out.print("testMap({");
         boolean first = true;
-        for (Int32 key : mapout.keySet()) {
+        for (int key : mapout.keySet()) {
           if (first) {
             first = false;
           } else {
             System.out.print(", ");
           }
-          System.out.print(key.get() + " => " + mapout.get(key).get());
+          System.out.print(key + " => " + mapout.get(key));
         }
         System.out.print("})");
-        HashMap<Int32,Int32> mapin = testClient.testMap(mapout);
+        HashMap<Integer,Integer> mapin = testClient.testMap(mapout);
         System.out.print(" = {");
         first = true;
-        for (Int32 key : mapin.keySet()) {
+        for (int key : mapin.keySet()) {
           if (first) {
             first = false;
           } else {
             System.out.print(", ");
           }
-          System.out.print(key.get() + " => " + mapout.get(key).get());
+          System.out.print(key + " => " + mapout.get(key));
         }
         System.out.print("}\n");
 
         /**
          * SET TEST
          */
-        HashSet<Int32> setout = new HashSet<Int32>();
+        HashSet<Integer> setout = new HashSet<Integer>();
         for (int i = -2; i < 3; ++i) {
-          setout.add(new Int32(i));
+          setout.add(i);
         }
         System.out.print("testSet({");
         first = true;
-        for (Int32 elem : setout) {
+        for (int elem : setout) {
           if (first) {
             first = false;
           } else {
             System.out.print(", ");
           }
-          System.out.print(elem.get());
+          System.out.print(elem);
         }
         System.out.print("})");
-        HashSet<Int32> setin = testClient.testSet(setout);
+        HashSet<Integer> setin = testClient.testSet(setout);
         System.out.print(" = {");
         first = true;
-        for (Int32 elem : setin) {
+        for (int elem : setin) {
           if (first) {
             first = false;
           } else {
             System.out.print(", ");
           }
-          System.out.print(elem.get());
+          System.out.print(elem);
         }
         System.out.print("}\n");
 
         /**
          * LIST TEST
          */
-        ArrayList<Int32> listout = new ArrayList<Int32>();
+        ArrayList<Integer> listout = new ArrayList<Integer>();
         for (int i = -2; i < 3; ++i) {
-          listout.add(new Int32(i));
+          listout.add(i);
         }
         System.out.print("testList({");
         first = true;
-        for (Int32 elem : listout) {
+        for (int elem : listout) {
           if (first) {
             first = false;
           } else {
             System.out.print(", ");
           }
-          System.out.print(elem.get());
+          System.out.print(elem);
         }
         System.out.print("})");
-        ArrayList<Int32> listin = testClient.testList(listout);
+        ArrayList<Integer> listin = testClient.testList(listout);
         System.out.print(" = {");
         first = true;
-        for (Int32 elem : listin) {
+        for (int elem : listin) {
           if (first) {
             first = false;
           } else {
             System.out.print(", ");
           }
-          System.out.print(elem.get());
+          System.out.print(elem);
         }
         System.out.print("}\n");
 
@@ -224,44 +224,44 @@
          * ENUM TEST
          */
         System.out.print("testEnum(ONE)");
-        Int32 ret = testClient.testEnum(Numberz.ONE);
-        System.out.print(" = " + ret.get() + "\n");
+        int ret = testClient.testEnum(Numberz.ONE);
+        System.out.print(" = " + ret + "\n");
 
         System.out.print("testEnum(TWO)");
         ret = testClient.testEnum(Numberz.TWO);
-        System.out.print(" = " + ret.get() + "\n");
+        System.out.print(" = " + ret + "\n");
 
         System.out.print("testEnum(THREE)");
         ret = testClient.testEnum(Numberz.THREE);
-        System.out.print(" = " + ret.get() + "\n");
+        System.out.print(" = " + ret + "\n");
 
         System.out.print("testEnum(FIVE)");
         ret = testClient.testEnum(Numberz.FIVE);
-        System.out.print(" = " + ret.get() + "\n");
+        System.out.print(" = " + ret + "\n");
 
         System.out.print("testEnum(EIGHT)");
         ret = testClient.testEnum(Numberz.EIGHT);
-        System.out.print(" = " + ret.get() + "\n");
+        System.out.print(" = " + ret + "\n");
 
         /**
          * TYPEDEF TEST
          */
         System.out.print("testTypedef(309858235082523)");
-        Int64 uid = testClient.testTypedef(new Int64(309858235082523L));
-        System.out.print(" = " + uid.get() + "\n");
+        long uid = testClient.testTypedef(309858235082523L);
+        System.out.print(" = " + uid + "\n");
 
         /**
          * NESTED MAP TEST
          */
         System.out.print("testMapMap(1)");
-        HashMap<Int32,HashMap<Int32,Int32>> mm =
-          testClient.testMapMap(new Int32(1));
+        HashMap<Integer,HashMap<Integer,Integer>> mm =
+          testClient.testMapMap(1);
         System.out.print(" = {");
-        for (Int32 key : mm.keySet()) {
-          System.out.print(key.get() + " => {");
-          HashMap<Int32,Int32> m2 = mm.get(key);
-          for (Int32 k2 : m2.keySet()) {
-            System.out.print(k2.get() + " => " + m2.get(k2).get() + ", ");
+        for (int key : mm.keySet()) {
+          System.out.print(key + " => {");
+          HashMap<Integer,Integer> m2 = mm.get(key);
+          for (int k2 : m2.keySet()) {
+            System.out.print(k2 + " => " + m2.get(k2) + ", ");
           }
           System.out.print("}, ");
         }
@@ -271,29 +271,29 @@
          * INSANITY TEST
          */
         Insanity insane = new Insanity();
-        insane.userMap.put(Numberz.FIVE, new Int64(5000));
+        insane.userMap.put(Numberz.FIVE, (long)5000);
         Xtruct truck = new Xtruct();
-        truck.string_thing.value = "Truck";
-        truck.byte_thing.set((short)8);
-        truck.i32_thing.set(8);
-        truck.i64_thing.set(8);
+        truck.string_thing = "Truck";
+        truck.byte_thing = (byte)8;
+        truck.i32_thing = 8;
+        truck.i64_thing = 8;
         insane.xtructs.add(truck);
         System.out.print("testInsanity()");
-        HashMap<Int64,HashMap<Int32,Insanity>> whoa =
+        HashMap<Long,HashMap<Integer,Insanity>> whoa =
           testClient.testInsanity(insane);
         System.out.print(" = {");
-        for (Int64 key : whoa.keySet()) {
-          HashMap<Int32,Insanity> val = whoa.get(key);
-          System.out.print(key.get() + " => {");
+        for (long key : whoa.keySet()) {
+          HashMap<Integer,Insanity> val = whoa.get(key);
+          System.out.print(key + " => {");
 
-          for (Int32 k2 : val.keySet()) {
+          for (int k2 : val.keySet()) {
             Insanity v2 = val.get(k2);
-            System.out.print(k2.get() + " => {");
-            HashMap<Int32, Int64> userMap = v2.userMap;
+            System.out.print(k2 + " => {");
+            HashMap<Integer, Long> userMap = v2.userMap;
             System.out.print("{");
-            for (Int32 k3 : userMap.keySet()) {
-              System.out.print(k3.get() + " => " +
-                               userMap.get(k3).get() + ", ");
+            for (int k3 : userMap.keySet()) {
+              System.out.print(k3 + " => " +
+                               userMap.get(k3) + ", ");
             }
             System.out.print("}, ");
 
@@ -301,10 +301,10 @@
             System.out.print("{");
             for (Xtruct x : xtructs) {
               System.out.print("{" +
-                               "\"" + x.string_thing.value + "\", " +
-                               x.byte_thing.get() + ", " +
-                               x.i32_thing.get() + ", "+
-                               x.i64_thing.get() + "}, ");
+                               "\"" + x.string_thing + "\", " +
+                               x.byte_thing + ", " +
+                               x.i32_thing + ", "+
+                               x.i64_thing + "}, ");
             }
             System.out.print("}");