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

astra.core.Fragment Maven / Gradle / Ivy

There is a newer version: 1.4.2
Show newest version
package astra.core;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import astra.formula.Formula;
import astra.term.Primitive;
import astra.term.Term;

public class Fragment {
	private Map modules = new HashMap();
	ASTRAClass clazz;
	Fragment next;
	List linearization;
	
	
	public Fragment(ASTRAClass clazz) throws ASTRAClassNotFoundException {
		this.clazz = clazz;
		linearization = clazz.getLinearization();
	}

	public List getLinearization() {
		return linearization;
	}

	public void addModule(String name, Class cls, Agent agent) {
		try {
			Module module = (Module) cls.getDeclaredConstructor(new Class[0]).newInstance(new Object[0]);
			module.setAgent(agent);
			modules.put(name,  module);
		} catch (Exception e) {
			e.printStackTrace();
			return;
		}
	}

	public void addModule(String name, Class cls, Term[] params, Agent agent) {
		Object[] values = getValues(params);
		try {
			Module module = (Module) cls.getDeclaredConstructor(getTypes(values)).newInstance(values);
			module.setAgent(agent);
			modules.put(name,  module);
		} catch (Exception e) {
			e.printStackTrace();
			return;
		}
	}

	private Object[] getValues(Term[] params) {
		Object[] values = new Object[params.length];
		for (int i=0; i) params[i]).value();
			} else {
				throw new RuntimeException("Invalid type in module constructor: " + params[i]);
			}
		}
		return values;
	}
	private Class[] getTypes(Object[] values) {
		Class[] classes = new Class[values.length];
		for (int i=0; i getMatchingFormulae(Formula predicate) {
		return null;
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy