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);
}
}
}