Skip to content

Commit aa5552c

Browse files
committed
Add some @NotNull annotations
1 parent d69a54f commit aa5552c

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

src/express/Express.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package express;
22

3+
import com.sun.istack.internal.NotNull;
34
import com.sun.net.httpserver.HttpServer;
45
import express.events.Action;
56
import express.events.HttpRequest;
@@ -33,7 +34,7 @@ public class Express extends ExpressMiddleware {
3334
private final ExpressFilterChain MIDDLEWARE_CHAIN = new ExpressFilterChain();
3435
private final ExpressFilterChain FILTER_CHAIN = new ExpressFilterChain();
3536

36-
private Executor executor;
37+
private Executor executor = Executors.newCachedThreadPool();
3738
private String hostname = "localhost";
3839
private HttpServer httpServer;
3940

@@ -43,11 +44,8 @@ public class Express extends ExpressMiddleware {
4344
*
4445
* @param hostname The host name
4546
*/
46-
public Express(String hostname) {
47-
if (hostname != null)
48-
this.hostname = hostname;
49-
50-
this.executor = Executors.newCachedThreadPool();
47+
public Express(@NotNull String hostname) {
48+
this.hostname = hostname;
5149
}
5250

5351
/**
@@ -62,7 +60,7 @@ public Express() {
6260
* @param param The parameter name.
6361
* @param request An request handler.
6462
*/
65-
public void onParam(String param, HttpRequest request) {
63+
public void onParam(@NotNull String param, @NotNull HttpRequest request) {
6664
PARAMETER_LISTENER.put(param, request);
6765
}
6866

@@ -99,7 +97,7 @@ public Object get(Object key) {
9997
* @param executor The new executor.
10098
* @throws IOException If the server is currently running
10199
*/
102-
public void setExecutor(Executor executor) throws IOException {
100+
public void setExecutor(@NotNull Executor executor) throws IOException {
103101
if (httpServer != null) {
104102
throw new IOException("Cannot set the executor after the server has starderd!");
105103
} else {
@@ -112,7 +110,7 @@ public void setExecutor(Executor executor) throws IOException {
112110
*
113111
* @param middleware An middleware which will be fired on every equestmethod- and path.
114112
*/
115-
public void use(HttpRequest middleware) {
113+
public void use(@NotNull HttpRequest middleware) {
116114
addMiddleware("*", "*", middleware);
117115
}
118116

@@ -122,7 +120,7 @@ public void use(HttpRequest middleware) {
122120
* @param context The context where the middleware should listen.
123121
* @param middleware An middleware which will be fired if the context matches the requestpath.
124122
*/
125-
public void use(String context, HttpRequest middleware) {
123+
public void use(@NotNull String context, @NotNull HttpRequest middleware) {
126124
addMiddleware("*", context, middleware);
127125
}
128126

@@ -133,11 +131,11 @@ public void use(String context, HttpRequest middleware) {
133131
* @param requestMethod And type of request-method eg. GET, POST etc.
134132
* @param middleware An middleware which will be fired if the context matches the requestmethod- and path.
135133
*/
136-
public void use(String context, String requestMethod, HttpRequest middleware) {
134+
public void use(@NotNull String context, @NotNull String requestMethod, @NotNull HttpRequest middleware) {
137135
addMiddleware(requestMethod.toUpperCase(), context, middleware);
138136
}
139137

140-
private void addMiddleware(String requestMethod, String context, HttpRequest middleware) {
138+
private void addMiddleware(@NotNull String requestMethod, @NotNull String context, HttpRequest middleware) {
141139
if (middleware instanceof ExpressFilterTask) {
142140
WORKER.add(new ExpressFilterWorker((ExpressFilterTask) middleware));
143141
}
@@ -151,7 +149,7 @@ private void addMiddleware(String requestMethod, String context, HttpRequest mid
151149
* @param context The context.
152150
* @param request An listener which will be fired if the context matches the requestpath.
153151
*/
154-
public void all(String context, HttpRequest request) {
152+
public void all(@NotNull String context, @NotNull HttpRequest request) {
155153
FILTER_CHAIN.add(new ExpressFilterImpl(this, "*", context, request));
156154
}
157155

@@ -161,7 +159,7 @@ public void all(String context, HttpRequest request) {
161159
* @param context The context.
162160
* @param request An listener which will be fired if the context matches the requestpath.
163161
*/
164-
public void get(String context, HttpRequest request) {
162+
public void get(@NotNull String context, @NotNull HttpRequest request) {
165163
FILTER_CHAIN.add(new ExpressFilterImpl(this, "GET", context, request));
166164
}
167165

@@ -171,7 +169,7 @@ public void get(String context, HttpRequest request) {
171169
* @param context The context.
172170
* @param request An listener which will be fired if the context matches the requestpath.
173171
*/
174-
public void post(String context, HttpRequest request) {
172+
public void post(@NotNull String context, @NotNull HttpRequest request) {
175173
FILTER_CHAIN.add(new ExpressFilterImpl(this, "POST", context, request));
176174
}
177175

@@ -181,7 +179,7 @@ public void post(String context, HttpRequest request) {
181179
* @param context The context for the request handler..
182180
* @param request An listener which will be fired if the context matches the requestpath.
183181
*/
184-
public void put(String context, HttpRequest request) {
182+
public void put(@NotNull String context, @NotNull HttpRequest request) {
185183
FILTER_CHAIN.add(new ExpressFilterImpl(this, "PUT", context, request));
186184
}
187185

@@ -191,7 +189,7 @@ public void put(String context, HttpRequest request) {
191189
* @param context The context.
192190
* @param request An listener which will be fired if the context matches the requestpath.
193191
*/
194-
public void delete(String context, HttpRequest request) {
192+
public void delete(@NotNull String context, @NotNull HttpRequest request) {
195193
FILTER_CHAIN.add(new ExpressFilterImpl(this, "DELETE", context, request));
196194
}
197195

@@ -201,7 +199,7 @@ public void delete(String context, HttpRequest request) {
201199
* @param context The context.
202200
* @param request An listener which will be fired if the context matches the requestpath.
203201
*/
204-
public void patch(String context, HttpRequest request) {
202+
public void patch(@NotNull String context, @NotNull HttpRequest request) {
205203
FILTER_CHAIN.add(new ExpressFilterImpl(this, "PATCH", context, request));
206204
}
207205

@@ -212,7 +210,7 @@ public void patch(String context, HttpRequest request) {
212210
* @param context The context for the request handler.
213211
* @param request An listener which will be fired if the context matches the requestpath.
214212
*/
215-
public void on(String requestMethod, String context, HttpRequest request) {
213+
public void on(@NotNull String requestMethod, @NotNull String context, @NotNull HttpRequest request) {
216214
FILTER_CHAIN.add(new ExpressFilterImpl(this, requestMethod, context, request));
217215
}
218216

@@ -224,7 +222,7 @@ public void on(String requestMethod, String context, HttpRequest request) {
224222
* @param contexts The contexts for the request handler..
225223
* @param request An listener which will be fired if the context matches the requestpath.
226224
*/
227-
public void on(String requestMethod, HttpRequest request, String... contexts) {
225+
public void on(@NotNull String requestMethod, @NotNull HttpRequest request, String... contexts) {
228226
for (String c : contexts)
229227
FILTER_CHAIN.add(new ExpressFilterImpl(this, requestMethod, c, request));
230228
}

0 commit comments

Comments
 (0)