package org.leibnizcenter.cfg.earleyparser;


import org.leibnizcenter.cfg.algebra.semiring.dbl.Resolvable;
import org.leibnizcenter.cfg.algebra.semiring.dbl.ResolvableLockable;

@SuppressWarnings("WeakerAccess")
public final class ExpressionWrapper extends ResolvableLockable {
    private double literal = Double.NaN;
    private Resolvable expression = null;

    public ExpressionWrapper(final Resolvable expression) {
        if (expression == null) throw new NullPointerException();
        this.expression = expression;
    }

    public ExpressionWrapper(final double literal) {
        this.literal = literal;
    }

    public Resolvable getExpression() {
        if (lock) throw new IllegalStateException("Value already locked");
        if (expression == null) throw new NullPointerException();
        return expression;
    }

    public void setExpression(final Resolvable expression) {
        if (lock) throw new IllegalStateException("Value already locked");
        if (expression == null) throw new NullPointerException();
        this.literal = Double.NaN;
        this.expression = expression;
    }

    public void setExpression(final double expression) {
        if (lock) throw new IllegalStateException("Value already locked");
        this.literal = expression;
        this.expression = null;
    }

    public double resolveAndClean() {
        if (lock) return cached;
        if (expression == null) return literal;
        else {
            literal = expression.resolveFinal();
            expression = null;
            return literal;
        }
    }

    public boolean hasExpression() {
        return expression != null;
    }

    public double getLiteral() {
        return literal;
    }
}

@@ -274,16 +274,53 @@
 ble %7B%0A  
+private double literal = Double.NaN;%0A
   privat
@@ -320,33 +320,37 @@
  private double 
-l
+plusL
 iteral = Double.
@@ -356,16 +356,58 @@
 .NaN;%0A  
+private double timesLiteral = Double.NaN;%0A
   privat
@@ -437,26 +437,24 @@
  = null;%0A%0A  
- 
- 
 public Expre
@@ -497,28 +497,24 @@
 sion) %7B%0A    
-   
- 
 if (expressi
@@ -559,28 +559,24 @@
 tion();%0A    
-  
-  
 this.express
@@ -589,33 +589,29 @@
 expression;%0A
-  
   %7D%0A%0A
-  
   public Exp
@@ -649,28 +649,24 @@
 eral) %7B%0A    
-  
-  
 this.literal
@@ -677,25 +677,21 @@
 iteral;%0A
-  
   %7D%0A%0A
-  
   public
@@ -716,36 +716,32 @@
 ression() %7B%0A    
- 
-   
 if (lock) throw 
@@ -783,36 +783,32 @@
 ready locked%22);%0A
-    
     if (expressi
@@ -853,28 +853,24 @@
 tion();%0A    
- 
-   
 return expre
@@ -872,33 +872,29 @@
 expression;%0A
-  
   %7D%0A%0A
-  
   public voi
@@ -932,36 +932,32 @@
 e expression) %7B%0A
-    
     if (lock) th
@@ -1007,28 +1007,24 @@
 y locked%22);%0A
-    
     if (expr
@@ -1069,28 +1069,24 @@
 xception();%0A
-    
     this.lit
@@ -1104,24 +1104,81 @@
 le.NaN;%0A    
+plusLiteral = Double.NaN;%0A    timesLiteral = Double.NaN;%0A
     this.exp
@@ -1199,25 +1199,21 @@
 ession;%0A
-  
   %7D%0A%0A
-  
   public
@@ -1255,36 +1255,32 @@
 pression) %7B%0A    
-  
-  
 if (lock) throw 
@@ -1330,20 +1330,16 @@
 cked%22);%0A
-    
     this
@@ -1369,45 +1369,272 @@
     
-    this.expression = null;%0A  
+plusLiteral = Double.NaN;%0A    timesLiteral = Double.NaN;%0A    this.expression = null;%0A  %7D%0A  %0A  public void setPlusLiteral(final double plus) %7B%0A    plusLiteral = plus;    %0A
   %7D%0A
+  
 %0A  
+public void setTimesLiteral(final double times) %7B%0A    timesLiteral = times;    %0A  %7D%0A%0A
   pu
@@ -1661,28 +1661,24 @@
 ndClean() %7B%0A
-    
     if (lock
@@ -1698,20 +1698,16 @@
 ed;%0A    
-   
- 
 if (expr
@@ -1734,28 +1734,24 @@
 rn literal;%0A
-    
     else %7B%0A 
@@ -1755,22 +1755,16 @@
 %7B%0A      
-   
-   
 literal 
@@ -1798,22 +1798,16 @@
 ;%0A      
-    
-  
 expressi
@@ -1817,22 +1817,16 @@
 = null;%0A
-      
       re
@@ -1843,29 +1843,21 @@
 al;%0A
-    
     %7D%0A
-  
   %7D%0A%0A  
- 
- 
 publ
@@ -1885,28 +1885,24 @@
 ion() %7B%0A    
-   
- 
 return expre
@@ -1920,19 +1920,15 @@
 ll;%0A
-  
   %7D%0A%0A  
- 
- 
 publ
@@ -1952,20 +1952,16 @@
 ral() %7B%0A
-    
     retu
@@ -1968,20 +1968,18 @@
 rn literal;%0A
-  
   %7D%0A%7D%0A

Update ExpressionWrapper.java