Skip to content

Commit b3a983f

Browse files
committed
Clean up style
1 parent 78a3c6c commit b3a983f

File tree

7 files changed

+64
-55
lines changed

7 files changed

+64
-55
lines changed

src/main/java/org/scijava/plugins/scripting/jython/DefaultJythonService.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
* %%
99
* Redistribution and use in source and binary forms, with or without
1010
* modification, are permitted provided that the following conditions are met:
11-
*
11+
*
1212
* 1. Redistributions of source code must retain the above copyright notice,
1313
* this list of conditions and the following disclaimer.
1414
* 2. Redistributions in binary form must reproduce the above copyright notice,
1515
* this list of conditions and the following disclaimer in the documentation
1616
* and/or other materials provided with the distribution.
17-
*
17+
*
1818
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1919
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2020
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -28,6 +28,7 @@
2828
* POSSIBILITY OF SUCH DAMAGE.
2929
* #L%
3030
*/
31+
3132
package org.scijava.plugins.scripting.jython;
3233

3334
import javax.script.ScriptEngine;
@@ -46,7 +47,9 @@
4647
* @author Mark Hiner hinerm at gmail.com
4748
*/
4849
@Plugin(type = Service.class)
49-
public class DefaultJythonService extends AbstractService implements JythonService {
50+
public class DefaultJythonService extends AbstractService implements
51+
JythonService
52+
{
5053

5154
// -- Fields --
5255

src/main/java/org/scijava/plugins/scripting/jython/JythonBindings.java

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
* %%
99
* Redistribution and use in source and binary forms, with or without
1010
* modification, are permitted provided that the following conditions are met:
11-
*
11+
*
1212
* 1. Redistributions of source code must retain the above copyright notice,
1313
* this list of conditions and the following disclaimer.
1414
* 2. Redistributions in binary form must reproduce the above copyright notice,
1515
* this list of conditions and the following disclaimer in the documentation
1616
* and/or other materials provided with the distribution.
17-
*
17+
*
1818
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1919
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2020
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -48,7 +48,7 @@
4848

4949
/**
5050
* A {@link Bindings} wrapper around Jython's local variables.
51-
*
51+
*
5252
* @author Johannes Schindelin
5353
*/
5454
public class JythonBindings implements Bindings {
@@ -71,8 +71,7 @@ public class JythonBindings implements Bindings {
7171
* PythonInterpreter, as the ScriptModule has a hard
7272
* reference to its ScriptEngine.
7373
*/
74-
private Map<String, WeakReference<Object>> shallowMap =
75-
new HashMap<String, WeakReference<Object>>();
74+
private final Map<String, WeakReference<Object>> shallowMap = new HashMap<>();
7675

7776
public JythonBindings(final PythonInterpreter interpreter) {
7877
this.interpreter = interpreter;
@@ -89,43 +88,44 @@ public boolean isEmpty() {
8988
}
9089

9190
@Override
92-
public boolean containsKey(Object key) {
91+
public boolean containsKey(final Object key) {
9392
return get(key) != null;
9493
}
9594

9695
@Override
97-
public boolean containsValue(Object value) {
96+
public boolean containsValue(final Object value) {
9897
for (final Object value2 : values()) {
9998
if (value.equals(value2)) return true;
10099
}
101100
return false;
102101
}
103102

104103
@Override
105-
public Object get(Object key) {
104+
public Object get(final Object key) {
106105
if (shallowMap.containsKey(key)) {
107106
return shallowMap.get(key).get();
108107
}
109108

110109
try {
111-
return interpreter.get((String)key);
112-
} catch (Error e) {
110+
return interpreter.get((String) key);
111+
}
112+
catch (final Error e) {
113113
return null;
114114
}
115115
}
116116

117117
@Override
118-
public Object put(String key, Object value) {
118+
public Object put(final String key, final Object value) {
119119
final Object result = get(key);
120120

121-
if (value instanceof ScriptModule || value instanceof JythonScriptEngine){
122-
shallowMap.put(key, new WeakReference<Object>(value));
121+
if (value instanceof ScriptModule || value instanceof JythonScriptEngine) {
122+
shallowMap.put(key, new WeakReference<>(value));
123123
}
124124
else {
125125
try {
126126
interpreter.set(key, value);
127127
}
128-
catch (Error e) {
128+
catch (final Error e) {
129129
// ignore
130130
}
131131
}
@@ -134,23 +134,25 @@ public Object put(String key, Object value) {
134134
}
135135

136136
@Override
137-
public Object remove(Object key) {
137+
public Object remove(final Object key) {
138138
final Object result = get(key);
139139
if (shallowMap.containsKey(key)) shallowMap.remove(key);
140-
else if (result != null) interpreter.getLocals().__delitem__((String)key);
140+
else if (result != null) interpreter.getLocals().__delitem__((String) key);
141141

142142
return result;
143143
}
144144

145145
@Override
146-
public void putAll(Map<? extends String, ? extends Object> toMerge) {
147-
for (final Entry<? extends String, ? extends Object> entry : toMerge.entrySet()) {
146+
public void putAll(final Map<? extends String, ? extends Object> toMerge) {
147+
for (final Entry<? extends String, ? extends Object> entry : toMerge
148+
.entrySet())
149+
{
148150
put(entry.getKey(), entry.getValue());
149151
}
150152
}
151153

152154
private PyStringMap dict() {
153-
return (PyStringMap)interpreter.getLocals();
155+
return (PyStringMap) interpreter.getLocals();
154156
}
155157

156158
@Override
@@ -160,7 +162,7 @@ public void clear() {
160162

161163
@Override
162164
public Set<String> keySet() {
163-
final Set<String> result = new HashSet<String>();
165+
final Set<String> result = new HashSet<>();
164166
for (final Object name : dict().keys()) {
165167
result.add(name.toString());
166168
}
@@ -169,18 +171,21 @@ public Set<String> keySet() {
169171

170172
@Override
171173
public Collection<Object> values() {
172-
final List<Object> result = new ArrayList<Object>();
173-
for (final Object name : dict().keys()) try {
174-
result.add(get(name));
175-
} catch (Error exc) {
176-
// ignore for now
174+
final List<Object> result = new ArrayList<>();
175+
for (final Object name : dict().keys()) {
176+
try {
177+
result.add(get(name));
178+
}
179+
catch (final Error exc) {
180+
// ignore for now
181+
}
177182
}
178183
return result;
179184
}
180185

181186
@Override
182187
public Set<Entry<String, Object>> entrySet() {
183-
final Set<Entry<String, Object>> result = new HashSet<Entry<String, Object>>();
188+
final Set<Entry<String, Object>> result = new HashSet<>();
184189
for (final Object name : dict().keys()) {
185190
result.add(new Entry<String, Object>() {
186191

@@ -195,7 +200,7 @@ public Object getValue() {
195200
}
196201

197202
@Override
198-
public Object setValue(Object value) {
203+
public Object setValue(final Object value) {
199204
throw new UnsupportedOperationException();
200205
}
201206
});

src/main/java/org/scijava/plugins/scripting/jython/JythonReferenceCleaner.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
* %%
99
* Redistribution and use in source and binary forms, with or without
1010
* modification, are permitted provided that the following conditions are met:
11-
*
11+
*
1212
* 1. Redistributions of source code must retain the above copyright notice,
1313
* this list of conditions and the following disclaimer.
1414
* 2. Redistributions in binary form must reproduce the above copyright notice,
1515
* this list of conditions and the following disclaimer in the documentation
1616
* and/or other materials provided with the distribution.
17-
*
17+
*
1818
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1919
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2020
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -45,7 +45,7 @@
4545
/**
4646
* A helper class for purging dangling references within a Jython interpreter
4747
* after it executes a script.
48-
*
48+
*
4949
* @author Mark Hiner
5050
*/
5151
public class JythonReferenceCleaner {
@@ -55,9 +55,9 @@ public class JythonReferenceCleaner {
5555
// See http://resources.ej-technologies.com/jprofiler/help/doc/index.html
5656

5757
private final LinkedList<JythonEnginePhantomReference> phantomReferences =
58-
new LinkedList<JythonEnginePhantomReference>();
58+
new LinkedList<>();
5959
private final ReferenceQueue<JythonScriptEngine> queue =
60-
new ReferenceQueue<JythonScriptEngine>();
60+
new ReferenceQueue<>();
6161

6262
private boolean shutDown = false;
6363

@@ -146,7 +146,7 @@ public JythonEnginePhantomReference(final JythonScriptEngine engine,
146146
}
147147

148148
public void cleanup() {
149-
final List<String> scriptLocals = new ArrayList<String>();
149+
final List<String> scriptLocals = new ArrayList<>();
150150
final PythonInterpreter interp = interpreter;
151151
if (interp == null) return;
152152

src/main/java/org/scijava/plugins/scripting/jython/JythonScriptEngine.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
* %%
99
* Redistribution and use in source and binary forms, with or without
1010
* modification, are permitted provided that the following conditions are met:
11-
*
11+
*
1212
* 1. Redistributions of source code must retain the above copyright notice,
1313
* this list of conditions and the following disclaimer.
1414
* 2. Redistributions in binary form must reproduce the above copyright notice,
1515
* this list of conditions and the following disclaimer in the documentation
1616
* and/or other materials provided with the distribution.
17-
*
17+
*
1818
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1919
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2020
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -44,11 +44,10 @@
4444

4545
/**
4646
* A Python interpreter based on Jython.
47-
*
47+
*
4848
* @author Johannes Schindelin
4949
*/
50-
public class JythonScriptEngine extends AbstractScriptEngine
51-
{
50+
public class JythonScriptEngine extends AbstractScriptEngine {
5251

5352
protected final PythonInterpreter interpreter;
5453

@@ -73,7 +72,8 @@ public Object eval(final Reader reader) throws ScriptException {
7372
setup();
7473
try {
7574
final String filename = getString(ScriptEngine.FILENAME);
76-
return Py.runCode(interpreter.compile(reader, filename), null, interpreter.getLocals());
75+
return Py.runCode(interpreter.compile(reader, filename), null, interpreter
76+
.getLocals());
7777
}
7878
catch (final Exception e) {
7979
throw new ScriptException(e);
@@ -97,7 +97,7 @@ protected void setup() {
9797
}
9898

9999
private String getString(final String key) {
100-
Object result = get(key);
100+
final Object result = get(key);
101101
return result == null ? null : result.toString();
102102
}
103103
}

src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
* %%
99
* Redistribution and use in source and binary forms, with or without
1010
* modification, are permitted provided that the following conditions are met:
11-
*
11+
*
1212
* 1. Redistributions of source code must retain the above copyright notice,
1313
* this list of conditions and the following disclaimer.
1414
* 2. Redistributions in binary form must reproduce the above copyright notice,
1515
* this list of conditions and the following disclaimer in the documentation
1616
* and/or other materials provided with the distribution.
17-
*
17+
*
1818
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1919
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2020
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -47,7 +47,7 @@
4747

4848
/**
4949
* An adapter of the Jython interpreter to the SciJava scripting interface.
50-
*
50+
*
5151
* @author Johannes Schindelin
5252
* @author Mark Hiner <hinerm@gmail.com>
5353
* @see ScriptEngine
@@ -65,9 +65,9 @@ public JythonScriptLanguage() {
6565
@Override
6666
public ScriptEngine getScriptEngine() {
6767
// NB: recursive priorities can only be resolved via inter-service
68-
// dependencies. There is no way to make the ScriptService
69-
// depend on the JythonService because of the hierarchy
70-
// of components. So we have to get the JythonService indirectly.
68+
// dependencies. There is no way to make the ScriptService
69+
// depend on the JythonService because of the hierarchy
70+
// of components. So we have to get the JythonService indirectly.
7171
return context.service(JythonService.class).getScriptEngine();
7272
}
7373

src/main/java/org/scijava/plugins/scripting/jython/JythonService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
* %%
99
* Redistribution and use in source and binary forms, with or without
1010
* modification, are permitted provided that the following conditions are met:
11-
*
11+
*
1212
* 1. Redistributions of source code must retain the above copyright notice,
1313
* this list of conditions and the following disclaimer.
1414
* 2. Redistributions in binary form must reproduce the above copyright notice,
1515
* this list of conditions and the following disclaimer in the documentation
1616
* and/or other materials provided with the distribution.
17-
*
17+
*
1818
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1919
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2020
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -28,6 +28,7 @@
2828
* POSSIBILITY OF SUCH DAMAGE.
2929
* #L%
3030
*/
31+
3132
package org.scijava.plugins.scripting.jython;
3233

3334
import javax.script.ScriptEngine;

src/test/java/org/scijava/plugins/scripting/jython/JythonTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
* %%
99
* Redistribution and use in source and binary forms, with or without
1010
* modification, are permitted provided that the following conditions are met:
11-
*
11+
*
1212
* 1. Redistributions of source code must retain the above copyright notice,
1313
* this list of conditions and the following disclaimer.
1414
* 2. Redistributions in binary form must reproduce the above copyright notice,
1515
* this list of conditions and the following disclaimer in the documentation
1616
* and/or other materials provided with the distribution.
17-
*
17+
*
1818
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1919
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2020
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -51,7 +51,7 @@
5151

5252
/**
5353
* Jython unit tests.
54-
*
54+
*
5555
* @author Johannes Schindelin
5656
*/
5757
public class JythonTest {
@@ -100,7 +100,7 @@ public void testParameters() throws InterruptedException, ExecutionException,
100100
final ScriptModule m = scriptService.run("hello.py", script, true).get();
101101

102102
final Object actual = m.getOutput("language");
103-
final String expected =
103+
final String expected = //
104104
scriptService.getLanguageByName("jython").getLanguageName();
105105
assertEquals(expected, actual);
106106
}

0 commit comments

Comments
 (0)