Skip to content

Commit 3b7446e

Browse files
Fixed some warning and small issues
Change-Id: I132e3bcb46328e26b36f66a63246212565d33cae
1 parent 2a7d9f3 commit 3b7446e

10 files changed

Lines changed: 96 additions & 94 deletions

File tree

AndroidSocketIO/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies {
2626
compile "javax.inject:javax.inject:1"
2727
}
2828

29-
def baseVersionName = "1.1"
29+
def baseVersionName = "1.1.1"
3030
if (project.hasProperty("versionSuffix")) {
3131
project.ext.versionSuffix = project.versionSuffix
3232
} else {

AndroidSocketIO/src/com/appunite/socketio/IOMessage.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.appunite.socketio;
1818

1919
import static com.google.common.base.Preconditions.checkArgument;
20+
import static com.google.common.base.Preconditions.checkNotNull;
2021

2122

2223
import com.google.common.base.Optional;
@@ -55,20 +56,20 @@ public IOMessage(int messageType, String messageId) {
5556
}
5657

5758
public IOMessage(int messageType, String messageId, String messageEndpoint) {
58-
checkArgument(MSG_DISCONNECT >= 0 && messageType <= MSG_NOP, "Unknown message type");
59-
checkArgument(messageId != null, "message could not be null");
60-
checkArgument(messageEndpoint != null, "message endpoint could not be null");
59+
checkArgument((messageType >= MSG_DISCONNECT) && (messageType <= MSG_NOP), "Unknown message type");
60+
checkNotNull(messageId, "message could not be null");
61+
checkNotNull(messageEndpoint, "message endpoint could not be null");
6162
this.mMessageType = messageType;
6263
this.mMessageId = messageId;
6364
this.mMessageEndpoint = messageEndpoint;
6465
this.mMessageData = Optional.absent();
6566
}
6667

6768
public IOMessage(int messageType, String messageId, String messageEndpoint, String messageData) {
68-
checkArgument(MSG_DISCONNECT >= 0 && messageType <= MSG_NOP, "Unknown message type");
69-
checkArgument(messageId != null, "message could not be null");
70-
checkArgument(messageEndpoint != null, "message endpoint could not be null");
71-
checkArgument(messageData != null, "messag could not be null");
69+
checkArgument(messageType >= MSG_DISCONNECT && messageType <= MSG_NOP, "Unknown message type");
70+
checkNotNull(messageId, "message could not be null");
71+
checkNotNull(messageEndpoint, "message endpoint could not be null");
72+
checkNotNull(messageData, "messag could not be null");
7273
this.mMessageType = messageType;
7374
this.mMessageId = messageId;
7475
this.mMessageEndpoint = messageEndpoint;
@@ -77,22 +78,15 @@ public IOMessage(int messageType, String messageId, String messageEndpoint, Stri
7778

7879
@Override
7980
public String toString() {
80-
return new StringBuilder().append("Type: ").append(mMessageType)
81-
.append(", Id: ").append(mMessageId).append(", Endpoint: ")
82-
.append(mMessageEndpoint).append(", Data: ")
83-
.append(mMessageData).toString();
81+
return "Type: " + mMessageType + ", Id: " + mMessageId + ", Endpoint: " + mMessageEndpoint + ", Data: " + mMessageData;
8482
}
8583

8684
public String getMessage() {
87-
return new StringBuilder().append(mMessageType).append(':')
88-
.append(mMessageId)
89-
.append(':').append(mMessageEndpoint).append(':')
90-
.append(mMessageData.isPresent() ? mMessageData.get() : "")
91-
.toString();
85+
return String.valueOf(mMessageType) + ':' + mMessageId + ':' + mMessageEndpoint + ':' + (mMessageData.isPresent() ? mMessageData.get() : "");
9286
}
9387

9488
public static IOMessage parse(String message) throws WrongSocketIOResponse {
95-
checkArgument(message != null, "Message should not be null");
89+
checkNotNull(message, "Message should not be null");
9690
int messageTypeEnd = message.indexOf(':');
9791
if (messageTypeEnd < 1) {
9892
throw new WrongSocketIOResponse("Wrong response from socket io");

AndroidSocketIO/src/com/appunite/socketio/SocketBase.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
import com.appunite.socketio.helpers.HTTPUtils.WrongHttpResponseCode;
2828
import com.appunite.websocket.WrongWebsocketResponse;
29+
30+
import javax.annotation.Nonnull;
31+
2932
import static com.google.common.base.Preconditions.*;
3033

3134
/**
@@ -50,18 +53,18 @@ public SocketHandler(SocketBase socketBase) {
5053
}
5154

5255
@Override
53-
public void dispatchMessage(Message msg) {
56+
public void dispatchMessage(@Nonnull Message msg) {
5457
mSocketBase.handlerMessage(msg);
5558
}
5659

5760
}
5861

59-
private Object mStartStopLock = new Object();
62+
private final Object mStartStopLock = new Object();
6063
private Thread mThread = null;
6164

6265
protected final SocketListener mListener;
6366

64-
protected Object mInterruptionLock = new Object();
67+
protected final Object mInterruptionLock = new Object();
6568
protected boolean mInterrupted = true;
6669

6770
private SocketHandler mHandler;
@@ -75,7 +78,7 @@ public SocketBase(SocketListener listener) {
7578
/**
7679
* Receive message on connect method thread
7780
*
78-
* @param msg
81+
* @param msg message
7982
*/
8083
public abstract void handlerMessage(Message msg);
8184

@@ -85,7 +88,7 @@ public SocketBase(SocketListener listener) {
8588
public void connect() {
8689
synchronized (mStartStopLock) {
8790
checkState(mThread == null, "You are already connected/connecting");
88-
assert (mInterrupted == true);
91+
checkState(mInterrupted);
8992
mInterrupted = false;
9093
mHandler = new SocketHandler(this);
9194
mThread = new Thread(this);
@@ -112,7 +115,8 @@ public boolean isAlive() {
112115
*
113116
* (Thread safe)
114117
*/
115-
public void disconnectAsyncIfAlive() {
118+
@SuppressWarnings("UnusedDeclaration")
119+
public void disconnectAsyncIfAlive() {
116120
new Thread(new Runnable() {
117121

118122
@Override
@@ -139,7 +143,7 @@ public boolean disconnectIfAlive() {
139143
throw new RuntimeException(
140144
"disconnectIfAlive could not be called from socket thread");
141145
}
142-
assert (mInterrupted == false);
146+
checkState(!mInterrupted);
143147
synchronized (mInterruptionLock) {
144148
mInterrupted = true;
145149
interrupt();
@@ -149,7 +153,7 @@ public boolean disconnectIfAlive() {
149153
mThread.join();
150154
// Loop until success
151155
break;
152-
} catch (InterruptedException e) {
156+
} catch (InterruptedException ignore) {
153157
}
154158
}
155159
mHandler.removeCallbacksAndMessages(null);
@@ -166,7 +170,7 @@ public void run() {
166170
synchronized (mInterruptionLock) {
167171
boolean reconnect = mListener.onDisconnected(mInterrupted);
168172
if (mInterrupted) {
169-
checkState(reconnect == false,
173+
checkState(!reconnect,
170174
"If disconnection is forced by user reconnect value should be always false");
171175
}
172176
if (!reconnect)

AndroidSocketIO/src/com/appunite/socketio/SocketIO.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ public void registerToEndpoint(String endpoint) throws IOException,
9999
sendMessage(new IOMessage(IOMessage.MSG_CONNECT, "", endpoint));
100100
}
101101

102-
@Override
102+
@SuppressWarnings("StatementWithEmptyBody")
103+
@Override
103104
public void onStringMessage(String message) throws IOException,
104105
InterruptedException, NotConnectedException {
105106
try {
@@ -108,7 +109,7 @@ public void onStringMessage(String message) throws IOException,
108109
}
109110
IOMessage msg = IOMessage.parse(message);
110111
redelayKill();
111-
if (msg.mMessageType == IOMessage.MSG_DISCONNECT) {
112+
if (msg.mMessageType == IOMessage.MSG_DISCONNECT) {
112113
// TODO Im not quite sure what we have to do if we will receive
113114
// message like this - maybe we will implement this later
114115
} else if (msg.mMessageType == IOMessage.MSG_CONNECT) {
@@ -250,8 +251,8 @@ public void sendStringMessage(String messageEndpoint, String message) throws IOE
250251
@Override
251252
public void sendJsonMessage(String messageEndpoint, JSONObject object) throws IOException,
252253
InterruptedException, NotConnectedException {
253-
checkArgument(object != null, "Object could not be null");
254-
checkArgument(messageEndpoint != null, "Message endpoint could not be null");
254+
checkNotNull(object, "Object could not be null");
255+
checkNotNull(messageEndpoint, "Message endpoint could not be null");
255256
IOMessage msg = new IOMessage(IOMessage.MSG_MESSAGE, "", messageEndpoint,
256257
object.toString());
257258
sendMessage(msg);
@@ -263,9 +264,9 @@ public void sendJsonMessage(String messageEndpoint, JSONObject object) throws IO
263264
@Override
264265
public void sendJsonEvent(String messageEndpoint, String name, JSONArray args) throws IOException,
265266
InterruptedException, NotConnectedException {
266-
checkArgument(messageEndpoint != null, "Message endpoint could not be null");
267-
checkArgument(args != null, "Args could not be null");
268-
checkArgument(name != null, "Name could not be null");
267+
checkNotNull(messageEndpoint, "Message endpoint could not be null");
268+
checkNotNull(args, "Args could not be null");
269+
checkNotNull(name, "Name could not be null");
269270
checkArgument(!DISALLOWED_NAMES.contains(name),
270271
"Name could not be one of the reserved values: "
271272
+ DISALLOWED_NAMES.toString());

AndroidSocketIO/src/com/appunite/socketio/SocketIOBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import com.google.common.collect.ImmutableSet;
3939

4040
/**
41-
* Base class for {@link SocketIO}. Its ask socketio server for websocket
41+
* Base class for {@link SocketIO}. Its ask socketIO server for websocket
4242
* connection.
4343
*
4444
* @author Jacek Marchwicki <jacek.marchwicki@gmail.com>

AndroidSocketIO/src/com/appunite/socketio/SocketListener.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public interface SocketListener {
3535
/**
3636
* Occurs when connection was established. Called on Socket thread
3737
*
38-
* @param socketWriter
38+
* @param socketWriter socket writer
3939
* @throws IOException
4040
* can be thrown when socket exception occur
4141
* @throws InterruptedException
@@ -100,7 +100,7 @@ public void onReceivedEvent(String name, JSONArray args)
100100
*
101101
* Called on socket thread.
102102
*
103-
* @param object
103+
* @param object received json message
104104
* @throws IOException
105105
* can be thrown when socket exception occur
106106
* @throws InterruptedException
@@ -116,7 +116,7 @@ public void onReceivedJsonMessage(JSONObject object) throws IOException,
116116
*
117117
* Called on socket thread.
118118
*
119-
* @param string
119+
* @param string received string message
120120
* @throws IOException
121121
* can be thrown when socket exception occur
122122
* @throws InterruptedException
@@ -133,7 +133,7 @@ public void onReceivedStringMessage(String string) throws IOException,
133133
*
134134
* Called on socket thread.
135135
*
136-
* @param messageData
136+
* @param messageData received message data
137137
* @throws IOException
138138
* can be thrown when socket exception occur
139139
* @throws InterruptedException
@@ -148,30 +148,30 @@ public void onReceiverError(Optional<String> messageData)
148148
* {@link WrongSocketIOResponse} exception occurs client would be
149149
* disconnected
150150
*
151-
* @param exception
151+
* @param exception received exception
152152
*/
153-
public void onNetworkError(WrongSocketIOResponse e);
153+
public void onNetworkError(WrongSocketIOResponse exception);
154154

155155
/**
156156
* {@link IOException} exception occurs client would be disconnected
157157
*
158-
* @param exception
158+
* @param exception received exception
159159
*/
160-
public void onNetworkError(IOException e);
160+
public void onNetworkError(IOException exception);
161161

162162
/**
163163
* {@link WrongWebsocketResponse} exception occurs client would be
164164
* disconnected
165165
*
166-
* @param exception
166+
* @param exception received exception
167167
*/
168-
public void onNetworkError(WrongHttpResponseCode e);
168+
public void onNetworkError(WrongHttpResponseCode exception);
169169

170170
/**
171171
* {@link WrongWebsocketResponse} exception occurs client would be
172172
* disconnected
173173
*
174-
* @param exception
174+
* @param exception received exception
175175
*/
176176
public void onNetworkError(WrongWebsocketResponse exception);
177177

AndroidSocketIO/src/com/appunite/socketio/SocketWriter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public void sendStringMessage(String messageEndpoint, String message) throws IOE
4949
* @throws InterruptedException
5050
* @throws NotConnectedException
5151
*/
52-
public void sendJsonMessage(String messageEndpoint, JSONObject object) throws IOException,
52+
@SuppressWarnings("UnusedDeclaration")
53+
public void sendJsonMessage(String messageEndpoint, JSONObject object) throws IOException,
5354
InterruptedException, NotConnectedException;
5455

5556
/**
@@ -62,6 +63,7 @@ public void sendJsonMessage(String messageEndpoint, JSONObject object) throws IO
6263
* @throws InterruptedException
6364
* @throws NotConnectedException
6465
*/
66+
@SuppressWarnings("UnusedDeclaration")
6567
public void sendJsonEvent(String messageEndpoint, String name, JSONArray args) throws IOException,
6668
InterruptedException, NotConnectedException;
6769

0 commit comments

Comments
 (0)