Ajouter une classe à une classe
Bonjour a tous ,
ça fait plusieurs jours que je boucle sur un problème et je n'arrive pas a trouver la solution, je serai très reconnaissante si vous m' aidiez :calim2: ,
alors voila mon code :calim2: d'une méthode appeler Add1
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| if(cr.testSet.size()==1) { cr.m_test = cr.testSet.get(0);}
else if (cr.testSet.size()>1 ) {
cr.m_test = cr.testSet.get(0);
for(int i=1; i<cr.testSet.size(); i++) {
cr.m_test.m_next =cr.testSet.get(i);
System.out.println("j ajjout des test "+ cr.toString());
cr.m_test=cr.m_test.m_next;
System.out.println("aprs mouvement "+ cr.toString());
}
}
System.out.println("la regle est "+ cr.toString());
CR.add(cr);
}
} |
cette methode va prendre en parametre une regle i , de type (if atti=vali and attj=valj and... then classe , mes conditione (atti ,vali ) sont presenter par une class appelé test voila son code
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| private class Test
implements Serializable, RevisionHandler {
/** for serialization */
static final long serialVersionUID = -8925333011350280799L;
/** Attribute to test */
private int m_attr = -1;
/** The attribute's value */
private int m_val;
/** The next test in the rule */
private Test m_next = null;
/**
* Returns whether a given instance satisfies this test.
*
* @param inst the instance to be tested
* @return true if the instance satisfies the test
*/
private boolean satisfies(Instance inst) {
// System.out.print("kkkkkkk"+m_attr);
if ((int) inst.value(m_attr)== m_val) {
if (m_next == null) {
return true;
} else {
return m_next.satisfies(inst);
}
}
return false;
}
/**
* Returns the revision string.
*
* @return the revision
*/
public String getRevision() {
return RevisionUtils.extract("$Revision: 8109 $");
}
} |
j'ai une liste de type test testSet, ma méthode Add1 va lire la réglé passé en argument et a jouter a l ensemble des test de cette regle un autre test qui n'existe pas par exemple la regle c'est if color= red then true après qu'on applique Add1 on va obtenir
Code:
1 2 3
| if color=rend and age =old then true
if color red and age =young then true
if color= red and age =very young the true |
donc pour chaque couple (att, val) qui n exist pas dans la réglé initial je crée une copie de la réglé initiale et j'ajoute ce couple en utilisant la liste je fait add , après a la fin je veux lire cette liste un a un et j’ajoute dans le champ test de ma réglé cr mais cela ne marche voila ce que me donne l exécution
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| the rule for add 2 : If length = small then True
j ajjout des test If length = small
and color = Red then True
aprs mouvement If color = Red then True
la regle est If color = Red then True
j ajjout des test If length = small
and color = Green then True
aprs mouvement If color = Green then True
la regle est If color = Green then True
j ajjout des test If length = small
and color = Blue then True
aprs mouvement If color = Blue then True
la regle est If color = Blue then True
j ajjout des test If length = small
and age = young then True
aprs mouvement If age = young then True
la regle est If age = young then True
j ajjout des test If length = small
and age = old then True
aprs mouvement If age = old then True
la regle est If age = old then True
j ajjout des test If length = small
and neighbors = 1 then True
aprs mouvement If neighbors = 1 then True
la regle est If neighbors = 1 then True
j ajjout des test If length = small
and neighbors = 2-to-4 then True
aprs mouvement If neighbors = 2-to-4 then True
la regle est If neighbors = 2-to-4 then True
j ajjout des test If length = small
and neighbors = 5-to-9 then True
aprs mouvement If neighbors = 5-to-9 then True
la regle est If neighbors = 5-to-9 then True
j ajjout des test If length = small
and neighbors = more-than-10 then True
aprs mouvement If neighbors = more-than-10 then True
la regle est If neighbors = more-than-10 then True |