Skip to content

Commit 5d53a42

Browse files
author
Max Presman
committed
Merge branch 'checkstyle' into edge
2 parents 09cb418 + cab09fa commit 5d53a42

50 files changed

Lines changed: 448 additions & 350 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎build.gradle‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,16 @@ jacocoTestReport {
5555
checkstyle {
5656
configFile = new File(rootDir, "src/test/checkstyle.xml")
5757
toolVersion = '6.17'
58-
ignoreFailures = true
5958
}
6059

6160
findbugs {
6261
ignoreFailures = true
6362
}
6463

6564
tasks.withType(Checkstyle) {
65+
66+
exclude '**/vendor/**', "**/PubNubError.java"
67+
6668
reports {
6769
xml.enabled = true
6870
html.enabled = true
@@ -80,4 +82,4 @@ check.dependsOn jacocoTestReport
8082

8183
processResources {
8284
expand projectVersion: project.version
83-
}
85+
}

‎src/main/java/com/pubnub/api/PNConfiguration.java‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
@Setter
1515
@Accessors(chain = true)
1616
public class PNConfiguration {
17+
private static final int PRESENCE_TIMEOUT = 300;
18+
private static final int NON_SUBSCRIBE_REQUEST_TIMEOUT = 10;
19+
private static final int SUBSCRIBE_TIMEOUT = 310;
20+
private static final int CONNECT_TIMEOUT = 5;
1721

1822
/**
1923
* By default, the origin is pointing directly to PubNub servers. If a proxy origin is neeeded, set a custom
@@ -68,8 +72,8 @@ public class PNConfiguration {
6872
private int connectTimeout;
6973

7074
/**
71-
* Reference on number of seconds which is used by client during non-subscription operations to
72-
check whether response potentially failed with 'timeout' or not.
75+
* Reference on number of seconds which is used by client during non-subscription operations to
76+
* check whether response potentially failed with 'timeout' or not.
7377
*/
7478
private int nonSubscribeRequestTimeout;
7579

@@ -81,28 +85,30 @@ public class PNConfiguration {
8185
/**
8286
* filterExpression used as part of PSV2 specification.
8387
*/
84-
@Setter private String filterExpression;
88+
@Setter
89+
private String filterExpression;
8590

8691
/**
8792
* Initialize the PNConfiguration with default values
8893
*/
8994
public PNConfiguration() {
90-
setPresenceTimeout(300);
95+
setPresenceTimeout(PRESENCE_TIMEOUT);
9196

9297
uuid = UUID.randomUUID().toString();
9398

94-
nonSubscribeRequestTimeout = 10;
95-
subscribeTimeout = 310;
96-
connectTimeout = 5;
99+
nonSubscribeRequestTimeout = NON_SUBSCRIBE_REQUEST_TIMEOUT;
100+
subscribeTimeout = SUBSCRIBE_TIMEOUT;
101+
connectTimeout = CONNECT_TIMEOUT;
97102

98103
logVerbosity = PNLogVerbosity.NONE;
99104

100105
heartbeatNotificationOptions = PNHeartbeatNotificationOptions.Failures;
101106
}
102107

103108
/**
104-
* set presence configurations for timeout and announce interval.
105-
* @param timeout presence timeout; how long before the server considers this client to be gone.
109+
* set presence configurations for timeout and announce interval.
110+
*
111+
* @param timeout presence timeout; how long before the server considers this client to be gone.
106112
* @param interval presence announce interval, how often the client should announce itself.
107113
* @return returns itself.
108114
*/
@@ -115,11 +121,12 @@ public PNConfiguration setPresenceTimeoutWithCustomInterval(final int timeout, f
115121

116122
/**
117123
* set presence configurations for timeout and allow the client to pick the best interval
124+
*
118125
* @param timeout presence timeout; how long before the server considers this client to be gone.
119126
* @return returns itself.
120127
*/
121128
public PNConfiguration setPresenceTimeout(final int timeout) {
122-
return setPresenceTimeoutWithCustomInterval(timeout,(timeout / 2) - 1);
129+
return setPresenceTimeoutWithCustomInterval(timeout, (timeout / 2) - 1);
123130
}
124131

125132
}

‎src/main/java/com/pubnub/api/PubNub.java‎

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,24 @@
88
import com.pubnub.api.endpoints.Time;
99
import com.pubnub.api.endpoints.access.Audit;
1010
import com.pubnub.api.endpoints.access.Grant;
11-
import com.pubnub.api.endpoints.channel_groups.*;
11+
import com.pubnub.api.endpoints.channel_groups.AddChannelChannelGroup;
12+
import com.pubnub.api.endpoints.channel_groups.AllChannelsChannelGroup;
13+
import com.pubnub.api.endpoints.channel_groups.DeleteChannelGroup;
14+
import com.pubnub.api.endpoints.channel_groups.RemoveChannelChannelGroup;
15+
import com.pubnub.api.endpoints.channel_groups.ListAllChannelGroup;
1216
import com.pubnub.api.endpoints.presence.GetState;
1317
import com.pubnub.api.endpoints.presence.HereNow;
1418
import com.pubnub.api.endpoints.presence.SetState;
1519
import com.pubnub.api.endpoints.presence.WhereNow;
1620
import com.pubnub.api.endpoints.pubsub.Publish;
17-
import com.pubnub.api.endpoints.push.*;
21+
import com.pubnub.api.endpoints.push.AddChannelsToPush;
22+
import com.pubnub.api.endpoints.push.RemoveChannelsFromPush;
23+
import com.pubnub.api.endpoints.push.RemoveAllPushChannelsForDevice;
24+
import com.pubnub.api.endpoints.push.ListPushProvisions;
1825
import com.pubnub.api.managers.BasePathManager;
1926
import com.pubnub.api.managers.PublishSequenceManager;
2027
import com.pubnub.api.managers.SubscriptionManager;
28+
import com.pubnub.api.vendor.Crypto;
2129
import lombok.AccessLevel;
2230
import lombok.Getter;
2331
import lombok.extern.slf4j.Slf4j;
@@ -43,11 +51,14 @@ public class PubNub {
4351

4452
private String sdkVersion;
4553

54+
private static final int TIMESTAMP_DIVIDER = 1000;
55+
private static final int MAX_SEQUENCE = 65535;
56+
4657
public PubNub(final PNConfiguration initialConfig) {
4758
this.configuration = initialConfig;
4859
this.subscriptionManager = new SubscriptionManager(this);
4960
this.basePathManager = new BasePathManager(initialConfig);
50-
this.publishSequenceManager = new PublishSequenceManager(65535);
61+
this.publishSequenceManager = new PublishSequenceManager(MAX_SEQUENCE);
5162

5263
sdkVersion = fetchSDKVersion();
5364
}
@@ -70,7 +81,9 @@ public final SubscribeBuilder subscribe() {
7081
return new SubscribeBuilder(this.subscriptionManager);
7182
}
7283

73-
public final UnsubscribeBuilder unsubscribe() { return new UnsubscribeBuilder(this.subscriptionManager); }
84+
public final UnsubscribeBuilder unsubscribe() {
85+
return new UnsubscribeBuilder(this.subscriptionManager);
86+
}
7487

7588
// start push
7689

@@ -95,6 +108,7 @@ public final ListPushProvisions auditPushChannelProvisions() {
95108
public final WhereNow whereNow() {
96109
return new WhereNow(this);
97110
}
111+
98112
public final HereNow hereNow() {
99113
return new HereNow(this);
100114
}
@@ -103,19 +117,23 @@ public final Time time() {
103117
return new Time(this);
104118
}
105119

106-
public final History history() { return new History(this); }
120+
public final History history() {
121+
return new History(this);
122+
}
107123

108124

109125
public final Audit audit() {
110126
return new Audit(this);
111127
}
128+
112129
public final Grant grant() {
113130
return new Grant(this);
114131
}
115132

116133
public final GetState getPresenceState() {
117134
return new GetState(this);
118135
}
136+
119137
public final SetState setPresenceState() {
120138
return new SetState(this, subscriptionManager);
121139
}
@@ -148,6 +166,7 @@ public final DeleteChannelGroup deleteChannelGroup() {
148166

149167
/**
150168
* Perform Cryptographic decryption of an input string using cipher key provided by PNConfiguration
169+
*
151170
* @param inputString String to be encrypted
152171
* @return String containing the encryption of inputString using cipherKey
153172
*/
@@ -161,10 +180,11 @@ public final String decrypt(String inputString) throws PubNubException {
161180

162181
/**
163182
* Perform Cryptographic decryption of an input string using the cipher key
183+
*
164184
* @param inputString String to be encrypted
165-
* @param cipherKey cipher key to be used for encryption
166-
* @throws PubNubException throws exception in case of failed encryption
185+
* @param cipherKey cipher key to be used for encryption
167186
* @return String containing the encryption of inputString using cipherKey
187+
* @throws PubNubException throws exception in case of failed encryption
168188
*/
169189
public final String decrypt(final String inputString, final String cipherKey) throws PubNubException {
170190
if (inputString == null) {
@@ -176,6 +196,7 @@ public final String decrypt(final String inputString, final String cipherKey) th
176196

177197
/**
178198
* Perform Cryptographic encryption of an input string and the cipher key provided by PNConfiguration
199+
*
179200
* @param inputString String to be encrypted
180201
* @return String containing the encryption of inputString using cipherKey
181202
*/
@@ -189,10 +210,11 @@ public final String encrypt(final String inputString) throws PubNubException {
189210

190211
/**
191212
* Perform Cryptographic encryption of an input string and the cipher key.
213+
*
192214
* @param inputString String to be encrypted
193-
* @param cipherKey cipher key to be used for encryption
194-
* @throws PubNubException throws exception in case of failed encryption
215+
* @param cipherKey cipher key to be used for encryption
195216
* @return String containing the encryption of inputString using cipherKey
217+
* @throws PubNubException throws exception in case of failed encryption
196218
*/
197219
public final String encrypt(final String inputString, final String cipherKey) throws PubNubException {
198220
if (inputString == null) {
@@ -203,7 +225,7 @@ public final String encrypt(final String inputString, final String cipherKey) th
203225
}
204226

205227
public int getTimestamp() {
206-
return (int) ((new Date().getTime()) / 1000);
228+
return (int) ((new Date().getTime()) / TIMESTAMP_DIVIDER);
207229
}
208230

209231
/**
@@ -229,6 +251,7 @@ public final void reconnect() {
229251

230252
/**
231253
* fetch the SDK version from the resource files.
254+
*
232255
* @return Stringified representation of the SDK version.
233256
*/
234257
private String fetchSDKVersion() {

‎src/main/java/com/pubnub/api/PubNubException.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ public class PubNubException extends Exception {
1717

1818
@Getter(AccessLevel.NONE)
1919
private Call affectedCall;
20-
}
20+
}

‎src/main/java/com/pubnub/api/PubNubUtil.java‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.pubnub.api;
22

33
import com.pubnub.api.builder.PubNubErrorBuilder;
4-
import com.pubnub.api.utils.Base64;
4+
import com.pubnub.api.vendor.Base64;
55

66
import javax.crypto.Mac;
77
import javax.crypto.spec.SecretKeySpec;
@@ -15,28 +15,27 @@
1515
import java.util.Set;
1616
import java.util.TreeSet;
1717

18-
/**
19-
* Created by Frederick on 3/30/16.
20-
*/
21-
public class PubNubUtil {
2218

19+
public final class PubNubUtil {
2320

24-
public static String joinString(List<String> val, String delim){
21+
private PubNubUtil() {
22+
}
23+
24+
public static String joinString(List<String> val, String delim) {
2525
StringBuilder builder = new StringBuilder();
26-
for(String l: val){
26+
for (String l : val) {
2727
builder.append(l);
2828
builder.append(",");
2929
}
3030

31-
return builder.toString().substring(0,builder.toString().length() - 1);
31+
return builder.toString().substring(0, builder.toString().length() - 1);
3232

3333
}
3434

3535
/**
3636
* Returns encoded String
3737
*
38-
* @param sUrl
39-
* , input string
38+
* @param sUrl , input string
4039
* @return , encoded string
4140
*/
4241
public static String pamEncode(String sUrl) {
@@ -61,8 +60,7 @@ public static String pamEncode(String sUrl) {
6160
/**
6261
* Returns encoded String
6362
*
64-
* @param sUrl
65-
* , input string
63+
* @param sUrl , input string
6664
* @return , encoded string
6765
*/
6866
public static String urlEncode(String sUrl) {
@@ -88,7 +86,7 @@ public static String urlDecode(String sUrl) {
8886
}
8987
}
9088

91-
public static String preparePamArguments(Map<String, String> pamArgs){
89+
public static String preparePamArguments(Map<String, String> pamArgs) {
9290
Set<String> pamKeys = new TreeSet(pamArgs.keySet());
9391
String stringifiedArguments = "";
9492
int i = 0;

‎src/main/java/com/pubnub/api/builder/PubSubBuilder.java‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111

1212
public abstract class PubSubBuilder {
1313

14-
@Getter(AccessLevel.NONE)
15-
@Setter(AccessLevel.NONE)
16-
protected List<String> channelSubscriptions;
14+
@Getter(AccessLevel.PROTECTED)
15+
@Setter(AccessLevel.PROTECTED)
16+
private List<String> channelSubscriptions;
1717

18-
@Getter(AccessLevel.NONE)
19-
@Setter(AccessLevel.NONE)
20-
protected List<String> channelGroupSubscriptions;
18+
@Getter(AccessLevel.PROTECTED)
19+
@Setter(AccessLevel.PROTECTED)
20+
private List<String> channelGroupSubscriptions;
2121

22-
@Getter(AccessLevel.NONE)
23-
@Setter(AccessLevel.NONE)
24-
protected SubscriptionManager subscriptionManager;
22+
@Getter(AccessLevel.PROTECTED)
23+
@Setter(AccessLevel.PROTECTED)
24+
private SubscriptionManager subscriptionManager;
2525

26-
public PubSubBuilder(SubscriptionManager subscriptionManager) {
27-
this.subscriptionManager = subscriptionManager;
26+
public PubSubBuilder(SubscriptionManager subscriptionManagerInstance) {
27+
this.subscriptionManager = subscriptionManagerInstance;
2828
this.channelSubscriptions = new ArrayList<>();
2929
this.channelGroupSubscriptions = new ArrayList<>();
3030
}

‎src/main/java/com/pubnub/api/builder/SubscribeBuilder.java‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import java.util.List;
1010

1111
@Setter
12-
@Accessors(chain = true, fluent = true)
13-
public class SubscribeBuilder extends PubSubBuilder {
12+
@Accessors(chain = true, fluent = true)
13+
public class SubscribeBuilder extends PubSubBuilder {
1414

1515
/**
1616
* Allow users to specify if they would also like to include the presence channels for those subscriptions.
@@ -33,20 +33,20 @@ public SubscribeBuilder withPresence() {
3333
return this;
3434
}
3535

36-
public SubscribeBuilder withTimetoken(final Long timetoken) {
37-
this.timetoken = timetoken;
36+
public SubscribeBuilder withTimetoken(Long timetokenInstance) {
37+
this.timetoken = timetokenInstance;
3838
return this;
3939
}
4040

4141
public void execute() {
4242
SubscribeOperation subscribeOperation = SubscribeOperation.builder()
43-
.channels(channelSubscriptions)
44-
.channelGroups(channelGroupSubscriptions)
43+
.channels(this.getChannelSubscriptions())
44+
.channelGroups(this.getChannelGroupSubscriptions())
4545
.timetoken(timetoken)
4646
.presenceEnabled(presenceEnabled)
4747
.build();
4848

49-
this.subscriptionManager.adaptSubscribeBuilder(subscribeOperation);
49+
this.getSubscriptionManager().adaptSubscribeBuilder(subscribeOperation);
5050
}
5151

5252
public SubscribeBuilder channels(final List<String> channels) {

0 commit comments

Comments
 (0)