001/** 002 * DirectAttributeCopyMethod.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 org.apache.logging.log4j.LogManager; 013 014import es.ucm.fdi.gaia.jcolibri.cbrcore.Attribute; 015import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRCase; 016import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRQuery; 017import es.ucm.fdi.gaia.jcolibri.cbrcore.CaseComponent; 018import es.ucm.fdi.gaia.jcolibri.exception.AttributeAccessException; 019import es.ucm.fdi.gaia.jcolibri.util.AttributeUtils; 020 021import java.util.Collection; 022 023/** 024 * Copies the value of an attribute in the query to an attribute of a case 025 * @author Juan A. Recio-Garcia 026 * @version 2.0 027 * 028 */ 029public class DirectAttributeCopyMethod { 030 031 /** 032 * Copies the value of the querySource attribute into the caseDestination attribute of the cases. 033 */ 034 public static void copyAttribute(Attribute querySource, Attribute caseDestination, CBRQuery query, Collection<CBRCase> cases) 035 { 036 Object queryValue = AttributeUtils.findValue(querySource, query); 037 try { 038 039 for(CBRCase c: cases) 040 { 041 CaseComponent cc = AttributeUtils.findBelongingComponent(caseDestination, c); 042 caseDestination.setValue(cc, queryValue); 043 } 044 } catch (AttributeAccessException e) { 045 LogManager.getLogger().error(e); 046 } 047 } 048 049}