Bonjour,
J'ai l'architecture suivante :
A----B
----C--------E
----D
sont des classes java avec les proprietés suivat :
pour la classe A par exemple :
Class A{
String id;
String nom;
String prenom;
A pereA;
Collection filsA ;
public String getId(){
return id ;
}
public String getNom(){
return nom ;
}
public String getPrenom(){
return prenom ;
}
public A getPereA(){
return pereA ;
}
public getFilsA(){
return filsA;
}
public void setFilsA(Collection filsA){
this.filsA = filsA;
}
public void setPereA(A pereA){
this.pereA = pereA ;
}
public void setId(String id){
this.id = id ;
}
public void setNom(String nom){
this.nom = nom ;
}
public void setPrenom(String prenom){
this.prenom = prenom ;
}
}
et c'est pareil pour B,C,E.
donc A a comme fils B,C,D et C comme fils E et comme pere A.
la problématique est la suivante :
on veut charger ces classes dans une nouvelle architecture
VA----VB
----VC-----VE
----VD
avec :
Class VA{
String id;
String nom;
String prenom;
A pereA;
Collection filsA ;
public String getId(){
return id ;
}
public String getNom(){
return nom ;
}
public String getPrenom(){
return prenom ;
}
public A getPereA(){
return pereA ;
}
public getFilsA(){
return filsA;
}
public void setFilsA(Collection filsA){
this.filsA = filsA;
}
public void setPereA(A pereA){
this.pereA = pereA ;
}
public void setId(String id){
this.id = id ;
}
public void setNom(String nom){
this.nom = nom ;
}
public void setPrenom(String prenom){
this.prenom = prenom ;
}
}
et VA,VB,VC,VE ont la meme representation de données que A,B,C,D,E
pour cela j'utilise une méthode récursive :
public VA getV(A a){
Va va = new Va ;
va.setId(a.getId());
va.setNom(a.getNom());
va.setPrenom(a.getPrenom());
//maintenant le problème :
A pereA = a.getPereA();
vaPere = getV(pereA) ;
va.setPereA(vaPere);
Collection filsA = a.getFilsA();
a.setFilsA(getVAColl(filsA)) ;
}
public Collection getVAColl(Collection filsA) {
Collection vdColl = null;
if (filsA != null) {
vdColl = new HashSet();
for (Iterator i = filsA.iterator(); i.hasNext() {
A a = (A) i.next();
VA va = getVA(a);
vdColl.add(va);
}
}
return vitrineDataList;
}
avez-vous une solution de ce problème?
Merci d'avance.
Partager