package net.ranides.assira.grammar.impl;

import net.ranides.assira.generic.Ref;
import net.ranides.assira.grammar.G4ParserCoverage;

import java.util.ArrayList;
import java.util.Collection;

class CoverageSupport {

    public static class SimpleRuleCoverage implements G4ParserCoverage.RuleCoverage {

        private final String name;
        private final Collection<G4ParserCoverage.BranchCoverage> branches;
        private final Ref<String> alias;
        private int used;

        public SimpleRuleCoverage(String name, Ref<String> alias) {
            this.name = name;
            this.branches = new ArrayList<>();
            this.alias = alias;
            this.used = 0;
        }

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

        @Override
        public Collection<G4ParserCoverage.BranchCoverage> branches() {
            return branches;
        }

        @Override
        public Ref<String> inner() {
            return alias;
        }

        @Override
        public int used() {
            return used;
        }

        @Override
        public void use() {
            used++;
        }
    }

    public static class SimpleBranchCoverage implements G4ParserCoverage.BranchCoverage {

        private final String rule;
        private final String qualifier;
        private final Ref<String> alias;
        private int used;

        public SimpleBranchCoverage(String rule, String qualifier, Ref<String> alias) {
            this.rule = rule;
            this.qualifier = qualifier;
            this.alias = alias;
        }

        @Override
        public String rule() {
            return rule;
        }

        @Override
        public String qualifier() {
            return qualifier;
        }

        @Override
        public Ref<String> inner() {
            return alias;
        }

        @Override
        public int used() {
            return used;
        }

        @Override
        public void use() {
            used++;
        }
    }

}
