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

activityconfig.yaml.StmtsDocList Maven / Gradle / Ivy

Go to download

The driver API for engineblock; Provides the interfaces needed to build drivers that can be loaded by engineblock core

There is a newer version: 2.12.65
Show newest version
/*
 *
 *    Copyright 2016 jshook
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 * /
 */

package activityconfig.yaml;

import activityconfig.rawyaml.RawStmtsDocList;
import io.engineblock.util.TagFilter;
import org.jetbrains.annotations.NotNull;

import java.util.*;
import java.util.stream.Collectors;

public class StmtsDocList implements Iterable {

    private RawStmtsDocList rawStmtsDocList;

    public StmtsDocList(RawStmtsDocList rawStmtsDocList) {
        this.rawStmtsDocList = rawStmtsDocList;
    }

    public List getStmtDocs(String tagFilter) {
        TagFilter tf = new TagFilter(tagFilter);
        return getStmtDocs().stream()
                .filter(tf::matchesTagged)
                .collect(Collectors.toList());
    }

    public List getStmtDocs() {
        return rawStmtsDocList.getStmtsDocs().stream()
                .map(StmtsDoc::new)
                .collect(Collectors.toList());
    }

    public List getStmts() {
        return getStmts("");
    }

    /**
     * @return The list of all included statements for all included blocks of  in this document,
     * including the inherited and overridden values from the this doc and the parent block.
     * @param tagFilterSpec a comma-separated tag filter spec
     */
    public List getStmts(String tagFilterSpec) {
        TagFilter ts = new TagFilter(tagFilterSpec);

        List stmts = getStmtDocs().stream()
                .flatMap(d -> d.getStmts().stream())
                .filter(ts::matchesTagged)
                .collect(Collectors.toList());
        return stmts;
    }

    @NotNull
    @Override
    public Iterator iterator() {
        return getStmtDocs().iterator();
    }

    /**
     * Return the list of all bindings combined across all docs, not including
     * the block or statement level bindings.
     * @return A map of all bindings at the doc level.
     */
    public Map getDocBindings() {
        LinkedHashMap docBindings= new LinkedHashMap<>();
        getStmtDocs().stream()
                .map(StmtsDoc::getBindings)
                .forEach(docBindings::putAll);
        return docBindings;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy