Intuitive DSL for Java

Version 2.0.0 · src/main/java/ch/dbalabs/intuitivedsl/parser/ParseResult.java

Git clone
git clone https://www.dbalabs.ch/git/intuitive-dsl-java.git

ParseResult.java

/*
 * This file is part of the Intuitive DSL project.
 * Copyright (c) 2026 DBA Labs - Switzerland. All rights reserved.
 *
 * This program is dual-licensed under a commercial license and the AGPLv3.
 * For commercial licensing, contact us at [email protected] or visit https://www.dbalabs.ch.
 *
 * AGPLv3 licensing:
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, version 3 (19 November 2007).
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/agpl-3.0.html>.
 */

package ch.dbalabs.intuitivedsl.parser;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Stores the results of a successful DSL parsing operation.
 *
 * @author DBA Labs
 */
public class ParseResult {

    private final List<BoundParameter> parameters;
    private final List<String> keywords;

    public record BoundParameter(String name, String context, String value) {}

    public ParseResult() {
        this.parameters = new ArrayList<>();
        this.keywords = new ArrayList<>();
    }

    private ParseResult(List<BoundParameter> parameters, List<String> keywords) {
        this.parameters = new ArrayList<>(parameters);
        this.keywords = new ArrayList<>(keywords);
    }

    public ParseResult copy() {
        return new ParseResult(this.parameters, this.keywords);
    }

    public void addParameter(String name, String context, String value) {
        parameters.add(new BoundParameter(name, context, value));
    }

    public void addKeyword(String keyword) {
        keywords.add(keyword.toUpperCase());
    }

    public List<BoundParameter> getParameters() {
        return Collections.unmodifiableList(parameters);
    }

    public List<String> getKeywords() {
        return Collections.unmodifiableList(keywords);
    }

    /**
     * AUDIT FIX: Exact match only. Abandons the substring concatenation
     * approach to prevent false positive matches on adjacent distinct keywords.
     */
    public boolean hasKeyword(String keyword) {
        return keywords.contains(keyword.toUpperCase());
    }

    public boolean isSuccess() {
        return true;
    }
}