001/**
002 * CombineQueryAndCasesMethod.java
003 * jCOLIBRI2 framework. 
004 * @author Juan A. Recio-Garc�a.
005 * GAIA - Group for Artificial Intelligence Applications
006 * http://gaia.fdi.ucm.es
007 * 05/01/2007
008 */
009package es.ucm.fdi.gaia.jcolibri.method.reuse;
010
011
012import java.util.ArrayList;
013import java.util.Collection;
014import java.util.List;
015
016import org.apache.log4j.LogManager;
017
018import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRCase;
019import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRQuery;
020import es.ucm.fdi.gaia.jcolibri.util.CopyUtils;
021
022/**
023 * Method to combine the description of a query with the other components of a case: solution, result and justification of solution.
024 * @author Juan A. Recio-Garcia
025 * @version 2.0
026 */
027public class CombineQueryAndCasesMethod {
028
029        /**
030         * Combienes some cases with a query. 
031         * This method creates a new copy for each case and overwrites their description with the description of the query.
032         */
033        public static List<CBRCase> combine(CBRQuery query, Collection<CBRCase> cases)
034        {
035                ArrayList<CBRCase> res = new ArrayList<CBRCase>();
036                
037                for(CBRCase orig: cases)
038                {
039                        try {
040                                CBRCase copy = orig.getClass().newInstance();
041                                
042                                copy.setDescription(CopyUtils.copyCaseComponent(query.getDescription()));
043                                copy.setSolution(CopyUtils.copyCaseComponent(orig.getSolution()));
044                                copy.setJustificationOfSolution(CopyUtils.copyCaseComponent(orig.getJustificationOfSolution()));
045                                copy.setResult(CopyUtils.copyCaseComponent(orig.getResult()));
046                                
047                                res.add(copy);
048                                
049                                
050                        } catch (Exception e) {
051                                LogManager.getLogger(CombineQueryAndCasesMethod.class).error("Error combining cases and query", e);
052                        } 
053                }       
054                return res;
055        }
056}