Skip to content

Commit 26f8827

Browse files
authored
Merge pull request #305 from chadlwilson/cleanup-java-syntax
Modernize some remaining Java syntax
2 parents 9b95bd0 + 0a74172 commit 26f8827

30 files changed

+136
-337
lines changed

src/main/java/org/jruby/rack/DefaultErrorApplication.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ static Exception getException(RackEnvironment env) {
8686
private class Response implements RackResponse {
8787

8888
private int status = 500;
89-
@SuppressWarnings("rawtypes")
90-
private Map headers = Collections.EMPTY_MAP;
89+
private Map<String, ?> headers = Collections.emptyMap();
9190
private String body;
9291

9392
protected final RackEnvironment env;
@@ -103,14 +102,13 @@ public void setStatus(int status) {
103102
this.status = status;
104103
}
105104

106-
@SuppressWarnings("rawtypes")
107-
public Map getHeaders() {
105+
public Map<String, ?> getHeaders() {
108106
return headers;
109107
}
110108

111109
@SuppressWarnings("unused")
112-
public void setHeaders(@SuppressWarnings("rawtypes") Map headers) {
113-
this.headers = headers == null ? Collections.EMPTY_MAP : headers;
110+
public void setHeaders(Map<String, ?> headers) {
111+
this.headers = headers == null ? Collections.emptyMap() : headers;
114112
}
115113

116114
public String getBody() {
@@ -161,15 +159,12 @@ private void log(RackLogger.Level level, String message, Throwable e) {
161159

162160
}
163161

164-
@SuppressWarnings("rawtypes")
165162
public static void defaultRespond(final RackResponse rackResponse,
166163
final RackResponseEnvironment responseEnv) throws IOException {
167164
responseEnv.setStatus( rackResponse.getStatus() );
168-
@SuppressWarnings("unchecked")
169-
final Set<Map.Entry> headers = rackResponse.getHeaders().entrySet();
170-
for ( Iterator<Map.Entry> it = headers.iterator(); it.hasNext(); ) {
171-
final Map.Entry entry = it.next();
172-
final String key = entry.getKey().toString();
165+
final Set<? extends Map.Entry<String, ?>> headers = rackResponse.getHeaders().entrySet();
166+
for (final Map.Entry<String, ?> entry : headers) {
167+
final String key = entry.getKey();
173168
final Object value = entry.getValue();
174169
responseEnv.addHeader(key, value != null ? value.toString() : null);
175170
}

src/main/java/org/jruby/rack/DefaultRackApplication.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,8 @@ public RackResponse call(final RackEnvironment env) {
5050
final IRubyObject app = getApplication();
5151
final Ruby runtime = getRuntime();
5252
final IRubyObject servlet_env = JavaEmbedUtils.javaToRuby(runtime, env);
53-
//try { // app.call(env) :
5453
final IRubyObject response = app.callMethod(runtime.getCurrentContext(), "call", servlet_env);
55-
return (RackResponse) response.toJava(RackResponse.class);
56-
//}
57-
//catch (RuntimeException e) {
58-
// throw ExceptionUtils.wrapException(runtime, e);
59-
//}
54+
return response.toJava(RackResponse.class);
6055
}
6156

6257
@Override

src/main/java/org/jruby/rack/DefaultRackApplicationFactory.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.jruby.rack.util.IOHelpers;
2626
import org.jruby.runtime.ThreadContext;
2727
import org.jruby.runtime.builtin.IRubyObject;
28+
import org.jruby.util.cli.OutputStrings;
2829

2930
import static org.jruby.rack.RackLogger.Level.*;
3031
import static org.jruby.rack.DefaultRackConfig.isIgnoreRUBYOPT;
@@ -85,7 +86,7 @@ public void init(final RackContext rackContext) {
8586
this.rackContext = (ServletRackContext) rackContext;
8687
if ( getRackupScript() == null ) resolveRackupScript();
8788
this.runtimeConfig = createRuntimeConfig();
88-
rackContext.log(INFO, runtimeConfig.getVersionString());
89+
rackContext.log(INFO, OutputStrings.getVersionString());
8990
configureDefaults();
9091
}
9192

@@ -199,7 +200,7 @@ public IRubyObject createErrorApplicationObject(final Ruby runtime) {
199200

200201
public RackApplication newErrorApplication() {
201202
Boolean error = rackContext.getConfig().getBooleanProperty("jruby.rack.error");
202-
if ( error != null && ! error.booleanValue() ) { // jruby.rack.error = false
203+
if ( error != null && !error) { // jruby.rack.error = false
203204
return new DefaultErrorApplication(rackContext);
204205
}
205206
try {
@@ -557,7 +558,7 @@ private void configureDefaults() {
557558
if (iniSize == null) iniSize = RewindableInputStream.INI_BUFFER_SIZE;
558559
Integer maxSize = config.getMaximumMemoryBufferSize();
559560
if (maxSize == null) maxSize = RewindableInputStream.MAX_BUFFER_SIZE;
560-
if (iniSize.intValue() > maxSize.intValue()) iniSize = maxSize;
561+
if (iniSize > maxSize) iniSize = maxSize;
561562

562563
RewindableInputStream.setDefaultInitialBufferSize(iniSize);
563564
RewindableInputStream.setDefaultMaximumBufferSize(maxSize);

src/main/java/org/jruby/rack/DefaultRackConfig.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public boolean isSerialInitialization() {
123123
}
124124
}
125125
}
126-
return serial.booleanValue();
126+
return serial;
127127
}
128128

129129
@Override
@@ -156,10 +156,7 @@ protected RackLogger createLogger(final String loggerClass) {
156156
Constructor<?> ctor = klass.getConstructor(String.class);
157157
return (RackLogger) ctor.newInstance( getLoggerName() );
158158
}
159-
catch (NoSuchMethodException retry) {
160-
return newLoggerInstance(klass, retry);
161-
}
162-
catch (IllegalAccessException retry) {
159+
catch (NoSuchMethodException | IllegalAccessException retry) {
163160
return newLoggerInstance(klass, retry);
164161
}
165162
catch (InstantiationException e) {
@@ -268,7 +265,7 @@ static boolean isIgnoreRUBYOPT(RackConfig config) {
268265
// RUBYOPT ignored if jruby.runtime.env.rubyopt = false
269266
Boolean rubyopt = config.getBooleanProperty("jruby.runtime.env.rubyopt");
270267
if ( rubyopt == null ) return ! config.isIgnoreEnvironment();
271-
return rubyopt != null && ! rubyopt.booleanValue();
268+
return rubyopt != null && !rubyopt;
272269
}
273270

274271
@Override
@@ -282,11 +279,11 @@ public boolean isThrowInitException() {
282279

283280
static boolean isThrowInitException(RackConfig config) {
284281
Boolean error = config.getBooleanProperty("jruby.rack.error");
285-
if ( error != null && error.booleanValue() ) {
282+
if ( error != null && error) {
286283
return false; // jruby.rack.error = true
287284
}
288285
error = config.getBooleanProperty(RackEnvironment.EXCEPTION);
289-
if ( error != null && error.booleanValue() ) {
286+
if ( error != null && error) {
290287
return false; // jruby.rack.exception = true
291288
}
292289
return true;
@@ -335,7 +332,7 @@ private Integer getPositiveInteger(String key) {
335332
if (value == null) return null;
336333
try {
337334
int i = Integer.parseInt(value);
338-
if (i > 0) return Integer.valueOf(i);
335+
if (i > 0) return i;
339336
} catch (Exception e) { /* ignored */ }
340337
return null;
341338
}
@@ -367,12 +364,12 @@ public static Number toNumber(String value, Number defaultValue) {
367364
}
368365
if ( number == ((int) number) )
369366
if ( number > Integer.MAX_VALUE ) {
370-
return Long.valueOf((long) number);
367+
return (long) number;
371368
}
372369
else {
373-
return Integer.valueOf((int) number);
370+
return (int) number;
374371
}
375-
return Float.valueOf(number);
372+
return number;
376373
}
377374
catch (Exception e) { /* ignored */ }
378375
return defaultValue;
@@ -386,7 +383,7 @@ private Map<String, String> toStringMap(final String env) {
386383
GEM_HOME=/opt/local/rvm/gems/jruby-1.6.8@jruby-rack
387384
*/
388385
LineNumberReader reader = new LineNumberReader(new StringReader(env.trim()));
389-
Map<String, String> map = new LinkedHashMap<String, String>(); String line;
386+
Map<String, String> map = new LinkedHashMap<>(); String line;
390387
try {
391388
while ( (line = reader.readLine()) != null ) {
392389
final String[] entries = line.split(",");
@@ -419,7 +416,6 @@ private static Map<String,String> getLoggerTypes() {
419416
loggerTypes.put("clogging", "org.jruby.rack.logging.CommonsLoggingLogger");
420417
loggerTypes.put("slf4j", "org.jruby.rack.logging.Slf4jLogger");
421418
loggerTypes.put("jul", "org.jruby.rack.logging.JulLogger");
422-
//loggerTypes.put("servlet_context", "org.jruby.rack.logging.ServletContextLogger");
423419
return loggerTypes;
424420
}
425421

src/main/java/org/jruby/rack/DefaultRackDispatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected void afterException(
5757
// TODO seems redundant maybe we should let the container decide ?!
5858
context.log(ERROR, "error app failed to handle exception: " + e, re);
5959
Integer errorCode = getErrorApplicationFailureStatusCode();
60-
if ( errorCode != null && errorCode.intValue() > 0 ) {
60+
if ( errorCode != null && errorCode > 0 ) {
6161
response.sendError(errorCode);
6262
}
6363
else {

src/main/java/org/jruby/rack/PoolingRackApplicationFactory.java

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class PoolingRackApplicationFactory extends RackApplicationFactoryDecorat
4949
// 10 seconds seems still too much for a default, has been 30 previously :
5050
private static final float ACQUIRE_DEFAULT = 10.0f;
5151

52-
protected final Queue<RackApplication> applicationPool = new LinkedList<RackApplication>();
52+
protected final Queue<RackApplication> applicationPool = new LinkedList<>();
5353
private Integer initialSize, maximumSize;
5454

5555
private final AtomicInteger initedApplications = new AtomicInteger(0);
@@ -111,7 +111,7 @@ public void setAcquireTimeout(Number acquireTimeout) {
111111

112112
@Override
113113
protected void doInit() throws Exception {
114-
super.doInit(); // delegate.init(rackContext);
114+
super.doInit();
115115
final RackConfig config = getConfig();
116116
// TODO until config.getRuntimeTimeoutSeconds returns an integer :
117117
Number timeout = config.getNumberProperty("jruby.runtime.acquire.timeout");
@@ -253,16 +253,15 @@ public void destroy() {
253253
synchronized (applicationPool) {
254254
for (RackApplication app : applicationPool) {
255255
getDelegate().finishedWithApplication(app);
256-
// DefaultRackAppFactory: app.destroy();
257256
}
258257
applicationPool.clear();
259258
}
260-
super.destroy(); // delegate.destroy();
259+
super.destroy();
261260
}
262261

263262
/**
264263
* Fills the initial pool with initialized application instances.
265-
*
264+
* <p>
266265
* Application objects are created in foreground threads to avoid
267266
* leakage when the web application is undeployed from the server.
268267
*/
@@ -294,19 +293,15 @@ protected void launchInitialization(final Queue<RackApplication> apps) {
294293
if ( initThreads == null ) initThreads = 4; // quad-core baby
295294

296295
for (int i = 0; i < initThreads; i++) {
297-
new Thread(new Runnable() {
298-
@Override
299-
public void run() {
300-
while (true) {
301-
final RackApplication app;
302-
synchronized (apps) {
303-
if ( apps.isEmpty() ) break;
304-
app = apps.remove();
305-
}
306-
if ( ! initAndPutApplicationToPool(app) ) break;
296+
new Thread(() -> {
297+
while (true) {
298+
final RackApplication app;
299+
synchronized (apps) {
300+
if ( apps.isEmpty() ) break;
301+
app = apps.remove();
307302
}
303+
if ( ! initAndPutApplicationToPool(app) ) break;
308304
}
309-
310305
}, "JRuby-Rack-App-Init-" + i).start();
311306
}
312307
}
@@ -395,14 +390,14 @@ private int getInitialPoolSizeWait() {
395390
if ( waitNum != null ) {
396391
int wait = waitNum.intValue();
397392
if (maximumSize != null && wait > maximumSize) {
398-
wait = maximumSize.intValue();
393+
wait = maximumSize;
399394
}
400395
return wait;
401396
}
402397
// otherwise we assume it to be a boolean true/false flag :
403398
Boolean waitFlag = getConfig().getBooleanProperty("jruby.runtime.init.wait");
404399
if ( waitFlag == null ) waitFlag = Boolean.TRUE;
405-
return waitFlag ? ( initialSize == null ? 1 : initialSize.intValue() ) : 0;
400+
return waitFlag ? ( initialSize == null ? 1 : initialSize) : 0;
406401
// NOTE: this slightly changes the behavior in 1.1.8, in previous
407402
// versions the initialization only waited for 1 application instance
408403
// to be available in the pool - here by default we wait till initial
@@ -411,14 +406,14 @@ private int getInitialPoolSizeWait() {
411406

412407
@Override
413408
public Collection<RackApplication> getManagedApplications() {
414-
int initSize = initialSize != null ? initialSize.intValue() : -1;
409+
int initSize = initialSize != null ? initialSize : -1;
415410
synchronized (applicationPool) {
416411
if ( applicationPool.isEmpty() ) {
417412
if ( initSize > 0 ) return null; // ~ init error
418413
return Collections.emptySet();
419414
}
420415
Collection<RackApplication> snapshot =
421-
new ArrayList<RackApplication>(applicationPool);
416+
new ArrayList<>(applicationPool);
422417
return Collections.unmodifiableCollection(snapshot);
423418
}
424419
}

src/main/java/org/jruby/rack/RackApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public interface RackApplication {
2424
* @param env the RackEnvironment
2525
* @return the RackResponse
2626
*/
27-
public RackResponse call(RackEnvironment env);
27+
RackResponse call(RackEnvironment env);
2828

2929
/**
3030
* Get a reference to the underlying runtime that holds the application

src/main/java/org/jruby/rack/RackApplicationFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public interface RackApplicationFactory {
6868
*
6969
* @author kares
7070
*/
71-
public static interface Decorator {
71+
interface Decorator {
7272

7373
/**
7474
* @return the delegate factory this decorator wraps

src/main/java/org/jruby/rack/RackApplicationFactoryDecorator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ private RackContext getContextBang() throws IllegalStateException {
204204
public static Collection<Ruby> getManagedRuntimes(RackApplicationFactoryDecorator factory) {
205205
final Collection<RackApplication> apps = factory.getManagedApplications();
206206
if ( apps == null ) return null;
207-
final Set<Ruby> runtimes = new LinkedHashSet<Ruby>(apps.size());
207+
final Set<Ruby> runtimes = new LinkedHashSet<>(apps.size());
208208
for ( RackApplication app : apps ) {
209209
runtimes.add( app.getRuntime() );
210210
}

src/main/java/org/jruby/rack/RackConfig.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,7 @@ public interface RackConfig {
135135
* @return the maximum size of the in-memory buffer
136136
*/
137137
Integer getMaximumMemoryBufferSize();
138-
139-
/**
140-
* @return whether we allow the initialization exception to bubble up
141-
*/
142-
//boolean isThrowInitException();
143-
138+
144139
/**
145140
* Create a logger to be used (based on this configuration).
146141
* @return a logger instance

0 commit comments

Comments
 (0)