Skip to content

Commit aa2d536

Browse files
author
John Michael Luy
committed
Apply Google Java format
Update the google-java-format gradle plugin from 0.8 to 0.9
1 parent 32903d4 commit aa2d536

File tree

117 files changed

+1104
-1127
lines changed

Some content is hidden

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

117 files changed

+1104
-1127
lines changed

OCPP-J/src/main/java/eu/chargetime/ocpp/Draft_HttpHealthCheck.java

Lines changed: 95 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
/*
33
* Based ON https://github.com/TooTallNate/Java-WebSocket/issues/1077
44
*/
5+
import java.nio.ByteBuffer;
6+
import java.util.Collections;
7+
import java.util.List;
58
import org.java_websocket.WebSocketImpl;
69
import org.java_websocket.drafts.Draft;
710
import org.java_websocket.enums.CloseHandshakeType;
@@ -12,105 +15,98 @@
1215
import org.java_websocket.handshake.*;
1316
import org.java_websocket.util.Charsetfunctions;
1417

15-
import java.nio.ByteBuffer;
16-
import java.util.Collections;
17-
import java.util.List;
18-
1918
class Draft_HttpHealthCheck extends Draft {
2019

21-
static final int HTTP_HEALTH_CHECK_CLOSE_CODE = 10200;
22-
23-
static Boolean isHttp(ClientHandshake handshakedata) {
24-
String upgradeField = handshakedata.getFieldValue("Upgrade");
25-
return upgradeField == null || upgradeField == "";
26-
}
27-
28-
@Override
29-
public List<ByteBuffer> createHandshake(Handshakedata handshakedata, boolean withcontent) {
30-
byte[] content = Charsetfunctions.asciiBytes("<h1>OCPP-J Websocket OK</h1>");
31-
byte[] header = Charsetfunctions.asciiBytes(
32-
"HTTP/1.0 200 OK\r\n" +
33-
"Mime-Version: 1.0\r\n" +
34-
"Content-Type: text/html\r\n" +
35-
"Content-Length: " + content.length + " \r\n" +
36-
"Connection: close\r\n" +
37-
"\r\n"
38-
);
39-
40-
ByteBuffer bytebuffer = ByteBuffer.allocate(content.length + header.length);
41-
bytebuffer.put(header);
42-
bytebuffer.put(content);
43-
bytebuffer.flip();
44-
return Collections.singletonList(bytebuffer);
45-
}
46-
47-
@Override
48-
public HandshakeState acceptHandshakeAsClient(
49-
ClientHandshake request, ServerHandshake response
50-
) throws InvalidHandshakeException {
51-
throw new InvalidHandshakeException("This draft can't be used on a client");
52-
}
53-
54-
@Override
55-
public HandshakeState acceptHandshakeAsServer(
56-
ClientHandshake handshakedata
57-
) throws InvalidHandshakeException {
58-
return (isHttp(handshakedata)) ? HandshakeState.MATCHED : HandshakeState.NOT_MATCHED;
59-
}
60-
61-
@Override
62-
public ByteBuffer createBinaryFrame(Framedata framedata) {
63-
return null;
64-
}
65-
66-
@Override
67-
public List<Framedata> createFrames(ByteBuffer binary, boolean mask) {
68-
return null;
69-
}
70-
71-
@Override
72-
public List<Framedata> createFrames(String text, boolean mask) {
73-
return null;
74-
}
75-
76-
@Override
77-
public void processFrame(
78-
WebSocketImpl webSocketImpl, Framedata frame
79-
) throws InvalidDataException {
80-
throw new InvalidDataException(0, "This draft can't be used on a client");
81-
}
82-
83-
@Override
84-
public void reset() {
85-
// Nothing to Do
86-
}
87-
88-
@Override
89-
public ClientHandshakeBuilder postProcessHandshakeRequestAsClient(
90-
ClientHandshakeBuilder request
91-
) throws InvalidHandshakeException {
92-
throw new InvalidHandshakeException("This draft can't be used on a client");
93-
}
94-
95-
@Override
96-
public HandshakeBuilder postProcessHandshakeResponseAsServer(
97-
ClientHandshake request, ServerHandshakeBuilder response
98-
) throws InvalidHandshakeException {
99-
return response;
100-
}
101-
102-
@Override
103-
public List<Framedata> translateFrame(ByteBuffer buffer) throws InvalidDataException {
104-
throw new InvalidHandshakeException("This draft doesn't work with frames");
105-
}
106-
107-
@Override
108-
public CloseHandshakeType getCloseHandshakeType() {
109-
return CloseHandshakeType.NONE;
110-
}
111-
112-
@Override
113-
public Draft copyInstance() {
114-
return this;
115-
}
20+
static final int HTTP_HEALTH_CHECK_CLOSE_CODE = 10200;
21+
22+
static Boolean isHttp(ClientHandshake handshakedata) {
23+
String upgradeField = handshakedata.getFieldValue("Upgrade");
24+
return upgradeField == null || upgradeField == "";
25+
}
26+
27+
@Override
28+
public List<ByteBuffer> createHandshake(Handshakedata handshakedata, boolean withcontent) {
29+
byte[] content = Charsetfunctions.asciiBytes("<h1>OCPP-J Websocket OK</h1>");
30+
byte[] header =
31+
Charsetfunctions.asciiBytes(
32+
"HTTP/1.0 200 OK\r\n"
33+
+ "Mime-Version: 1.0\r\n"
34+
+ "Content-Type: text/html\r\n"
35+
+ "Content-Length: "
36+
+ content.length
37+
+ " \r\n"
38+
+ "Connection: close\r\n"
39+
+ "\r\n");
40+
41+
ByteBuffer bytebuffer = ByteBuffer.allocate(content.length + header.length);
42+
bytebuffer.put(header);
43+
bytebuffer.put(content);
44+
bytebuffer.flip();
45+
return Collections.singletonList(bytebuffer);
46+
}
47+
48+
@Override
49+
public HandshakeState acceptHandshakeAsClient(ClientHandshake request, ServerHandshake response)
50+
throws InvalidHandshakeException {
51+
throw new InvalidHandshakeException("This draft can't be used on a client");
52+
}
53+
54+
@Override
55+
public HandshakeState acceptHandshakeAsServer(ClientHandshake handshakedata)
56+
throws InvalidHandshakeException {
57+
return (isHttp(handshakedata)) ? HandshakeState.MATCHED : HandshakeState.NOT_MATCHED;
58+
}
59+
60+
@Override
61+
public ByteBuffer createBinaryFrame(Framedata framedata) {
62+
return null;
63+
}
64+
65+
@Override
66+
public List<Framedata> createFrames(ByteBuffer binary, boolean mask) {
67+
return null;
68+
}
69+
70+
@Override
71+
public List<Framedata> createFrames(String text, boolean mask) {
72+
return null;
73+
}
74+
75+
@Override
76+
public void processFrame(WebSocketImpl webSocketImpl, Framedata frame)
77+
throws InvalidDataException {
78+
throw new InvalidDataException(0, "This draft can't be used on a client");
79+
}
80+
81+
@Override
82+
public void reset() {
83+
// Nothing to Do
84+
}
85+
86+
@Override
87+
public ClientHandshakeBuilder postProcessHandshakeRequestAsClient(ClientHandshakeBuilder request)
88+
throws InvalidHandshakeException {
89+
throw new InvalidHandshakeException("This draft can't be used on a client");
90+
}
91+
92+
@Override
93+
public HandshakeBuilder postProcessHandshakeResponseAsServer(
94+
ClientHandshake request, ServerHandshakeBuilder response) throws InvalidHandshakeException {
95+
return response;
96+
}
97+
98+
@Override
99+
public List<Framedata> translateFrame(ByteBuffer buffer) throws InvalidDataException {
100+
throw new InvalidHandshakeException("This draft doesn't work with frames");
101+
}
102+
103+
@Override
104+
public CloseHandshakeType getCloseHandshakeType() {
105+
return CloseHandshakeType.NONE;
106+
}
107+
108+
@Override
109+
public Draft copyInstance() {
110+
return this;
111+
}
116112
}

OCPP-J/src/main/java/eu/chargetime/ocpp/JSONCommunicator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ protected Message parse(Object json) {
170170
message.setPayload(array.get(INDEX_CALLRESULT_PAYLOAD).toString());
171171
} else if (array.get(INDEX_MESSAGEID).getAsInt() == TYPENUMBER_CALLERROR) {
172172
message = new CallErrorMessage();
173-
((CallErrorMessage) message).setErrorCode(array.get(INDEX_CALLERROR_ERRORCODE).getAsString());
173+
((CallErrorMessage) message)
174+
.setErrorCode(array.get(INDEX_CALLERROR_ERRORCODE).getAsString());
174175
((CallErrorMessage) message)
175176
.setErrorDescription(array.get(INDEX_CALLERROR_DESCRIPTION).getAsString());
176177
((CallErrorMessage) message).setRawPayload(array.get(INDEX_CALLERROR_PAYLOAD).toString());

OCPP-J/src/main/java/eu/chargetime/ocpp/WebSocketListener.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void open(String hostname, int port, ListenerEvents handler) {
8787
drafts) {
8888
@Override
8989
public void onOpen(WebSocket webSocket, ClientHandshake clientHandshake) {
90-
if(Draft_HttpHealthCheck.isHttp(clientHandshake)){
90+
if (Draft_HttpHealthCheck.isHttp(clientHandshake)) {
9191
logger.debug("On HTTP Request, for heathcheck");
9292
webSocket.close(Draft_HttpHealthCheck.HTTP_HEALTH_CHECK_CLOSE_CODE);
9393
return;
@@ -127,9 +127,9 @@ public void relay(String message) {
127127
SessionInformation information =
128128
new SessionInformation.Builder()
129129
.Identifier(clientHandshake.getResourceDescriptor())
130-
.InternetAddress(webSocket.getRemoteSocketAddress())
131-
.ProxiedAddress(proxiedAddress)
132-
.build();
130+
.InternetAddress(webSocket.getRemoteSocketAddress())
131+
.ProxiedAddress(proxiedAddress)
132+
.build();
133133

134134
handler.newSession(
135135
sessionFactory.createSession(new JSONCommunicator(receiver)), information);
@@ -142,8 +142,8 @@ public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer(
142142
SessionInformation information =
143143
new SessionInformation.Builder()
144144
.Identifier(clientHandshake.getResourceDescriptor())
145-
.InternetAddress(webSocket.getRemoteSocketAddress())
146-
.build();
145+
.InternetAddress(webSocket.getRemoteSocketAddress())
146+
.build();
147147

148148
String username = null;
149149
byte[] password = null;
@@ -166,8 +166,14 @@ public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer(
166166
}
167167
}
168168
if (password == null
169-
|| password.length < configuration.getParameter(JSONConfiguration.OCPPJ_CP_MIN_PASSWORD_LENGTH, OCPPJ_CP_MIN_PASSWORD_LENGTH)
170-
|| password.length > configuration.getParameter(JSONConfiguration.OCPPJ_CP_MAX_PASSWORD_LENGTH, OCPPJ_CP_MAX_PASSWORD_LENGTH))
169+
|| password.length
170+
< configuration.getParameter(
171+
JSONConfiguration.OCPPJ_CP_MIN_PASSWORD_LENGTH,
172+
OCPPJ_CP_MIN_PASSWORD_LENGTH)
173+
|| password.length
174+
> configuration.getParameter(
175+
JSONConfiguration.OCPPJ_CP_MAX_PASSWORD_LENGTH,
176+
OCPPJ_CP_MAX_PASSWORD_LENGTH))
171177
throw new InvalidDataException(401, "Invalid password length");
172178
}
173179

@@ -190,8 +196,7 @@ public void onClose(WebSocket webSocket, int code, String reason, boolean remote
190196
reason,
191197
remote);
192198

193-
if(code == Draft_HttpHealthCheck.HTTP_HEALTH_CHECK_CLOSE_CODE)
194-
return;
199+
if (code == Draft_HttpHealthCheck.HTTP_HEALTH_CHECK_CLOSE_CODE) return;
195200

196201
WebSocketReceiver receiver = sockets.get(webSocket);
197202
if (receiver != null) {

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
}
1010
}
1111
dependencies {
12-
classpath "gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.8"
12+
classpath "gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.9"
1313
}
1414
}
1515

ocpp-common/src/main/java/eu/chargetime/ocpp/CallErrorException.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ of this software and associated documentation files (the "Software"), to deal
2525
SOFTWARE.
2626
*/
2727

28-
/**
29-
* Exception returned to an outgoing request if an error is reported from the other end.
30-
*/
28+
/** Exception returned to an outgoing request if an error is reported from the other end. */
3129
public class CallErrorException extends Exception {
3230

3331
private String errorCode;
@@ -37,9 +35,9 @@ public class CallErrorException extends Exception {
3735
/**
3836
* Constructor.
3937
*
40-
* @param errorCode send from the other end.
38+
* @param errorCode send from the other end.
4139
* @param errorDescription describing the error.
42-
* @param payload raw payload send from the other end.
40+
* @param payload raw payload send from the other end.
4341
*/
4442
public CallErrorException(String errorCode, String errorDescription, Object payload) {
4543
super(

ocpp-common/src/main/java/eu/chargetime/ocpp/Client.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ public class Client {
5454
* @param promiseRepository Inject promise repository
5555
* @see Session
5656
*/
57-
public Client(
58-
ISession session,
59-
IPromiseRepository promiseRepository) {
57+
public Client(ISession session, IPromiseRepository promiseRepository) {
6058
this.session = session;
6159
this.promiseRepository = promiseRepository;
6260
}
@@ -94,7 +92,8 @@ public Confirmation handleRequest(Request request) throws UnsupportedFeatureExce
9492
}
9593

9694
@Override
97-
public boolean asyncCompleteRequest(String uniqueId, Confirmation confirmation) throws UnsupportedFeatureException, OccurenceConstraintException {
95+
public boolean asyncCompleteRequest(String uniqueId, Confirmation confirmation)
96+
throws UnsupportedFeatureException, OccurenceConstraintException {
9897
return session.completePendingPromise(uniqueId, confirmation);
9998
}
10099

@@ -104,7 +103,8 @@ public void handleError(
104103
Optional<CompletableFuture<Confirmation>> promiseOptional =
105104
promiseRepository.getPromise(uniqueId);
106105
if (promiseOptional.isPresent()) {
107-
promiseOptional.get()
106+
promiseOptional
107+
.get()
108108
.completeExceptionally(
109109
new CallErrorException(errorCode, errorDescription, payload));
110110
} else {
@@ -158,11 +158,13 @@ public CompletableFuture<Confirmation> send(Request request)
158158
String requestUuid = session.storeRequest(request);
159159
CompletableFuture<Confirmation> promise = promiseRepository.createPromise(requestUuid);
160160

161-
// Clean up after the promise has completed, no matter if it was successful or had an error or a timeout.
162-
promise.whenComplete((confirmation, throwable) -> {
163-
session.removeRequest(requestUuid);
164-
promiseRepository.removePromise(requestUuid);
165-
});
161+
// Clean up after the promise has completed, no matter if it was successful or had an error or a
162+
// timeout.
163+
promise.whenComplete(
164+
(confirmation, throwable) -> {
165+
session.removeRequest(requestUuid);
166+
promiseRepository.removePromise(requestUuid);
167+
});
166168

167169
session.sendRequest(featureOptional.get().getAction(), request, requestUuid);
168170
return promise;
@@ -172,7 +174,8 @@ public UUID getSessionId() {
172174
return this.session.getSessionId();
173175
}
174176

175-
public boolean asyncCompleteRequest(String uniqueId, Confirmation confirmation) throws UnsupportedFeatureException, OccurenceConstraintException {
177+
public boolean asyncCompleteRequest(String uniqueId, Confirmation confirmation)
178+
throws UnsupportedFeatureException, OccurenceConstraintException {
176179
return session.completePendingPromise(uniqueId, confirmation);
177180
}
178181
}

ocpp-common/src/main/java/eu/chargetime/ocpp/ISession.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public interface ISession {
4444

4545
void sendRequest(String action, Request payload, String uuid);
4646

47-
boolean completePendingPromise(String id, Confirmation confirmation) throws UnsupportedFeatureException, OccurenceConstraintException;
47+
boolean completePendingPromise(String id, Confirmation confirmation)
48+
throws UnsupportedFeatureException, OccurenceConstraintException;
4849

4950
void close();
5051
}

ocpp-common/src/main/java/eu/chargetime/ocpp/Queue.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ public Optional<Request> restoreRequest(String ticket) {
9090
}
9191

9292
/**
93-
* Remove a stored {@link Request} using a unique identifier.
94-
* If no request is found for the identifier this method has no effect.
93+
* Remove a stored {@link Request} using a unique identifier. If no request is found for the
94+
* identifier this method has no effect.
9595
*
9696
* @param ticket unique identifier returned when {@link Request} was initially stored.
9797
*/

0 commit comments

Comments
 (0)