Clear a lot of compiler warnings because of unparameterized types.

This commit is contained in:
Andreas Schildbach 2014-05-27 15:59:13 +02:00
parent d4c1a1b043
commit f10fefe2ae
5 changed files with 47 additions and 47 deletions

View File

@ -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<Sha256Hash> {
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);

View File

@ -88,7 +88,7 @@ public class PaymentChannelClientConnection {
// And glue back in the opposite direction - network to the channelClient.
wireParser = new ProtobufParser<Protos.TwoWayChannelMessage>(new ProtobufParser.Listener<Protos.TwoWayChannelMessage>() {
@Override
public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) {
public void messageReceived(ProtobufParser<Protos.TwoWayChannelMessage> 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<Protos.TwoWayChannelMessage> handler) {
channelClient.connectionOpen();
}
@Override
public void connectionClosed(ProtobufParser handler) {
public void connectionClosed(ProtobufParser<Protos.TwoWayChannelMessage> handler) {
channelClient.connectionClosed();
channelOpenFuture.setException(new PaymentChannelCloseException("The TCP socket died",
PaymentChannelCloseException.CloseReason.CONNECTION_CLOSED));

View File

@ -89,12 +89,12 @@ public class PaymentChannelServerListener {
protobufHandlerListener = new ProtobufParser.Listener<Protos.TwoWayChannelMessage>() {
@Override
public synchronized void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) {
public synchronized void messageReceived(ProtobufParser<Protos.TwoWayChannelMessage> handler, Protos.TwoWayChannelMessage msg) {
paymentChannelManager.receiveMessage(msg);
}
@Override
public synchronized void connectionClosed(ProtobufParser handler) {
public synchronized void connectionClosed(ProtobufParser<Protos.TwoWayChannelMessage> 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<Protos.TwoWayChannelMessage> 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<Protos.TwoWayChannelMessage> getNewParser(InetAddress inetAddress, int port) {
return new ServerHandler(new InetSocketAddress(inetAddress, port), timeoutSeconds).socketProtobufHandler;
}
}, new InetSocketAddress(port));

View File

@ -29,10 +29,10 @@ import javax.annotation.Nullable;
* {@link PaymentChannelServerListener}
*/
public abstract class ServerConnectionEventHandler {
private ProtobufParser connectionChannel;
private ProtobufParser<Protos.TwoWayChannelMessage> 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<Protos.TwoWayChannelMessage> connectionChannel) { this.connectionChannel = connectionChannel; }
/**
* <p>Closes the channel with the client (will generate a

View File

@ -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<Protos.TwoWayChannelMessage> 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<Protos.TwoWayChannelMessage> clientMessage2Received = SettableFuture.create();
NioServer server = new NioServer(new StreamParserFactory() {
@Override
public ProtobufParser getNewParser(InetAddress inetAddress, int port) {
public ProtobufParser<TwoWayChannelMessage> getNewParser(InetAddress inetAddress, int port) {
return new ProtobufParser<Protos.TwoWayChannelMessage>(new ProtobufParser.Listener<Protos.TwoWayChannelMessage>() {
@Override
public void messageReceived(ProtobufParser<Protos.TwoWayChannelMessage> handler, Protos.TwoWayChannelMessage msg) {
@ -107,12 +108,12 @@ public class NetworkAbstractionTests {
}
@Override
public void connectionOpen(ProtobufParser handler) {
public void connectionOpen(ProtobufParser<Protos.TwoWayChannelMessage> handler) {
serverConnectionOpen.set(null);
}
@Override
public void connectionClosed(ProtobufParser handler) {
public void connectionClosed(ProtobufParser<Protos.TwoWayChannelMessage> handler) {
serverConnectionClosed.set(null);
}
}, Protos.TwoWayChannelMessage.getDefaultInstance(), 1000, 0);
@ -124,7 +125,7 @@ public class NetworkAbstractionTests {
ProtobufParser<Protos.TwoWayChannelMessage> clientHandler = new ProtobufParser<Protos.TwoWayChannelMessage>(
new ProtobufParser.Listener<Protos.TwoWayChannelMessage>() {
@Override
public synchronized void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) {
public synchronized void messageReceived(ProtobufParser<Protos.TwoWayChannelMessage> 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<Protos.TwoWayChannelMessage> handler) {
clientConnectionOpen.set(null);
}
@Override
public void connectionClosed(ProtobufParser handler) {
public void connectionClosed(ProtobufParser<Protos.TwoWayChannelMessage> handler) {
clientConnectionClosed.set(null);
}
}, Protos.TwoWayChannelMessage.getDefaultInstance(), 1000, 0);
@ -176,15 +177,15 @@ public class NetworkAbstractionTests {
final SettableFuture<Void> clientConnection2Closed = SettableFuture.create();
NioServer server = new NioServer(new StreamParserFactory() {
@Override
public ProtobufParser getNewParser(InetAddress inetAddress, int port) {
public ProtobufParser<Protos.TwoWayChannelMessage> getNewParser(InetAddress inetAddress, int port) {
return new ProtobufParser<Protos.TwoWayChannelMessage>(new ProtobufParser.Listener<Protos.TwoWayChannelMessage>() {
@Override
public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) {
public void messageReceived(ProtobufParser<Protos.TwoWayChannelMessage> handler, Protos.TwoWayChannelMessage msg) {
fail.set(true);
}
@Override
public synchronized void connectionOpen(ProtobufParser handler) {
public synchronized void connectionOpen(ProtobufParser<Protos.TwoWayChannelMessage> 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<Protos.TwoWayChannelMessage> handler) {
if (serverConnection1Closed.isDone()) {
serverConnection2Closed.set(null);
} else
@ -208,17 +209,17 @@ public class NetworkAbstractionTests {
openConnection(new InetSocketAddress("localhost", 4243), new ProtobufParser<Protos.TwoWayChannelMessage>(
new ProtobufParser.Listener<Protos.TwoWayChannelMessage>() {
@Override
public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) {
public void messageReceived(ProtobufParser<Protos.TwoWayChannelMessage> handler, Protos.TwoWayChannelMessage msg) {
fail.set(true);
}
@Override
public void connectionOpen(ProtobufParser handler) {
public void connectionOpen(ProtobufParser<Protos.TwoWayChannelMessage> handler) {
clientConnection1Open.set(null);
}
@Override
public void connectionClosed(ProtobufParser handler) {
public void connectionClosed(ProtobufParser<Protos.TwoWayChannelMessage> handler) {
clientConnection1Closed.set(null);
}
}, Protos.TwoWayChannelMessage.getDefaultInstance(), 1000, 0));
@ -233,17 +234,17 @@ public class NetworkAbstractionTests {
ProtobufParser<Protos.TwoWayChannelMessage> client2Handler = new ProtobufParser<Protos.TwoWayChannelMessage>(
new ProtobufParser.Listener<Protos.TwoWayChannelMessage>() {
@Override
public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) {
public void messageReceived(ProtobufParser<Protos.TwoWayChannelMessage> handler, Protos.TwoWayChannelMessage msg) {
fail.set(true);
}
@Override
public void connectionOpen(ProtobufParser handler) {
public void connectionOpen(ProtobufParser<Protos.TwoWayChannelMessage> handler) {
clientConnection2Open.set(null);
}
@Override
public void connectionClosed(ProtobufParser handler) {
public void connectionClosed(ProtobufParser<Protos.TwoWayChannelMessage> handler) {
clientConnection2Closed.set(null);
}
}, Protos.TwoWayChannelMessage.getDefaultInstance(), 1000, 0);
@ -275,7 +276,7 @@ public class NetworkAbstractionTests {
final SettableFuture<Protos.TwoWayChannelMessage> clientMessage4Received = SettableFuture.create();
NioServer server = new NioServer(new StreamParserFactory() {
@Override
public ProtobufParser getNewParser(InetAddress inetAddress, int port) {
public ProtobufParser<Protos.TwoWayChannelMessage> getNewParser(InetAddress inetAddress, int port) {
return new ProtobufParser<Protos.TwoWayChannelMessage>(new ProtobufParser.Listener<Protos.TwoWayChannelMessage>() {
@Override
public void messageReceived(ProtobufParser<Protos.TwoWayChannelMessage> handler, Protos.TwoWayChannelMessage msg) {
@ -283,12 +284,12 @@ public class NetworkAbstractionTests {
}
@Override
public void connectionOpen(ProtobufParser handler) {
public void connectionOpen(ProtobufParser<Protos.TwoWayChannelMessage> handler) {
serverConnectionOpen.set(null);
}
@Override
public void connectionClosed(ProtobufParser handler) {
public void connectionClosed(ProtobufParser<Protos.TwoWayChannelMessage> handler) {
serverConnectionClosed.set(null);
}
}, Protos.TwoWayChannelMessage.getDefaultInstance(), 0x10000, 0);
@ -300,7 +301,7 @@ public class NetworkAbstractionTests {
ProtobufParser<Protos.TwoWayChannelMessage> clientHandler = new ProtobufParser<Protos.TwoWayChannelMessage>(
new ProtobufParser.Listener<Protos.TwoWayChannelMessage>() {
@Override
public synchronized void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) {
public synchronized void messageReceived(ProtobufParser<Protos.TwoWayChannelMessage> 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<Protos.TwoWayChannelMessage> handler) {
clientConnectionOpen.set(null);
}
@Override
public void connectionClosed(ProtobufParser handler) {
public void connectionClosed(ProtobufParser<Protos.TwoWayChannelMessage> handler) {
clientConnectionClosed.set(null);
}
}, Protos.TwoWayChannelMessage.getDefaultInstance(), 0x10000, 0);
@ -426,7 +427,7 @@ public class NetworkAbstractionTests {
final SettableFuture<Protos.TwoWayChannelMessage> client3MessageReceived = SettableFuture.create();
NioServer server = new NioServer(new StreamParserFactory() {
@Override
public ProtobufParser getNewParser(InetAddress inetAddress, int port) {
public ProtobufParser<Protos.TwoWayChannelMessage> getNewParser(InetAddress inetAddress, int port) {
return new ProtobufParser<Protos.TwoWayChannelMessage>(new ProtobufParser.Listener<Protos.TwoWayChannelMessage>() {
@Override
public void messageReceived(ProtobufParser<Protos.TwoWayChannelMessage> handler, Protos.TwoWayChannelMessage msg) {
@ -434,7 +435,7 @@ public class NetworkAbstractionTests {
}
@Override
public synchronized void connectionOpen(ProtobufParser handler) {
public synchronized void connectionOpen(ProtobufParser<Protos.TwoWayChannelMessage> 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<Protos.TwoWayChannelMessage> handler) {
if (serverConnectionClosed1.isDone()) {
if (serverConnectionClosed2.isDone()) {
checkState(!serverConnectionClosed3.isDone());
@ -464,17 +465,17 @@ public class NetworkAbstractionTests {
ProtobufParser<Protos.TwoWayChannelMessage> client1Handler = new ProtobufParser<Protos.TwoWayChannelMessage>(
new ProtobufParser.Listener<Protos.TwoWayChannelMessage>() {
@Override
public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) {
public void messageReceived(ProtobufParser<Protos.TwoWayChannelMessage> handler, Protos.TwoWayChannelMessage msg) {
client1MessageReceived.set(msg);
}
@Override
public void connectionOpen(ProtobufParser handler) {
public void connectionOpen(ProtobufParser<Protos.TwoWayChannelMessage> handler) {
client1ConnectionOpen.set(null);
}
@Override
public void connectionClosed(ProtobufParser handler) {
public void connectionClosed(ProtobufParser<Protos.TwoWayChannelMessage> handler) {
client1ConnectionClosed.set(null);
}
}, Protos.TwoWayChannelMessage.getDefaultInstance(), 1000, 0);
@ -486,17 +487,17 @@ public class NetworkAbstractionTests {
ProtobufParser<Protos.TwoWayChannelMessage> client2Handler = new ProtobufParser<Protos.TwoWayChannelMessage>(
new ProtobufParser.Listener<Protos.TwoWayChannelMessage>() {
@Override
public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) {
public void messageReceived(ProtobufParser<Protos.TwoWayChannelMessage> handler, Protos.TwoWayChannelMessage msg) {
client2MessageReceived.set(msg);
}
@Override
public void connectionOpen(ProtobufParser handler) {
public void connectionOpen(ProtobufParser<Protos.TwoWayChannelMessage> handler) {
client2ConnectionOpen.set(null);
}
@Override
public void connectionClosed(ProtobufParser handler) {
public void connectionClosed(ProtobufParser<Protos.TwoWayChannelMessage> handler) {
client2ConnectionClosed.set(null);
}
}, Protos.TwoWayChannelMessage.getDefaultInstance(), 1000, 0);
@ -508,17 +509,17 @@ public class NetworkAbstractionTests {
ProtobufParser<Protos.TwoWayChannelMessage> client3Handler = new ProtobufParser<Protos.TwoWayChannelMessage>(
new ProtobufParser.Listener<Protos.TwoWayChannelMessage>() {
@Override
public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) {
public void messageReceived(ProtobufParser<Protos.TwoWayChannelMessage> handler, Protos.TwoWayChannelMessage msg) {
client3MessageReceived.set(msg);
}
@Override
public void connectionOpen(ProtobufParser handler) {
public void connectionOpen(ProtobufParser<Protos.TwoWayChannelMessage> handler) {
client3ConnectionOpen.set(null);
}
@Override
public synchronized void connectionClosed(ProtobufParser handler) {
public synchronized void connectionClosed(ProtobufParser<Protos.TwoWayChannelMessage> handler) {
checkState(!client3ConnectionClosed.isDone());
client3ConnectionClosed.set(null);
}