refactor: minor cleanup

- replace explicit types by <>
- remove unnecessary interface modifiers
This commit is contained in:
Damien Arrachequesne
2021-04-26 11:06:57 +02:00
parent a4053e8645
commit 48fec45740
16 changed files with 104 additions and 104 deletions

View File

@@ -5,7 +5,7 @@ package io.socket.client;
*/
public interface Ack {
public void call(Object... args);
void call(Object... args);
}

View File

@@ -16,7 +16,7 @@ public class IO {
private static final Logger logger = Logger.getLogger(IO.class.getName());
private static final ConcurrentHashMap<String, Manager> managers = new ConcurrentHashMap<String, Manager>();
private static final ConcurrentHashMap<String, Manager> managers = new ConcurrentHashMap<>();
/**
* Protocol version.

View File

@@ -114,8 +114,8 @@ public class Manager extends Emitter {
opts.callFactory = defaultCallFactory;
}
this.opts = opts;
this.nsps = new ConcurrentHashMap<String, Socket>();
this.subs = new LinkedList<On.Handle>();
this.nsps = new ConcurrentHashMap<>();
this.subs = new LinkedList<>();
this.reconnection(opts.reconnection);
this.reconnectionAttempts(opts.reconnectionAttempts != 0 ? opts.reconnectionAttempts : Integer.MAX_VALUE);
this.reconnectionDelay(opts.reconnectionDelay != 0 ? opts.reconnectionDelay : 1000);
@@ -129,7 +129,7 @@ public class Manager extends Emitter {
this.readyState = ReadyState.CLOSED;
this.uri = uri;
this.encoding = false;
this.packetBuffer = new ArrayList<Packet>();
this.packetBuffer = new ArrayList<>();
this.encoder = opts.encoder != null ? opts.encoder : new IOParser.Encoder();
this.decoder = opts.decoder != null ? opts.decoder : new IOParser.Decoder();
}
@@ -555,9 +555,9 @@ public class Manager extends Emitter {
}
public static interface OpenCallback {
public interface OpenCallback {
public void call(Exception err);
void call(Exception err);
}

View File

@@ -16,8 +16,8 @@ public class On {
};
}
public static interface Handle {
public interface Handle {
public void destroy();
void destroy();
}
}

View File

@@ -58,10 +58,10 @@ public class Socket extends Emitter {
private String nsp;
private Manager io;
private Map<String, String> auth;
private Map<Integer, Ack> acks = new HashMap<Integer, Ack>();
private Map<Integer, Ack> acks = new HashMap<>();
private Queue<On.Handle> subs;
private final Queue<List<Object>> receiveBuffer = new LinkedList<List<Object>>();
private final Queue<Packet<JSONArray>> sendBuffer = new LinkedList<Packet<JSONArray>>();
private final Queue<List<Object>> receiveBuffer = new LinkedList<>();
private final Queue<Packet<JSONArray>> sendBuffer = new LinkedList<>();
public Socket(Manager io, String nsp, Manager.Options opts) {
this.io = io;
@@ -205,7 +205,7 @@ public class Socket extends Emitter {
}
}
Packet<JSONArray> packet = new Packet<JSONArray>(Parser.EVENT, jsonArgs);
Packet<JSONArray> packet = new Packet<>(Parser.EVENT, jsonArgs);
if (ack != null) {
logger.fine(String.format("emitting packet with ack id %d", ids));
@@ -302,7 +302,7 @@ public class Socket extends Emitter {
}
private void onevent(Packet<JSONArray> packet) {
List<Object> args = new ArrayList<Object>(Arrays.asList(toArray(packet.data)));
List<Object> args = new ArrayList<>(Arrays.asList(toArray(packet.data)));
if (logger.isLoggable(Level.FINE)) {
logger.fine(String.format("emitting event %s", args));
}
@@ -341,7 +341,7 @@ public class Socket extends Emitter {
jsonArgs.put(arg);
}
Packet<JSONArray> packet = new Packet<JSONArray>(Parser.ACK, jsonArgs);
Packet<JSONArray> packet = new Packet<>(Parser.ACK, jsonArgs);
packet.id = id;
self.packet(packet);
}

View File

@@ -20,7 +20,7 @@ public class Binary {
@SuppressWarnings("unchecked")
public static DeconstructedPacket deconstructPacket(Packet packet) {
List<byte[]> buffers = new ArrayList<byte[]>();
List<byte[]> buffers = new ArrayList<>();
packet.data = _deconstructPacket(packet.data, buffers);
packet.attachments = buffers.size();

View File

@@ -122,7 +122,7 @@ final public class IOParser implements Parser {
int i = 0;
int length = str.length();
Packet<Object> p = new Packet<Object>(Character.getNumericValue(str.charAt(0)));
Packet<Object> p = new Packet<>(Character.getNumericValue(str.charAt(0)));
if (p.type < 0 || p.type > types.length - 1) {
throw new DecodingException("unknown packet type " + p.type);
@@ -214,7 +214,7 @@ final public class IOParser implements Parser {
BinaryReconstructor(Packet packet) {
this.reconPack = packet;
this.buffers = new ArrayList<byte[]>();
this.buffers = new ArrayList<>();
}
public Packet takeBinaryData(byte[] binData) {
@@ -230,7 +230,7 @@ final public class IOParser implements Parser {
public void finishReconstruction () {
this.reconPack = null;
this.buffers = new ArrayList<byte[]>();
this.buffers = new ArrayList<>();
}
}
}

View File

@@ -5,44 +5,44 @@ public interface Parser {
/**
* Packet type `connect`.
*/
public static final int CONNECT = 0;
int CONNECT = 0;
/**
* Packet type `disconnect`.
*/
public static final int DISCONNECT = 1;
int DISCONNECT = 1;
/**
* Packet type `event`.
*/
public static final int EVENT = 2;
int EVENT = 2;
/**
* Packet type `ack`.
*/
public static final int ACK = 3;
int ACK = 3;
/**
* Packet type `error`.
*/
public static final int CONNECT_ERROR = 4;
int CONNECT_ERROR = 4;
/**
* Packet type `binary event`.
*/
public static final int BINARY_EVENT = 5;
int BINARY_EVENT = 5;
/**
* Packet type `binary ack`.
*/
public static final int BINARY_ACK = 6;
int BINARY_ACK = 6;
public static int protocol = 5;
int protocol = 5;
/**
* Packet types.
*/
public static String[] types = new String[] {
String[] types = new String[] {
"CONNECT",
"DISCONNECT",
"EVENT",
@@ -52,29 +52,29 @@ public interface Parser {
"BINARY_ACK"
};
public static interface Encoder {
interface Encoder {
public void encode(Packet obj, Callback callback);
void encode(Packet obj, Callback callback);
public interface Callback {
interface Callback {
public void call(Object[] data);
void call(Object[] data);
}
}
public static interface Decoder {
interface Decoder {
public void add(String obj);
void add(String obj);
public void add(byte[] obj);
void add(byte[] obj);
public void destroy();
void destroy();
public void onDecoded(Callback callback);
void onDecoded(Callback callback);
public interface Callback {
interface Callback {
public void call(Packet packet);
void call(Packet packet);
}
}
}

View File

@@ -108,7 +108,7 @@ public abstract class Connection {
}
String[] createEnv() {
Map<String, String> env = new HashMap<String, String>(System.getenv());
Map<String, String> env = new HashMap<>(System.getenv());
env.put("DEBUG", "socket.io:*");
env.put("PORT", String.valueOf(PORT));
String[] _env = new String[env.size()];

View File

@@ -30,7 +30,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void connectToLocalhost() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
@@ -71,7 +71,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void workWithAcks() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
@@ -112,7 +112,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void receiveDateWithAck() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@@ -137,7 +137,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void sendBinaryAck() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
final byte[] buf = "huehue".getBytes(Charset.forName("UTF-8"));
socket = client();
@@ -169,7 +169,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void receiveBinaryDataWithAck() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
final byte[] buf = "huehue".getBytes(Charset.forName("UTF-8"));
socket = client();
@@ -192,7 +192,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void workWithFalse() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
@@ -213,7 +213,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void receiveUTF8MultibyteCharacters() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
final String[] correct = new String[] {
"てすと",
"Я Б Г Д Ж Й",
@@ -246,7 +246,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void connectToNamespaceAfterConnectionEstablished() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
final Manager manager = new Manager(uri());
socket = manager.socket("/");
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@@ -271,7 +271,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void connectToNamespaceAfterConnectionGetsClosed() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
final Manager manager = new Manager(uri());
socket = manager.socket("/");
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@@ -300,7 +300,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void reconnectByDefault() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
socket = client();
socket.io().on(Manager.EVENT_RECONNECT, new Emitter.Listener() {
@Override
@@ -321,7 +321,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void reconnectManually() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
socket = client();
socket.once(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
@@ -347,7 +347,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void reconnectAutomaticallyAfterReconnectingManually() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
socket = client();
socket.once(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
@@ -379,7 +379,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = 14000)
public void attemptReconnectsAfterAFailedReconnect() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
IO.Options opts = createOptions();
opts.reconnection = true;
opts.timeout = 0;
@@ -416,7 +416,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void reconnectDelayShouldIncreaseEveryTime() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
IO.Options opts = createOptions();
opts.reconnection = true;
opts.timeout = 0;
@@ -466,7 +466,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void notReconnectWhenForceClosed() throws URISyntaxException, InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
IO.Options opts = createOptions();
opts.timeout = 0;
opts.reconnectionDelay = 10;
@@ -495,7 +495,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void stopReconnectingWhenForceClosed() throws URISyntaxException, InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
IO.Options opts = createOptions();
opts.timeout = 0;
opts.reconnectionDelay = 10;
@@ -525,7 +525,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void reconnectAfterStoppingReconnection() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
IO.Options opts = createOptions();
opts.forceNew = true;
opts.timeout = 0;
@@ -551,7 +551,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void stopReconnectingOnASocketAndKeepToReconnectOnAnother() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
final Manager manager = new Manager(uri());
final Socket socket1 = manager.socket("/");
final Socket socket2 = manager.socket("/asd");
@@ -597,7 +597,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void connectWhileDisconnectingAnotherSocket() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
final Manager manager = new Manager(uri());
final Socket socket1 = manager.socket("/foo");
@@ -624,7 +624,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void tryToReconnectTwiceAndFailWithIncorrectAddress() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
IO.Options opts = new IO.Options();
opts.reconnection = true;
opts.reconnectionAttempts = 2;
@@ -656,7 +656,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void tryToReconnectTwiceAndFailWithImmediateTimeout() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
IO.Options opts = new IO.Options();
opts.reconnection = true;
opts.timeout = 0;
@@ -689,7 +689,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void notTryToReconnectWithIncorrectPortWhenReconnectionDisabled() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
IO.Options opts = new IO.Options();
opts.reconnection = false;
final Manager manager = new Manager(URI.create("http://localhost:9823"), opts);
@@ -723,7 +723,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void fireReconnectEventsOnSocket() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
Manager.Options opts = new Manager.Options();
opts.reconnection = true;
@@ -758,7 +758,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void fireReconnectingWithAttemptsNumberWhenReconnectingTwice() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
Manager.Options opts = new Manager.Options();
opts.reconnection = true;
@@ -793,7 +793,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void emitDateAsString() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
@@ -814,7 +814,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void emitDateInObject() throws InterruptedException, JSONException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
@@ -844,7 +844,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void sendAndGetBinaryData() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
final byte[] buf = "asdfasdf".getBytes(Charset.forName("UTF-8"));
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@@ -866,7 +866,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void sendBinaryDataMixedWithJson() throws InterruptedException, JSONException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
final byte[] buf = "howdy".getBytes(Charset.forName("UTF-8"));
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@@ -899,7 +899,7 @@ public class ConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void sendEventsWithByteArraysInTheCorrectOrder() throws Exception {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
final byte[] buf = "abuff1".getBytes(Charset.forName("UTF-8"));
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {

View File

@@ -89,7 +89,7 @@ public class SSLConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void connect() throws Exception {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
IO.Options opts = createOptions();
opts.callFactory = sOkHttpClient;
opts.webSocketFactory = sOkHttpClient;
@@ -113,7 +113,7 @@ public class SSLConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void defaultSSLContext() throws Exception {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
IO.setDefaultOkHttpWebSocketFactory(sOkHttpClient);
IO.setDefaultOkHttpCallFactory(sOkHttpClient);
socket = client();

View File

@@ -26,7 +26,7 @@ public class ServerConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void openAndClose() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@@ -51,7 +51,7 @@ public class ServerConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void message() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@@ -74,7 +74,7 @@ public class ServerConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void event() throws Exception {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
final JSONObject obj = new JSONObject();
obj.put("foo", 1);
@@ -103,7 +103,7 @@ public class ServerConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void ack() throws Exception {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
final JSONObject obj = new JSONObject();
obj.put("foo", 1);
@@ -131,7 +131,7 @@ public class ServerConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void ackWithoutArgs() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@@ -153,7 +153,7 @@ public class ServerConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void ackWithoutArgsFromClient() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@@ -188,7 +188,7 @@ public class ServerConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void closeEngineConnection() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@@ -209,7 +209,7 @@ public class ServerConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void broadcast() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@@ -242,7 +242,7 @@ public class ServerConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void room() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@@ -266,7 +266,7 @@ public class ServerConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void pollingHeaders() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
IO.Options opts = createOptions();
opts.transports = new String[] {Polling.NAME};
@@ -301,7 +301,7 @@ public class ServerConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void websocketHandshakeHeaders() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
IO.Options opts = createOptions();
opts.transports = new String[] {WebSocket.NAME};
@@ -336,7 +336,7 @@ public class ServerConnectionTest extends Connection {
@Test(timeout = TIMEOUT)
public void disconnectFromServer() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {

View File

@@ -26,7 +26,7 @@ public class SocketTest extends Connection {
@Test(timeout = TIMEOUT)
public void shouldHaveAnAccessibleSocketIdEqualToServerSideSocketId() throws InterruptedException {
final BlockingQueue<Optional> values = new LinkedBlockingQueue<Optional>();
final BlockingQueue<Optional> values = new LinkedBlockingQueue<>();
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
@@ -45,7 +45,7 @@ public class SocketTest extends Connection {
@Test(timeout = TIMEOUT)
public void shouldHaveAnAccessibleSocketIdEqualToServerSideSocketIdOnCustomNamespace() throws InterruptedException {
final BlockingQueue<Optional> values = new LinkedBlockingQueue<Optional>();
final BlockingQueue<Optional> values = new LinkedBlockingQueue<>();
socket = client("/foo");
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
@@ -64,7 +64,7 @@ public class SocketTest extends Connection {
@Test(timeout = TIMEOUT)
public void clearsSocketIdUponDisconnection() throws InterruptedException {
final BlockingQueue<Optional> values = new LinkedBlockingQueue<Optional>();
final BlockingQueue<Optional> values = new LinkedBlockingQueue<>();
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
@@ -87,7 +87,7 @@ public class SocketTest extends Connection {
@Test(timeout = TIMEOUT)
public void doesNotFireConnectErrorIfWeForceDisconnectInOpeningState() throws InterruptedException {
final BlockingQueue<Optional> values = new LinkedBlockingQueue<Optional>();
final BlockingQueue<Optional> values = new LinkedBlockingQueue<>();
IO.Options opts = new IO.Options();
opts.timeout = 100;
socket = client(opts);
@@ -114,7 +114,7 @@ public class SocketTest extends Connection {
@Test(timeout = TIMEOUT)
public void shouldChangeSocketIdUponReconnection() throws InterruptedException {
final BlockingQueue<Optional> values = new LinkedBlockingQueue<Optional>();
final BlockingQueue<Optional> values = new LinkedBlockingQueue<>();
socket = client();
socket.once(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
@@ -155,7 +155,7 @@ public class SocketTest extends Connection {
@Test(timeout = TIMEOUT)
public void shouldAcceptAQueryStringOnDefaultNamespace() throws InterruptedException, JSONException {
final BlockingQueue<Optional> values = new LinkedBlockingQueue<Optional>();
final BlockingQueue<Optional> values = new LinkedBlockingQueue<>();
socket = client("/?c=d");
socket.emit("getHandshake", new Ack() {
@@ -176,7 +176,7 @@ public class SocketTest extends Connection {
@Test(timeout = TIMEOUT)
public void shouldAcceptAQueryString() throws InterruptedException, JSONException {
final BlockingQueue<Optional> values = new LinkedBlockingQueue<Optional>();
final BlockingQueue<Optional> values = new LinkedBlockingQueue<>();
socket = client("/abc?b=c&d=e");
socket.on("handshake", new Emitter.Listener() {
@@ -199,7 +199,7 @@ public class SocketTest extends Connection {
@Test(timeout = TIMEOUT)
public void shouldAcceptAnAuthOption() throws InterruptedException, JSONException {
final BlockingQueue<Optional> values = new LinkedBlockingQueue<Optional>();
final BlockingQueue<Optional> values = new LinkedBlockingQueue<>();
IO.Options opts = new IO.Options();
opts.auth = singletonMap("token", "abcd");
@@ -223,7 +223,7 @@ public class SocketTest extends Connection {
@Test(timeout = TIMEOUT)
public void shouldFireAnErrorEventOnMiddlewareFailure() throws InterruptedException, JSONException {
final BlockingQueue<Optional> values = new LinkedBlockingQueue<Optional>();
final BlockingQueue<Optional> values = new LinkedBlockingQueue<>();
socket = client("/no");
socket.on(Socket.EVENT_CONNECT_ERROR, new Emitter.Listener() {
@@ -245,7 +245,7 @@ public class SocketTest extends Connection {
@Test(timeout = TIMEOUT)
public void shouldThrowOnReservedEvent() {
final BlockingQueue<Optional> values = new LinkedBlockingQueue<Optional>();
final BlockingQueue<Optional> values = new LinkedBlockingQueue<>();
socket = client("/no");
try {

View File

@@ -20,7 +20,7 @@ public class ByteArrayTest {
@Test
public void encodeByteArray() {
Packet<byte[]> packet = new Packet<byte[]>(Parser.BINARY_EVENT);
Packet<byte[]> packet = new Packet<>(Parser.BINARY_EVENT);
packet.data = "abc".getBytes(Charset.forName("UTF-8"));
packet.id = 23;
packet.nsp = "/cool";
@@ -29,7 +29,7 @@ public class ByteArrayTest {
@Test
public void encodeByteArray2() {
Packet<byte[]> packet = new Packet<byte[]>(Parser.BINARY_EVENT);
Packet<byte[]> packet = new Packet<>(Parser.BINARY_EVENT);
packet.data = new byte[2];
packet.id = 0;
packet.nsp = "/";
@@ -42,7 +42,7 @@ public class ByteArrayTest {
data.getJSONObject("b").put("why", new byte[3]);
data.getJSONObject("c").getJSONObject("b").put("a", new byte[6]);
Packet<JSONObject> packet = new Packet<JSONObject>(Parser.BINARY_EVENT);
Packet<JSONObject> packet = new Packet<>(Parser.BINARY_EVENT);
packet.data = data;
packet.id = 999;
packet.nsp = "/deep";
@@ -54,7 +54,7 @@ public class ByteArrayTest {
JSONObject data = new JSONObject("{a: \"b\", c: 4, e: {g: null}, h: null}");
data.put("h", new byte[9]);
Packet<JSONObject> packet = new Packet<JSONObject>(Parser.BINARY_EVENT);
Packet<JSONObject> packet = new Packet<>(Parser.BINARY_EVENT);
packet.data = data;
packet.nsp = "/";
packet.id = 600;
@@ -66,7 +66,7 @@ public class ByteArrayTest {
JSONArray data = new JSONArray("[a, null, {}]");
data.put(1, "xxx".getBytes(Charset.forName("UTF-8")));
Packet<JSONArray> packet = new Packet<JSONArray>(Parser.BINARY_ACK);
Packet<JSONArray> packet = new Packet<>(Parser.BINARY_ACK);
packet.data = data;
packet.id = 127;
packet.nsp = "/back";
@@ -79,7 +79,7 @@ public class ByteArrayTest {
data.put(new byte[2]);
data.put(new byte[3]);
Packet<JSONArray> packet = new Packet<JSONArray>(Parser.BINARY_EVENT);
Packet<JSONArray> packet = new Packet<>(Parser.BINARY_EVENT);
packet.data = data;
packet.id = 0;
packet.nsp = "/";

View File

@@ -27,12 +27,12 @@ public class ParserTest {
@Test
public void encodeEvent() throws JSONException {
Packet<JSONArray> packet1 = new Packet<JSONArray>(Parser.EVENT);
Packet<JSONArray> packet1 = new Packet<>(Parser.EVENT);
packet1.data = new JSONArray("[\"a\", 1, {}]");
packet1.nsp = "/";
Helpers.test(packet1);
Packet<JSONArray> packet2 = new Packet<JSONArray>(Parser.EVENT);
Packet<JSONArray> packet2 = new Packet<>(Parser.EVENT);
packet2.data = new JSONArray("[\"a\", 1, {}]");
packet2.nsp = "/test";
Helpers.test(packet2);
@@ -40,7 +40,7 @@ public class ParserTest {
@Test
public void encodeAck() throws JSONException {
Packet<JSONArray> packet = new Packet<JSONArray>(Parser.ACK);
Packet<JSONArray> packet = new Packet<>(Parser.ACK);
packet.data = new JSONArray("[\"a\", 1, {}]");
packet.id = 123;
packet.nsp = "/";

View File

@@ -12,11 +12,11 @@ public class Optional<T> {
if (value == null) {
throw new NullPointerException();
}
return new Optional<T>(value);
return new Optional<>(value);
}
public static <T> Optional<T> ofNullable(T value) {
return new Optional<T>(value);
return new Optional<>(value);
}
public static Optional<Void> empty() {