Debian Codegraph @

net/sf/saxon/functions/ConstantFunction.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.functions;
9
10 import net.sf.saxon.expr.Expression;
11 import net.sf.saxon.expr.Literal;
12 import net.sf.saxon.expr.XPathContext;
13 import net.sf.saxon.om.GroundedValue;
14 import net.sf.saxon.om.Sequence;
15 import net.sf.saxon.trans.XPathException;
16 import net.sf.saxon.value.BooleanValue;
17 import net.sf.saxon.value.IntegerValue;
18
19 /**
20 * A ConstantFunction is a zero-argument function that always delivers the same result, supplied
21 * at the time the function is instantiated.
22 */
23
24 public class ConstantFunction extends SystemFunction {
25
26 public GroundedValue<?> value;
27
28 public ConstantFunction(GroundedValue<?> value) {
29 this.value = value;
30 }
31
32 public Sequence<?> call(XPathContext context, Sequence[] arguments) throws XPathException {
33 return value;
34 }
35
36 @Override
37 public Expression makeFunctionCall(Expression[] arguments) {
38 return Literal.makeLiteral(value);
39 }
40
41 @Override
42 public IntegerValue[] getIntegerBounds() {
43 if (value instanceof IntegerValue) {
44 return new IntegerValue[]{(IntegerValue) value, (IntegerValue) value};
45 } else {
46 return null;
47 }
48 }
49
50 public static class True extends ConstantFunction {
51 public True() {
52 super(BooleanValue.TRUE);
53 }
54 }
55
56 public static class False extends ConstantFunction {
57 public False() {
58 super(BooleanValue.FALSE);
59 }
60 }
61
62 }
63