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
4848
4949/**
5050 * A {@link Bindings} wrapper around Jython's local variables.
51- *
51+ *
5252 * @author Johannes Schindelin
5353 */
5454public 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 });
0 commit comments