Populate model/ hierarchy
[yangtools.git] / xpath / yang-xpath-api / src / main / java / org / opendaylight / yangtools / yang / xpath / api / YangXPathMathMode.java
1 /*
2  * Copyright (c) 2019 Pantheon Technologies, s.r.o.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.xpath.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13
14 /**
15  * {@link YangXPathParser} number compliance knobs. This enumeration defines what assumptions the parser can make --
16  * affecting its optimization properties around
17  * <a href="https://en.wikipedia.org/wiki/Constant_folding">constant folding</a> when number expressions are
18  * involved.
19  */
20 @Beta
21 public enum YangXPathMathMode {
22     /**
23      * All number expressions are treated as {@code double}. This in spirit of XPath 1.0 -- any number expression
24      * starts its life as a double, making all operations subject to IEEE754 rounding and range rules.
25      */
26     IEEE754(DoubleXPathMathSupport.INSTANCE),
27
28     /**
29      * All number expressions are treated as infinite-precision numbers. This follows the spirit of YANG 1.1 --
30      * where mostly have integral types and decimal64 mapped to BigDecimal. Non-decimal numbers are mapped either to
31      * {@code int}, {@code long} or {@code BigInteger}.
32      */
33     EXACT(BigDecimalXPathMathSupport.INSTANCE);
34
35     /*
36      * FIXME: 7.0.0: specify and implement this:
37      *
38      * All number expressions are treated either as {@code org.opendaylight.yangtools.yang.common} types with
39      * precision required to hold them. Decimal types are mapped to {@link Decimal64} with all range restrictions
40      * and rounding error implied by it.
41      */
42     // ODL_COMMON;
43
44     private YangXPathMathSupport support;
45
46     YangXPathMathMode(final YangXPathMathSupport support) {
47         this.support = requireNonNull(support);
48     }
49
50     /**
51      * Return {@link YangXPathMathSupport} which provides support for the this mode.
52      *
53      * @return YangXPathMathSupport supporting this mode.
54      */
55     public YangXPathMathSupport getSupport() {
56         return support;
57     }
58 }