mina-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvermill...@apache.org
Subject [18/25] git commit: code cleaning
Date Tue, 07 May 2013 19:20:06 GMT
code cleaning


Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/9638abef
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/9638abef
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/9638abef

Branch: refs/heads/trunk
Commit: 9638abef901e10b6b7d25bf4afd3fab3587375d7
Parents: 9759bab
Author: Raphaƫl P. Barazzutti <raphael.barazzutti@gmail.com>
Authored: Mon Apr 29 16:01:21 2013 +0200
Committer: jvermillard <jvermillard@apache.org>
Committed: Tue May 7 21:12:35 2013 +0200

----------------------------------------------------------------------
 .../mina/codec/delimited/ProtobufEncoder.java      |    1 +
 .../apache/mina/codec/delimited/ints/RawInt32.java |   13 +++--
 .../apache/mina/codec/delimited/DelimitTest.java   |   11 ++-
 .../apache/mina/codec/delimited/ProtobufTest.java  |    8 ++-
 .../apache/mina/codec/delimited/ThriftTest.java    |   11 ++--
 .../mina/codec/delimited/ints/IntEncodingTest.java |    6 +-
 .../serialization/GenericSerializerTest.java       |    3 +-
 .../delimited/serialization/JavaNativeTest.java    |   50 +++++---------
 .../delimited/serialization/ProtobufTest.java      |    2 +-
 9 files changed, 52 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina/blob/9638abef/codec/src/main/java/org/apache/mina/codec/delimited/ProtobufEncoder.java
----------------------------------------------------------------------
diff --git a/codec/src/main/java/org/apache/mina/codec/delimited/ProtobufEncoder.java b/codec/src/main/java/org/apache/mina/codec/delimited/ProtobufEncoder.java
index 5c63649..8386e89 100644
--- a/codec/src/main/java/org/apache/mina/codec/delimited/ProtobufEncoder.java
+++ b/codec/src/main/java/org/apache/mina/codec/delimited/ProtobufEncoder.java
@@ -24,6 +24,7 @@ import org.apache.mina.codec.delimited.serialization.ProtobufMessageEncoder;
 
 import com.google.protobuf.GeneratedMessage;
 
+
 /**
  * @author <a href="http://mina.apache.org">Apache MINA Project</a>
  */

http://git-wip-us.apache.org/repos/asf/mina/blob/9638abef/codec/src/main/java/org/apache/mina/codec/delimited/ints/RawInt32.java
----------------------------------------------------------------------
diff --git a/codec/src/main/java/org/apache/mina/codec/delimited/ints/RawInt32.java b/codec/src/main/java/org/apache/mina/codec/delimited/ints/RawInt32.java
index 7c56754..1ec8153 100644
--- a/codec/src/main/java/org/apache/mina/codec/delimited/ints/RawInt32.java
+++ b/codec/src/main/java/org/apache/mina/codec/delimited/ints/RawInt32.java
@@ -127,17 +127,20 @@ public class RawInt32 {
 
         @Override
         public Integer decode(ByteBuffer input) throws ProtocolDecoderException {
-            if (input.remaining() < 4)
+            if (input.remaining() < 4) {
                 return null;
+            }
 
             if (endianness == Endianness.BIG) {
-                if ((input.get(0) & 0x80) != 0)
+                if ((input.get(0) & 0x80) != 0) {
                     throw new ProtocolDecoderException("Not the big endian representation
of a signed int32");
+                }
                 return ((input.get() & 0xff) << 24) | ((input.get() & 0xff)
<< 16) | ((input.get() & 0xff) << 8)
                         | ((input.get() & 0xff));
             } else {
-                if ((input.get(3) & 0x80) != 0)
+                if ((input.get(3) & 0x80) != 0) {
                     throw new ProtocolDecoderException("Not the small endian representation
of a signed int32");
+                }
                 return ((input.get() & 0xff)) | ((input.get() & 0xff) << 8)
| ((input.get() & 0xff) << 16)
                         | ((input.get() & 0xff) << 24);
             }
@@ -162,8 +165,9 @@ public class RawInt32 {
         @Override
         public void writeTo(Integer message, ByteBuffer buffer) {
             // VarInts don't support negative values
-            if (message < 0)
+            if (message < 0) {
                 message = 0;
+            }
             if (endianness == Endianness.BIG) {
                 buffer.put((byte) (0xff & (message >> 24)));
                 buffer.put((byte) (0xff & (message >> 16)));
@@ -175,7 +179,6 @@ public class RawInt32 {
                 buffer.put((byte) (0xff & (message >> 16)));
                 buffer.put((byte) (0xff & (message >> 24)));
             }
-      
 
         }
 

http://git-wip-us.apache.org/repos/asf/mina/blob/9638abef/codec/src/test/java/org/apache/mina/codec/delimited/DelimitTest.java
----------------------------------------------------------------------
diff --git a/codec/src/test/java/org/apache/mina/codec/delimited/DelimitTest.java b/codec/src/test/java/org/apache/mina/codec/delimited/DelimitTest.java
index ea4996c..a43577f 100644
--- a/codec/src/test/java/org/apache/mina/codec/delimited/DelimitTest.java
+++ b/codec/src/test/java/org/apache/mina/codec/delimited/DelimitTest.java
@@ -44,17 +44,20 @@ abstract public class DelimitTest<T> {
         SizePrefixedEncoder<T> pe = getSerializer();
 
         List<ByteBuffer> buffers = new LinkedList<ByteBuffer>();
-        for (T p : getObjects())
+        for (T p : getObjects()) {
             buffers.add(pe.encode(p, null));
+        }
 
         int size = 0;
-        for (ByteBuffer b : buffers)
+        for (ByteBuffer b : buffers) {
             size += b.remaining();
+        }
 
         ByteBuffer buffer = ByteBuffer.allocate(size);
-        for (ByteBuffer b : buffers)
+        for (ByteBuffer b : buffers) {
             buffer.put(b);
-        buffer.flip();
+        }
+        buffer.flip();        
         return buffer;
     }
 

http://git-wip-us.apache.org/repos/asf/mina/blob/9638abef/codec/src/test/java/org/apache/mina/codec/delimited/ProtobufTest.java
----------------------------------------------------------------------
diff --git a/codec/src/test/java/org/apache/mina/codec/delimited/ProtobufTest.java b/codec/src/test/java/org/apache/mina/codec/delimited/ProtobufTest.java
index 57dabcb..54b8d82 100644
--- a/codec/src/test/java/org/apache/mina/codec/delimited/ProtobufTest.java
+++ b/codec/src/test/java/org/apache/mina/codec/delimited/ProtobufTest.java
@@ -24,8 +24,6 @@ import java.nio.ByteBuffer;
 import java.util.LinkedList;
 import java.util.List;
 
-import org.apache.mina.codec.delimited.serialization.ProtobufMessageDecoder;
-import org.apache.mina.codec.delimited.serialization.ProtobufMessageEncoder;
 import org.apache.mina.util.ByteBufferOutputStream;
 
 import ch.fever.code.mina.gpb.AddressBookProtos.Person;
@@ -38,6 +36,7 @@ import ch.fever.code.mina.gpb.AddressBookProtos.Person;
 public class ProtobufTest extends DelimitTest<Person> {
   
 
+    @Override
     public List<Person> getObjects() {
 
         List<Person> list = new LinkedList<Person>();
@@ -48,14 +47,17 @@ public class ProtobufTest extends DelimitTest<Person> {
         return list;
     }
 
+    @Override
     protected ByteBuffer delimitWithOriginal() throws IOException {
         ByteBufferOutputStream bbos = new ByteBufferOutputStream();
         bbos.setElastic(true);
-        for (Person p : getObjects())
+        for (Person p : getObjects()) {
             p.writeDelimitedTo(bbos);
+        }
         return bbos.getByteBuffer();
     }
 
+    @Override
     public SizePrefixedEncoder<Person> getSerializer() {
         return ProtobufEncoder.newInstance(Person.class);
     }

http://git-wip-us.apache.org/repos/asf/mina/blob/9638abef/codec/src/test/java/org/apache/mina/codec/delimited/ThriftTest.java
----------------------------------------------------------------------
diff --git a/codec/src/test/java/org/apache/mina/codec/delimited/ThriftTest.java b/codec/src/test/java/org/apache/mina/codec/delimited/ThriftTest.java
index 506a82e..2e1d821 100644
--- a/codec/src/test/java/org/apache/mina/codec/delimited/ThriftTest.java
+++ b/codec/src/test/java/org/apache/mina/codec/delimited/ThriftTest.java
@@ -23,8 +23,6 @@ import java.nio.ByteBuffer;
 import java.util.LinkedList;
 import java.util.List;
 
-import org.apache.mina.codec.delimited.serialization.ThriftMessageDecoder;
-import org.apache.mina.codec.delimited.serialization.ThriftMessageEncoder;
 import org.apache.thrift.TSerializer;
 import org.apache.thrift.transport.TFramedTransport;
 import org.apache.thrift.transport.TMemoryBuffer;
@@ -39,7 +37,8 @@ import ch.fever.code.mina.thrift.UserProfile;
  */
 public class ThriftTest extends DelimitTest<UserProfile> {
 
-	public List<UserProfile> getObjects() {
+	@Override
+    public List<UserProfile> getObjects() {
 
 		List<UserProfile> list = new LinkedList<UserProfile>();
 
@@ -49,7 +48,8 @@ public class ThriftTest extends DelimitTest<UserProfile> {
 		return list;
 	}
 
-	protected ByteBuffer delimitWithOriginal() throws Exception {
+	@Override
+    protected ByteBuffer delimitWithOriginal() throws Exception {
 
 		TMemoryBuffer m = new TMemoryBuffer(1000000);
 		TFramedTransport t = new TFramedTransport(m);
@@ -62,7 +62,8 @@ public class ThriftTest extends DelimitTest<UserProfile> {
 
 	}
 
-	public SizePrefixedEncoder<UserProfile> getSerializer()
+	@Override
+    public SizePrefixedEncoder<UserProfile> getSerializer()
 			throws SecurityException, NoSuchMethodException {
 		return ThriftEncoder.newInstance(UserProfile.class);
 	}

http://git-wip-us.apache.org/repos/asf/mina/blob/9638abef/codec/src/test/java/org/apache/mina/codec/delimited/ints/IntEncodingTest.java
----------------------------------------------------------------------
diff --git a/codec/src/test/java/org/apache/mina/codec/delimited/ints/IntEncodingTest.java
b/codec/src/test/java/org/apache/mina/codec/delimited/ints/IntEncodingTest.java
index f9a6b49..3126dc5 100644
--- a/codec/src/test/java/org/apache/mina/codec/delimited/ints/IntEncodingTest.java
+++ b/codec/src/test/java/org/apache/mina/codec/delimited/ints/IntEncodingTest.java
@@ -128,19 +128,21 @@ abstract public class IntEncodingTest {
     @Test
     public void testOverflow() {
 
-        for (ByteBuffer buffer : getIllegalBuffers())
+        for (ByteBuffer buffer : getIllegalBuffers()) {
             try {
                 decoder.decode(buffer);
                 fail("Should throw an overflow exception");
             } catch (ProtocolDecoderException e) {
                 // fine
             }
+        }
     }
 
     @Test
     public void testNegativeValues() {
         ByteBuffer zero = encoder.encode(0);
-        for (int i : new int[] { -1, -127, Integer.MIN_VALUE })
+        for (int i : new int[] { -1, -127, Integer.MIN_VALUE }) {
             assertEquals(zero, encoder.encode(i));
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/mina/blob/9638abef/codec/src/test/java/org/apache/mina/codec/delimited/serialization/GenericSerializerTest.java
----------------------------------------------------------------------
diff --git a/codec/src/test/java/org/apache/mina/codec/delimited/serialization/GenericSerializerTest.java
b/codec/src/test/java/org/apache/mina/codec/delimited/serialization/GenericSerializerTest.java
index 6615e1e..faa6327 100644
--- a/codec/src/test/java/org/apache/mina/codec/delimited/serialization/GenericSerializerTest.java
+++ b/codec/src/test/java/org/apache/mina/codec/delimited/serialization/GenericSerializerTest.java
@@ -45,8 +45,9 @@ abstract public class GenericSerializerTest<T> {
     public void testSerialization() throws Exception {
         ByteBufferDecoder<T> decoder = getDecoder();
         ByteBufferEncoder<T> encoder = getEncoder();
-        for (T object : getObjects())
+        for (T object : getObjects()) {
             assertEquals(object, decoder.decode(encoder.encode(object)));
+        }
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/mina/blob/9638abef/codec/src/test/java/org/apache/mina/codec/delimited/serialization/JavaNativeTest.java
----------------------------------------------------------------------
diff --git a/codec/src/test/java/org/apache/mina/codec/delimited/serialization/JavaNativeTest.java
b/codec/src/test/java/org/apache/mina/codec/delimited/serialization/JavaNativeTest.java
index 5dfc16e..05bf9f9 100644
--- a/codec/src/test/java/org/apache/mina/codec/delimited/serialization/JavaNativeTest.java
+++ b/codec/src/test/java/org/apache/mina/codec/delimited/serialization/JavaNativeTest.java
@@ -49,22 +49,29 @@ public class JavaNativeTest extends GenericSerializerTest<JavaNativeTest.TestBea
 
         @Override
         public boolean equals(Object obj) {
-            if (this == obj)
+            if (this == obj) {
                 return true;
-            if (obj == null)
+            }
+            if (obj == null) {
                 return false;
-            if (getClass() != obj.getClass())
+            }
+            if (getClass() != obj.getClass()) {
                 return false;
+            }
             TestBean other = (TestBean) obj;
             if (a == null) {
-                if (other.a != null)
+                if (other.a != null) {
                     return false;
-            } else if (!a.equals(other.a))
+                }
+            } else if (!a.equals(other.a)) {
                 return false;
-            if (b != other.b)
+            }
+            if (b != other.b) {
                 return false;
-            if (Double.doubleToLongBits(c) != Double.doubleToLongBits(other.c))
+            }
+            if (Double.doubleToLongBits(c) != Double.doubleToLongBits(other.c)) {
                 return false;
+            }
             return true;
         }
 
@@ -75,34 +82,13 @@ public class JavaNativeTest extends GenericSerializerTest<JavaNativeTest.TestBea
             this.c = c;
         }
 
-        private String a;
+        private final String a;
 
-        private int b;
+        private final int b;
 
-        private double c;
+        private final double c;
     }
-
-    // @Test
-    // public void testSerialization() {
-    // Transcoder<TestBean> transcoder = new JavaNativeTranscoder<TestBean>();
-    // TestBean bean1 = new TestBean("Hello", 86, 12.34);
-    // TestBean bean2 = new TestBean("MINA", 94, 67.89);
-    // assertEquals(bean1, transcoder.decode(transcoder.encode(bean1)));
-    // assertEquals(bean2, transcoder.decode(transcoder.encode(bean2)));
-    // }
-    //
-    // @Test
-    // public void testEncodedSize() {
-    // Transcoder<TestBean> transcoder = new JavaNativeTranscoder<TestBean>();
-    // TestBean bean = new TestBean("Hello", 86, 12.34);
-    // int size = transcoder.getEncodedSize(bean);
-    // ByteBuffer out = ByteBuffer.allocate(size);
-    // transcoder.writeTo(bean, out);
-    // assertEquals(size, out.position());
-    // out.position(0);
-    // assertEquals(bean, transcoder.decode(out));
-    // }
-
+ 
     @Override
     public List<TestBean> getObjects() {
         List<TestBean> list = new LinkedList<TestBean>();

http://git-wip-us.apache.org/repos/asf/mina/blob/9638abef/codec/src/test/java/org/apache/mina/codec/delimited/serialization/ProtobufTest.java
----------------------------------------------------------------------
diff --git a/codec/src/test/java/org/apache/mina/codec/delimited/serialization/ProtobufTest.java
b/codec/src/test/java/org/apache/mina/codec/delimited/serialization/ProtobufTest.java
index 20c9028..95504a6 100644
--- a/codec/src/test/java/org/apache/mina/codec/delimited/serialization/ProtobufTest.java
+++ b/codec/src/test/java/org/apache/mina/codec/delimited/serialization/ProtobufTest.java
@@ -47,7 +47,7 @@ public class ProtobufTest extends GenericSerializerTest<Person> {
 
         return list;
     }
-
+ 
     @Override
     public ByteBufferDecoder<Person> getDecoder() throws Exception {
         return ProtobufMessageDecoder.newInstance(Person.class);


Mime
View raw message