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

cdc.applic.consistency.impl.BlockIncImpl Maven / Gradle / Ivy

The newest version!
package cdc.applic.consistency.impl;

import java.io.PrintStream;
import java.util.List;
import java.util.Set;

import cdc.applic.consistency.Composition;
import cdc.applic.dictionaries.Dictionary;
import cdc.applic.expressions.Expression;

/**
 * Implementation of {@link Block} b=y inclusion.
 *
 * @author Damien Carbonne
 */
public class BlockIncImpl implements Block {
    private final BlockDefImpl owner;
    private final String id;
    private BlockDefImpl def = null;

    protected void fix(ConsistencyDataImpl data) {
        if (def == null) {
            def = data.getNode(id, BlockDefImpl.class);
            if (def != null) {
                if (def.isOver(owner)) {
                    throw new IllegalStateException("Composition cycle detected");
                }
                def.addParent(owner);
            }
        }
    }

    public BlockIncImpl(BlockDefImpl owner,
                        String id) {
        this.owner = owner;
        this.id = id;
    }

    private BlockDefImpl getDef() {
        return def;
    }

    @Override
    public String getId() {
        return id;
    }

    @Override
    public String getLabel() {
        return getDef().getLabel();
    }

    @Override
    public Dictionary getDictionary() {
        return getDef().getDictionary();
    }

    @Override
    public Expression getApplicability() {
        return getDef().getApplicability();
    }

    @Override
    public Composition getComposition() {
        return getDef().getComposition();
    }

    @Override
    public Set getParents() {
        return getDef().getParents();
    }

    @Override
    public List getChildren() {
        return getDef().getChildren();
    }

    @Override
    public void print(PrintStream out,
                      int level) {
        indent(out, level);
        out.println("BlockInc '" + getId() + "'");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy