All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yahoo.vespa.indexinglanguage.expressions.HexEncodeExpression Maven / Gradle / Ivy

There is a newer version: 8.441.21
Show newest version
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.indexinglanguage.expressions;

import com.yahoo.document.DataType;
import com.yahoo.document.datatypes.LongFieldValue;
import com.yahoo.document.datatypes.StringFieldValue;

/**
 * @author Simon Thoresen Hult
 */
public final class HexEncodeExpression extends Expression {

    public HexEncodeExpression() {
        super(DataType.LONG);
    }

    @Override
    public DataType setInputType(DataType inputType, VerificationContext context) {
        super.setInputType(inputType, DataType.LONG, context);
        return DataType.STRING;
    }

    @Override
    public DataType setOutputType(DataType outputType, VerificationContext context) {
        super.setOutputType(DataType.STRING, outputType, null, context);
        return DataType.LONG;
    }

    @Override
    protected void doVerify(VerificationContext context) {
        context.setCurrentType(createdOutputType());
    }

    @Override
    protected void doExecute(ExecutionContext context) {
        long input = ((LongFieldValue) context.getCurrentValue()).getLong();
        context.setCurrentValue(new StringFieldValue(Long.toHexString(input)));
    }

    @Override
    public DataType createdOutputType() { return DataType.STRING; }

    @Override
    public String toString() { return "hexencode"; }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof HexEncodeExpression)) return false;
        return true;
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy