Skip to content

Commit eea9427

Browse files
committed
(feat) Format code
1 parent f22609f commit eea9427

File tree

2 files changed

+109
-113
lines changed

2 files changed

+109
-113
lines changed

src/main/java/com/googlecode/aviator/AviatorEvaluator.java

Lines changed: 53 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/main/java/com/googlecode/aviator/Options.java

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,72 @@
22

33
import java.math.MathContext;
44

5+
56
/**
67
* Aviator Evaluator Configuration options.
78
*
89
* @author dennis
910
*
1011
*/
1112
public enum Options {
12-
/**
13-
* Always use double as BigDecimal, default is false.
14-
*
15-
* @since 2.3.4
16-
*/
17-
ALWAYS_USE_DOUBLE_AS_DECIMAL,
13+
/**
14+
* Always use double as BigDecimal, default is false.
15+
*
16+
* @since 2.3.4
17+
*/
18+
ALWAYS_USE_DOUBLE_AS_DECIMAL,
19+
20+
/**
21+
* Optimize level, default is {@link AviatorEvaluator#EVA}
22+
*
23+
* @see AviatorEvaluator#EVAL
24+
* @see AviatorEvaluator#COMPILE
25+
*/
26+
OPTIMIZE_LEVEL,
1827

19-
/**
20-
* Optimize level, default is {@link AviatorEvaluator#EVA}
21-
*
22-
* @see AviatorEvaluator#EVAL
23-
* @see AviatorEvaluator#COMPILE
24-
*/
25-
OPTIMIZE_LEVEL,
28+
/**
29+
* Math context for decimal, default is {@link MathContext.DECIMAL128}
30+
*
31+
* @see MathContext
32+
*/
33+
MATH_CONTEXT,
2634

27-
/**
28-
* Math context for decimal, default is {@link MathContext.DECIMAL128}
29-
*
30-
* @see MathContext
31-
*/
32-
MATH_CONTEXT,
35+
/**
36+
* Whether to trace code generation,default is false.
37+
*/
38+
TRACE;
3339

34-
/**
35-
* Whether to trace code generation,default is false.
36-
*/
37-
TRACE;
40+
public boolean isValidValue(Object val) {
41+
switch (this) {
42+
case ALWAYS_USE_DOUBLE_AS_DECIMAL:
43+
case TRACE:
44+
return val instanceof Boolean;
45+
case OPTIMIZE_LEVEL:
46+
return (val instanceof Integer)
47+
&& (((Integer) val).intValue() == AviatorEvaluator.EVAL || ((Integer) val).intValue() == AviatorEvaluator.COMPILE);
48+
case MATH_CONTEXT:
49+
return val instanceof MathContext;
50+
}
51+
return false;
52+
}
3853

39-
public boolean isValidValue(Object val) {
40-
switch (this) {
41-
case ALWAYS_USE_DOUBLE_AS_DECIMAL:
42-
case TRACE:
43-
return val instanceof Boolean;
44-
case OPTIMIZE_LEVEL:
45-
return (val instanceof Integer)
46-
&& (((Integer) val).intValue() == AviatorEvaluator.EVAL || ((Integer) val)
47-
.intValue() == AviatorEvaluator.COMPILE);
48-
case MATH_CONTEXT:
49-
return val instanceof MathContext;
50-
}
51-
return false;
52-
}
5354

54-
/**
55-
* Returns the default value of option.
56-
*
57-
* @return
58-
*/
59-
public Object getDefaultValue() {
60-
switch (this) {
61-
case ALWAYS_USE_DOUBLE_AS_DECIMAL:
62-
return false;
63-
case OPTIMIZE_LEVEL:
64-
return AviatorEvaluator.EVAL;
65-
case MATH_CONTEXT:
66-
return MathContext.DECIMAL128;
67-
case TRACE:
68-
return Boolean.valueOf(System.getProperty("aviator.asm.trace",
69-
"false"));
70-
}
71-
return null;
72-
}
55+
/**
56+
* Returns the default value of option.
57+
*
58+
* @return
59+
*/
60+
public Object getDefaultValue() {
61+
switch (this) {
62+
case ALWAYS_USE_DOUBLE_AS_DECIMAL:
63+
return false;
64+
case OPTIMIZE_LEVEL:
65+
return AviatorEvaluator.EVAL;
66+
case MATH_CONTEXT:
67+
return MathContext.DECIMAL128;
68+
case TRACE:
69+
return Boolean.valueOf(System.getProperty("aviator.asm.trace", "false"));
70+
}
71+
return null;
72+
}
7373
}

0 commit comments

Comments
 (0)