es.ucm.fdi.gaia.jcolibri.util.CopyUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jCOLIBRI Show documentation
Show all versions of jCOLIBRI Show documentation
jCOLIBRI is a java framework for the development of Case-Based Reasoning systems.
/**
* CopyUtils.java
* jCOLIBRI2 framework.
* @author Juan A. Recio-Garc�a.
* GAIA - Group for Artificial Intelligence Applications
* http://gaia.fdi.ucm.es
* 05/01/2007
*/
package es.ucm.fdi.gaia.jcolibri.util;
import org.apache.logging.log4j.LogManager;
import es.ucm.fdi.gaia.jcolibri.cbrcore.Attribute;
import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRCase;
import es.ucm.fdi.gaia.jcolibri.cbrcore.CaseComponent;
/**
* Utility functions to copy cases or case components.
* @author Juan A. Recio-Garcia
*/
public class CopyUtils {
/**
* Returns a deep copy of a CBRCase.
*/
public static CBRCase copyCBRCase(CBRCase c) {
try {
Class> _class = c.getClass();
CBRCase copy = (CBRCase)_class.newInstance();
copy.setDescription(copyCaseComponent(c.getDescription()));
copy.setSolution(copyCaseComponent(c.getSolution()));
copy.setJustificationOfSolution(copyCaseComponent(c.getJustificationOfSolution()));
copy.setResult(copyCaseComponent(c.getResult()));
return copy;
} catch (Exception e) {
LogManager.getLogger(CopyUtils.class).error("Error copying case "+c);
e.printStackTrace();
}
return null;
}
/**
* Returns a deep copy of a CaseComponent
*/
public static CaseComponent copyCaseComponent(CaseComponent c) {
try {
if(c==null)
return null;
Class> _class = c.getClass();
CaseComponent copy = (CaseComponent)_class.newInstance();
Attribute[] attrs = AttributeUtils.getAttributes(_class);
for(int i=0; i