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

com.espertech.esper.client.soda.View Maven / Gradle / Ivy

There is a newer version: 7.1.0
Show newest version
/*
 ***************************************************************************************
 *  Copyright (C) 2006 EsperTech, Inc. All rights reserved.                            *
 *  http://www.espertech.com/esper                                                     *
 *  http://www.espertech.com                                                           *
 *  ---------------------------------------------------------------------------------- *
 *  The software in this package is published under the terms of the GPL license       *
 *  a copy of which has been included with this distribution in the license.txt file.  *
 ***************************************************************************************
 */
package com.espertech.esper.client.soda;

import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * A view provides a projection upon a stream, such as a data window, grouping or unique.
 * For views, the namespace is an optional value and can be null for any-namespace.
 */
public class View extends EPBaseNamedObject {
    private static final long serialVersionUID = 704960216123401420L;

    /**
     * Ctor.
     */
    public View() {
    }

    /**
     * Creates a view.
     *
     * @param namespace is thie view namespace, i.e. "win" for data windows
     * @param name      is the view name, i.e. "length" for length window
     * @return view
     */
    public static View create(String namespace, String name) {
        return new View(namespace, name, new ArrayList());
    }

    /**
     * Creates a view.
     *
     * @param name is the view name, i.e. "length" for length window
     * @return view
     */
    public static View create(String name) {
        return new View(null, name, new ArrayList());
    }

    /**
     * Creates a view.
     *
     * @param namespace  is thie view namespace, i.e. "win" for data windows
     * @param name       is the view name, i.e. "length" for length window
     * @param parameters is a list of view parameters, or empty if there are no parameters for the view
     * @return view
     */
    public static View create(String namespace, String name, List parameters) {
        return new View(namespace, name, parameters);
    }

    /**
     * Creates a view.
     *
     * @param name       is the view name, i.e. "length" for length window
     * @param parameters is a list of view parameters, or empty if there are no parameters for the view
     * @return view
     */
    public static View create(String name, List parameters) {
        return new View(null, name, parameters);
    }

    /**
     * Creates a view.
     *
     * @param namespace  is thie view namespace, i.e. "win" for data windows
     * @param name       is the view name, i.e. "length" for length window
     * @param parameters is a list of view parameters, or empty if there are no parameters for the view
     * @return view
     */
    public static View create(String namespace, String name, Expression... parameters) {
        if (parameters != null) {
            return new View(namespace, name, Arrays.asList(parameters));
        } else {
            return new View(namespace, name, new ArrayList());
        }
    }

    /**
     * Creates a view.
     *
     * @param name       is the view name, i.e. "length" for length window
     * @param parameters is a list of view parameters, or empty if there are no parameters for the view
     * @return view
     */
    public static View create(String name, Expression... parameters) {
        if (parameters != null) {
            return new View(null, name, Arrays.asList(parameters));
        } else {
            return new View(null, name, new ArrayList());
        }
    }

    /**
     * Creates a view.
     *
     * @param namespace  is thie view namespace, i.e. "win" for data windows
     * @param name       is the view name, i.e. "length" for length window
     * @param parameters is a list of view parameters, or empty if there are no parameters for the view
     */
    public View(String namespace, String name, List parameters) {
        super(namespace, name, parameters);
    }

    /**
     * Render view.
     *
     * @param writer to render to
     */
    public void toEPLWithHash(StringWriter writer) {
        writer.write(getName());
        if (!getParameters().isEmpty()) {
            writer.write('(');
            ExpressionBase.toPrecedenceFreeEPL(getParameters(), writer);
            writer.write(')');
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy