From f10fefe2aed80255dbddf36307d13aaedd635619 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Tue, 27 May 2014 15:59:13 +0200 Subject: [PATCH] Clear a lot of compiler warnings because of unparameterized types. --- .../com/google/bitcoin/core/Sha256Hash.java | 5 +- .../PaymentChannelClientConnection.java | 6 +- .../PaymentChannelServerListener.java | 8 +-- .../ServerConnectionEventHandler.java | 4 +- .../bitcoin/net/NetworkAbstractionTests.java | 71 ++++++++++--------- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/core/src/main/java/com/google/bitcoin/core/Sha256Hash.java b/core/src/main/java/com/google/bitcoin/core/Sha256Hash.java index 0fdb4770..79d2b977 100644 --- a/core/src/main/java/com/google/bitcoin/core/Sha256Hash.java +++ b/core/src/main/java/com/google/bitcoin/core/Sha256Hash.java @@ -34,7 +34,7 @@ import static com.google.common.base.Preconditions.checkArgument; * A Sha256Hash just wraps a byte[] so that equals and hashcode work correctly, allowing it to be used as keys in a * map. It also checks that the length is correct and provides a bit more type safety. */ -public class Sha256Hash implements Serializable, Comparable { +public class Sha256Hash implements Serializable, Comparable { private byte[] bytes; public static final Sha256Hash ZERO_HASH = new Sha256Hash(new byte[32]); @@ -128,8 +128,7 @@ public class Sha256Hash implements Serializable, Comparable { } @Override - public int compareTo(Object o) { - checkArgument(o instanceof Sha256Hash); + public int compareTo(Sha256Hash o) { int thisCode = this.hashCode(); int oCode = ((Sha256Hash)o).hashCode(); return thisCode > oCode ? 1 : (thisCode == oCode ? 0 : -1); diff --git a/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelClientConnection.java b/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelClientConnection.java index 92ea7d56..4017afc0 100644 --- a/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelClientConnection.java +++ b/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelClientConnection.java @@ -88,7 +88,7 @@ public class PaymentChannelClientConnection { // And glue back in the opposite direction - network to the channelClient. wireParser = new ProtobufParser(new ProtobufParser.Listener() { @Override - public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { + public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { try { channelClient.receiveMessage(msg); } catch (InsufficientMoneyException e) { @@ -98,12 +98,12 @@ public class PaymentChannelClientConnection { } @Override - public void connectionOpen(ProtobufParser handler) { + public void connectionOpen(ProtobufParser handler) { channelClient.connectionOpen(); } @Override - public void connectionClosed(ProtobufParser handler) { + public void connectionClosed(ProtobufParser handler) { channelClient.connectionClosed(); channelOpenFuture.setException(new PaymentChannelCloseException("The TCP socket died", PaymentChannelCloseException.CloseReason.CONNECTION_CLOSED)); diff --git a/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelServerListener.java b/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelServerListener.java index d6bb3693..eba8d02e 100644 --- a/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelServerListener.java +++ b/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelServerListener.java @@ -89,12 +89,12 @@ public class PaymentChannelServerListener { protobufHandlerListener = new ProtobufParser.Listener() { @Override - public synchronized void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { + public synchronized void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { paymentChannelManager.receiveMessage(msg); } @Override - public synchronized void connectionClosed(ProtobufParser handler) { + public synchronized void connectionClosed(ProtobufParser handler) { paymentChannelManager.connectionClosed(); if (closeReason != null) eventHandler.channelClosed(closeReason); @@ -104,7 +104,7 @@ public class PaymentChannelServerListener { } @Override - public synchronized void connectionOpen(ProtobufParser handler) { + public synchronized void connectionOpen(ProtobufParser handler) { ServerConnectionEventHandler eventHandler = eventHandlerFactory.onNewConnection(address); if (eventHandler == null) handler.closeConnection(); @@ -141,7 +141,7 @@ public class PaymentChannelServerListener { public void bindAndStart(int port) throws Exception { server = new NioServer(new StreamParserFactory() { @Override - public ProtobufParser getNewParser(InetAddress inetAddress, int port) { + public ProtobufParser getNewParser(InetAddress inetAddress, int port) { return new ServerHandler(new InetSocketAddress(inetAddress, port), timeoutSeconds).socketProtobufHandler; } }, new InetSocketAddress(port)); diff --git a/core/src/main/java/com/google/bitcoin/protocols/channels/ServerConnectionEventHandler.java b/core/src/main/java/com/google/bitcoin/protocols/channels/ServerConnectionEventHandler.java index b9124c61..a1393e43 100644 --- a/core/src/main/java/com/google/bitcoin/protocols/channels/ServerConnectionEventHandler.java +++ b/core/src/main/java/com/google/bitcoin/protocols/channels/ServerConnectionEventHandler.java @@ -29,10 +29,10 @@ import javax.annotation.Nullable; * {@link PaymentChannelServerListener} */ public abstract class ServerConnectionEventHandler { - private ProtobufParser connectionChannel; + private ProtobufParser connectionChannel; // Called by ServerListener before channelOpen to set connectionChannel when it is ready to received application messages // Also called with null to clear connectionChannel after channelClosed() - synchronized void setConnectionChannel(@Nullable ProtobufParser connectionChannel) { this.connectionChannel = connectionChannel; } + synchronized void setConnectionChannel(@Nullable ProtobufParser connectionChannel) { this.connectionChannel = connectionChannel; } /** *

Closes the channel with the client (will generate a diff --git a/core/src/test/java/com/google/bitcoin/net/NetworkAbstractionTests.java b/core/src/test/java/com/google/bitcoin/net/NetworkAbstractionTests.java index 5e8a75d2..1f9994f9 100644 --- a/core/src/test/java/com/google/bitcoin/net/NetworkAbstractionTests.java +++ b/core/src/test/java/com/google/bitcoin/net/NetworkAbstractionTests.java @@ -21,6 +21,7 @@ import com.google.bitcoin.core.Utils; import com.google.common.util.concurrent.SettableFuture; import com.google.protobuf.ByteString; import org.bitcoin.paymentchannel.Protos; +import org.bitcoin.paymentchannel.Protos.TwoWayChannelMessage; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -62,7 +63,7 @@ public class NetworkAbstractionTests { channels = null; } - private MessageWriteTarget openConnection(SocketAddress addr, ProtobufParser parser) throws Exception { + private MessageWriteTarget openConnection(SocketAddress addr, ProtobufParser parser) throws Exception { if (clientType == 0 || clientType == 1) { channels.openConnection(addr, parser); if (parser.writeTarget.get() == null) @@ -98,7 +99,7 @@ public class NetworkAbstractionTests { final SettableFuture clientMessage2Received = SettableFuture.create(); NioServer server = new NioServer(new StreamParserFactory() { @Override - public ProtobufParser getNewParser(InetAddress inetAddress, int port) { + public ProtobufParser getNewParser(InetAddress inetAddress, int port) { return new ProtobufParser(new ProtobufParser.Listener() { @Override public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { @@ -107,12 +108,12 @@ public class NetworkAbstractionTests { } @Override - public void connectionOpen(ProtobufParser handler) { + public void connectionOpen(ProtobufParser handler) { serverConnectionOpen.set(null); } @Override - public void connectionClosed(ProtobufParser handler) { + public void connectionClosed(ProtobufParser handler) { serverConnectionClosed.set(null); } }, Protos.TwoWayChannelMessage.getDefaultInstance(), 1000, 0); @@ -124,7 +125,7 @@ public class NetworkAbstractionTests { ProtobufParser clientHandler = new ProtobufParser( new ProtobufParser.Listener() { @Override - public synchronized void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { + public synchronized void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { if (clientMessage1Received.isDone()) clientMessage2Received.set(msg); else @@ -132,12 +133,12 @@ public class NetworkAbstractionTests { } @Override - public void connectionOpen(ProtobufParser handler) { + public void connectionOpen(ProtobufParser handler) { clientConnectionOpen.set(null); } @Override - public void connectionClosed(ProtobufParser handler) { + public void connectionClosed(ProtobufParser handler) { clientConnectionClosed.set(null); } }, Protos.TwoWayChannelMessage.getDefaultInstance(), 1000, 0); @@ -176,15 +177,15 @@ public class NetworkAbstractionTests { final SettableFuture clientConnection2Closed = SettableFuture.create(); NioServer server = new NioServer(new StreamParserFactory() { @Override - public ProtobufParser getNewParser(InetAddress inetAddress, int port) { + public ProtobufParser getNewParser(InetAddress inetAddress, int port) { return new ProtobufParser(new ProtobufParser.Listener() { @Override - public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { + public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { fail.set(true); } @Override - public synchronized void connectionOpen(ProtobufParser handler) { + public synchronized void connectionOpen(ProtobufParser handler) { if (serverConnection1Open.isDone()) { handler.setSocketTimeout(0); serverConnection2Open.set(null); @@ -193,7 +194,7 @@ public class NetworkAbstractionTests { } @Override - public synchronized void connectionClosed(ProtobufParser handler) { + public synchronized void connectionClosed(ProtobufParser handler) { if (serverConnection1Closed.isDone()) { serverConnection2Closed.set(null); } else @@ -208,17 +209,17 @@ public class NetworkAbstractionTests { openConnection(new InetSocketAddress("localhost", 4243), new ProtobufParser( new ProtobufParser.Listener() { @Override - public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { + public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { fail.set(true); } @Override - public void connectionOpen(ProtobufParser handler) { + public void connectionOpen(ProtobufParser handler) { clientConnection1Open.set(null); } @Override - public void connectionClosed(ProtobufParser handler) { + public void connectionClosed(ProtobufParser handler) { clientConnection1Closed.set(null); } }, Protos.TwoWayChannelMessage.getDefaultInstance(), 1000, 0)); @@ -233,17 +234,17 @@ public class NetworkAbstractionTests { ProtobufParser client2Handler = new ProtobufParser( new ProtobufParser.Listener() { @Override - public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { + public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { fail.set(true); } @Override - public void connectionOpen(ProtobufParser handler) { + public void connectionOpen(ProtobufParser handler) { clientConnection2Open.set(null); } @Override - public void connectionClosed(ProtobufParser handler) { + public void connectionClosed(ProtobufParser handler) { clientConnection2Closed.set(null); } }, Protos.TwoWayChannelMessage.getDefaultInstance(), 1000, 0); @@ -275,7 +276,7 @@ public class NetworkAbstractionTests { final SettableFuture clientMessage4Received = SettableFuture.create(); NioServer server = new NioServer(new StreamParserFactory() { @Override - public ProtobufParser getNewParser(InetAddress inetAddress, int port) { + public ProtobufParser getNewParser(InetAddress inetAddress, int port) { return new ProtobufParser(new ProtobufParser.Listener() { @Override public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { @@ -283,12 +284,12 @@ public class NetworkAbstractionTests { } @Override - public void connectionOpen(ProtobufParser handler) { + public void connectionOpen(ProtobufParser handler) { serverConnectionOpen.set(null); } @Override - public void connectionClosed(ProtobufParser handler) { + public void connectionClosed(ProtobufParser handler) { serverConnectionClosed.set(null); } }, Protos.TwoWayChannelMessage.getDefaultInstance(), 0x10000, 0); @@ -300,7 +301,7 @@ public class NetworkAbstractionTests { ProtobufParser clientHandler = new ProtobufParser( new ProtobufParser.Listener() { @Override - public synchronized void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { + public synchronized void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { if (clientMessage1Received.isDone()) { if (clientMessage2Received.isDone()) { if (clientMessage3Received.isDone()) { @@ -316,12 +317,12 @@ public class NetworkAbstractionTests { } @Override - public void connectionOpen(ProtobufParser handler) { + public void connectionOpen(ProtobufParser handler) { clientConnectionOpen.set(null); } @Override - public void connectionClosed(ProtobufParser handler) { + public void connectionClosed(ProtobufParser handler) { clientConnectionClosed.set(null); } }, Protos.TwoWayChannelMessage.getDefaultInstance(), 0x10000, 0); @@ -426,7 +427,7 @@ public class NetworkAbstractionTests { final SettableFuture client3MessageReceived = SettableFuture.create(); NioServer server = new NioServer(new StreamParserFactory() { @Override - public ProtobufParser getNewParser(InetAddress inetAddress, int port) { + public ProtobufParser getNewParser(InetAddress inetAddress, int port) { return new ProtobufParser(new ProtobufParser.Listener() { @Override public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { @@ -434,7 +435,7 @@ public class NetworkAbstractionTests { } @Override - public synchronized void connectionOpen(ProtobufParser handler) { + public synchronized void connectionOpen(ProtobufParser handler) { if (serverConnection1Open.isDone()) { if (serverConnection2Open.isDone()) serverConnection3Open.set(null); @@ -445,7 +446,7 @@ public class NetworkAbstractionTests { } @Override - public synchronized void connectionClosed(ProtobufParser handler) { + public synchronized void connectionClosed(ProtobufParser handler) { if (serverConnectionClosed1.isDone()) { if (serverConnectionClosed2.isDone()) { checkState(!serverConnectionClosed3.isDone()); @@ -464,17 +465,17 @@ public class NetworkAbstractionTests { ProtobufParser client1Handler = new ProtobufParser( new ProtobufParser.Listener() { @Override - public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { + public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { client1MessageReceived.set(msg); } @Override - public void connectionOpen(ProtobufParser handler) { + public void connectionOpen(ProtobufParser handler) { client1ConnectionOpen.set(null); } @Override - public void connectionClosed(ProtobufParser handler) { + public void connectionClosed(ProtobufParser handler) { client1ConnectionClosed.set(null); } }, Protos.TwoWayChannelMessage.getDefaultInstance(), 1000, 0); @@ -486,17 +487,17 @@ public class NetworkAbstractionTests { ProtobufParser client2Handler = new ProtobufParser( new ProtobufParser.Listener() { @Override - public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { + public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { client2MessageReceived.set(msg); } @Override - public void connectionOpen(ProtobufParser handler) { + public void connectionOpen(ProtobufParser handler) { client2ConnectionOpen.set(null); } @Override - public void connectionClosed(ProtobufParser handler) { + public void connectionClosed(ProtobufParser handler) { client2ConnectionClosed.set(null); } }, Protos.TwoWayChannelMessage.getDefaultInstance(), 1000, 0); @@ -508,17 +509,17 @@ public class NetworkAbstractionTests { ProtobufParser client3Handler = new ProtobufParser( new ProtobufParser.Listener() { @Override - public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { + public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) { client3MessageReceived.set(msg); } @Override - public void connectionOpen(ProtobufParser handler) { + public void connectionOpen(ProtobufParser handler) { client3ConnectionOpen.set(null); } @Override - public synchronized void connectionClosed(ProtobufParser handler) { + public synchronized void connectionClosed(ProtobufParser handler) { checkState(!client3ConnectionClosed.isDone()); client3ConnectionClosed.set(null); }