View Javadoc
1   /*
2   Copyright (c) 2017 James Ahlborn
3   
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7   
8       http://www.apache.org/licenses/LICENSE-2.0
9   
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16  
17  package com.healthmarketscience.jackcess.impl.expr;
18  
19  import java.math.BigDecimal;
20  import java.time.LocalDateTime;
21  
22  import com.healthmarketscience.jackcess.expr.LocaleContext;
23  import com.healthmarketscience.jackcess.expr.Value;
24  
25  /**
26   *
27   * @author James Ahlborn
28   */
29  public abstract class BaseDelayedValue implements Value
30  {
31    private Value _val;
32  
33    protected BaseDelayedValue() {
34    }
35  
36    private Value getDelegate() {
37      if(_val == null) {
38        _val = eval();
39      }
40      return _val;
41    }
42  
43    @Override
44    public boolean isNull() {
45      return(getType() == Type.NULL);
46    }
47  
48    @Override
49    public Value.Type getType() {
50      return getDelegate().getType();
51    }
52  
53    @Override
54    public Object get() {
55      return getDelegate().get();
56    }
57  
58    @Override
59    public boolean getAsBoolean(LocaleContext ctx) {
60      return getDelegate().getAsBoolean(ctx);
61    }
62  
63    @Override
64    public String getAsString(LocaleContext ctx) {
65      return getDelegate().getAsString(ctx);
66    }
67  
68    @Override
69    public LocalDateTime getAsLocalDateTime(LocaleContext ctx) {
70      return getDelegate().getAsLocalDateTime(ctx);
71    }
72  
73    @Override
74    public Value getAsDateTimeValue(LocaleContext ctx) {
75      return getDelegate().getAsDateTimeValue(ctx);
76    }
77  
78    @Override
79    public Integer getAsLongInt(LocaleContext ctx) {
80      return getDelegate().getAsLongInt(ctx);
81    }
82  
83    @Override
84    public Double getAsDouble(LocaleContext ctx) {
85      return getDelegate().getAsDouble(ctx);
86    }
87  
88    @Override
89    public BigDecimal getAsBigDecimal(LocaleContext ctx) {
90      return getDelegate().getAsBigDecimal(ctx);
91    }
92  
93    protected abstract Value eval();
94  }