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

com.yahoo.tensor.functions.ToStringContext Maven / Gradle / Ivy

Go to download

Library for use in Java components of Vespa. Shared code which do not fit anywhere else.

There is a newer version: 8.409.18
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.tensor.functions;

import com.yahoo.tensor.evaluation.Name;
import com.yahoo.tensor.evaluation.TypeContext;

import java.util.Optional;

/**
 * A context which is passed down to all nested functions when returning a string representation.
 *
 * @author bratseth
 */
public interface ToStringContext {

    static  ToStringContext empty() { return new EmptyStringContext<>(); }

    /** Returns the name an identifier is bound to, or null if not bound in this context */
    String getBinding(String name);

    /** Returns the name an identifier is bound to, or the input name if none */
    default String resolveBinding(String name) {
        String binding = getBinding(name);
        return binding == null ? name : binding;
    }

    /**
     * Returns the context used to resolve types in this, if present.
     * In some functions serialization depends on type information.
     */
    default Optional> typeContext() { return Optional.empty(); }

    /**
     * Returns the parent context of this (the context we're in scope of when this is created),
     * or null if this is the root.
     */
    ToStringContext parent();

    class EmptyStringContext implements ToStringContext {

        @Override
        public String getBinding(String name) { return null; }

        @Override
        public ToStringContext parent() { return null; }

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy