/*
 * Copyright (c) 2012 Mateusz Parzonka, Eric Bodden
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Mateusz Parzonka - initial API and implementation
 */
package prm4j.indexing.staticdata;

import java.util.HashSet;
import java.util.Set;

import prm4j.api.Parameter;
import prm4j.indexing.realtime.DefaultNode;
import prm4j.indexing.realtime.Node;
import prm4j.indexing.realtime.NodeMap;

/**
 * Every {@link Node} is equipped with a MetaNode, containing factory methods and providing statically computed
 * algorithm logic.
 *
 */
public class MetaNode {

    private MetaNode[] successors;
    private ChainData[] chainData;
    private Set<Parameter<?>> parameterSet;
    private boolean isConfigured = false;
    private int monitorSetCount;

    public MetaNode(Set<Parameter<?>> parameterSet) {
	super();
	this.parameterSet = parameterSet;
    }

    public ChainData[] getChainData() {
	return chainData;
    }

    public Node createNode() {
	return new DefaultNode(this);
    }

    public Node createNode(int parameterId) {
	return successors[parameterId].createNode();
    }

    public NodeMap createNodeMap() {
	// TODO Auto-generated method stub
	return null;
    }

    void setChainingData(ChainData[] chainingData) {
	chainData = chainingData;
    }

    public MetaNode getMetaNode(Parameter<?> parameter) {
	MetaNode node = successors[parameter.getIndex()];
	if (node == null) {
	    Set<Parameter<?>> parameterSet = new HashSet<Parameter<?>>();
	    parameterSet.addAll(this.parameterSet);
	    assert !parameterSet.contains(parameter) : "Parameter set could not have had contained new parameter.";
	    parameterSet.add(parameter);
	    node = new MetaNode(parameterSet);
	    successors[parameter.getIndex()] = node;
	}
	return node;
    }

    public Set<Parameter<?>> getParameterSet() {
        return parameterSet;
    }

    boolean isConfigured() {
	return isConfigured;
    }

    void setConfigured(boolean isConfigured) {
	this.isConfigured = isConfigured;
    }

    public int getMonitorSetCount() {
	return monitorSetCount;
    }

    public void setMonitorSetCount(int monitorSetCount) {
	this.monitorSetCount = monitorSetCount;
    }

}

@@ -1436,27 +1436,24 @@
 Data%5B%5D chain
-ing
 Data) %7B%0A%09cha
@@ -1449,16 +1449,21 @@
 ata) %7B%0A%09
+this.
 chainDat
@@ -1467,27 +1467,24 @@
 Data = chain
-ing
 Data;%0A    %7D%0A

Rename field