Skip to content

Commit fd4829d

Browse files
author
duy
committed
Refactor Symja#init
1 parent de151b2 commit fd4829d

File tree

1 file changed

+11
-6
lines changed
  • modules/symja-evaluator/src/main/java/com/symja/evaluator

1 file changed

+11
-6
lines changed

modules/symja-evaluator/src/main/java/com/symja/evaluator/Symja.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -38,37 +38,42 @@ public class Symja {
3838
private final ThreadGroup threadGroup = new ThreadGroup("CalculateThread");
3939
private final ExprEvaluator exprEvaluator;
4040

41-
public Symja() {
42-
init();
41+
private Symja() {
4342
this.exprEvaluator = new ExprEvaluator();
4443
}
4544

4645
@WorkerThread
4746
public static Symja getInstance() {
4847
synchronized (lock) {
4948
if (instance == null) {
49+
initSymja();
5050
instance = new Symja();
5151
}
5252
}
5353
return instance;
5454
}
5555

5656
@WorkerThread
57-
public static void init() {
57+
private static void initSymja() {
5858
if (!systemInited.get()) {
5959
try {
60+
if (DLog.DEBUG) {
61+
Log.d(TAG, "init called");
62+
}
6063
semaphore.acquire();
6164

6265
Config.DISPLAY_JSFIDDLE_BUTTON = false;
6366
Config.JAVA_AWT_DESKTOP_AVAILABLE = false;
6467

6568
F.initSymbols();
66-
ExprEvaluator exprEvaluator = new ExprEvaluator();
67-
Log.d(TAG, String.valueOf(exprEvaluator.eval("Sin(x)+Cos(x)")));
6869

6970
systemInited.set(true);
71+
72+
if (DLog.DEBUG) {
73+
Log.d(TAG, "init done");
74+
}
7075
} catch (Exception e) { // Should not throw error
71-
e.printStackTrace();
76+
Log.e(TAG, e.getMessage(), e);
7277
} finally {
7378
semaphore.release();
7479
}

0 commit comments

Comments
 (0)