@@ -113,8 +113,9 @@ public final class AviatorEvaluator {
113113 public static int BYTECODE_VER = Opcodes .V1_5 ;
114114
115115 private static OutputStream traceOutputStream = System .out ;
116-
117- private static final ConcurrentHashMap <Options , Object > options = new ConcurrentHashMap <Options , Object >();
116+
117+ private static final ConcurrentHashMap <Options , Object > options = new ConcurrentHashMap <Options , Object >();
118+
118119
119120 /**
120121 * Configure whether to trace code generation
@@ -123,47 +124,45 @@ public final class AviatorEvaluator {
123124 * @param t
124125 * true is to trace,default is false.
125126 */
126- public static void setTrace (boolean t ) {
127- setOption (Options .TRACE , t );
128- }
129-
130- /**
131- * Adds a evaluator option
132- *
133- * @since 2.3.4
134- * @see Options
135- * @param opt
136- * @param val
137- */
138- public static void setOption (Options opt , Object val ) {
139- if (opt == null || val == null ) {
140- throw new IllegalArgumentException (
141- "Option and value should not be null." );
142- }
143- if (!opt .isValidValue (val )) {
144- throw new IllegalArgumentException ("Invalid value for option:"
145- + opt .name ());
146- }
147- options .put (opt , val );
148- if (opt == Options .OPTIMIZE_LEVEL ) {
149- optimizeLevel = -1 ;
150- }
151- }
152-
153- /**
154- * Returns the current evaluator option value, returns null if missing.
155- *
156- * @param opt
157- * @return
158- */
159- @ SuppressWarnings ("unchecked" )
160- public static <T > T getOption (Options opt ) {
161- Object val = options .get (opt );
162- if (val == null ) {
163- val = opt .getDefaultValue ();
164- }
165- return (T ) val ;
166- }
127+ public static void setTrace (boolean t ) {
128+ setOption (Options .TRACE , t );
129+ }
130+
131+
132+ /**
133+ * Adds a evaluator option
134+ *
135+ * @since 2.3.4
136+ * @see Options
137+ * @param opt
138+ * @param val
139+ */
140+ public static void setOption (Options opt , Object val ) {
141+ if (opt == null || val == null ) {
142+ throw new IllegalArgumentException ("Option and value should not be null." );
143+ }
144+ if (!opt .isValidValue (val )) {
145+ throw new IllegalArgumentException ("Invalid value for option:" + opt .name ());
146+ }
147+ options .put (opt , val );
148+ }
149+
150+
151+ /**
152+ * Returns the current evaluator option value, returns null if missing.
153+ *
154+ * @param opt
155+ * @return
156+ */
157+ @ SuppressWarnings ("unchecked" )
158+ public static <T > T getOption (Options opt ) {
159+ Object val = options .get (opt );
160+ if (val == null ) {
161+ val = opt .getDefaultValue ();
162+ }
163+ return (T ) val ;
164+ }
165+
167166
168167 /**
169168 * Get current trace output stream,default is System.out
@@ -182,9 +181,9 @@ public static OutputStream getTraceOutputStream() {
182181 * @deprecated Please use {@link #getOption(Options)}
183182 * @return
184183 */
185- public static MathContext getMathContext () {
186- return getOption (Options .MATH_CONTEXT );
187- }
184+ public static MathContext getMathContext () {
185+ return getOption (Options .MATH_CONTEXT );
186+ }
188187
189188
190189 /**
@@ -500,27 +499,24 @@ private static Expression innerCompile(final String expression, boolean cached)
500499 ExpressionParser parser = new ExpressionParser (lexer , codeGenerator );
501500 return parser .parse ();
502501 }
503-
504- private static int optimizeLevel = -1 ;
505502
506- private static int getOptimizeLevel () {
507- // cache it, avoid unboxing.
508- if (optimizeLevel == -1 ) {
509- optimizeLevel = getOption (Options .OPTIMIZE_LEVEL );
510- }
511- return optimizeLevel ;
512- }
503+
504+ private static int getOptimizeLevel () {
505+ return getOption (Options .OPTIMIZE_LEVEL );
506+ }
513507
514508
515509 private static CodeGenerator newCodeGenerator (boolean cached ) {
516510 switch (getOptimizeLevel ()) {
517511 case COMPILE :
518512 ASMCodeGenerator asmCodeGenerator =
519- new ASMCodeGenerator (getAviatorClassLoader (cached ), traceOutputStream , (Boolean )getOption (Options .TRACE ));
513+ new ASMCodeGenerator (getAviatorClassLoader (cached ), traceOutputStream ,
514+ (Boolean ) getOption (Options .TRACE ));
520515 asmCodeGenerator .start ();
521516 return asmCodeGenerator ;
522517 case EVAL :
523- return new OptimizeCodeGenerator (getAviatorClassLoader (cached ), traceOutputStream , (Boolean )getOption (Options .TRACE ));
518+ return new OptimizeCodeGenerator (getAviatorClassLoader (cached ), traceOutputStream ,
519+ (Boolean ) getOption (Options .TRACE ));
524520 default :
525521 throw new IllegalArgumentException ("Unknow option " + getOptimizeLevel ());
526522 }
0 commit comments