aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/ValueType.java
blob: 06301372dcce09d009f882f006be8755b929d980 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.yahoo.searchlib.rankingexpression.evaluation;// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

import com.yahoo.tensor.TensorType;

import java.util.Optional;

/**
 * The type of a ranking expression value - either a double or a tensor.
 *
 * @author bratseth
 */
public class ValueType {

    private static final ValueType doubleValueType = new ValueType(Optional.empty());

    private final Optional<TensorType> tensorType;

    private ValueType(Optional<TensorType> type) {
        this.tensorType = type;
    }

    /** Returns true if this is a double type */
    public boolean isDouble() { return ! tensorType.isPresent(); }

    /** Returns true if this is a tensor type */
    public boolean isTensor() { return tensorType.isPresent(); }

    /** The specific tensor type of this, or empty if this is not a tensor type */
    public Optional<TensorType> tensorType() { return tensorType; }

    /** Returns the type representing a double */
    public static ValueType doubleType() { return doubleValueType; }

    /** Returns a type representing the given tensor type */
    public static ValueType tensorType(TensorType type) { return new ValueType(Optional.of(type)); }

}