Bonjour j'ai un soucis avec la methode .add d'une arraylist qui ne se comporte pas du tout comme cela devrait être le cas.

voici mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
protected Jeu transformJeu(ElirePhotoEntity jeuElireEntity) throws ConvertionException {
 
		ElirePhoto jeu = (ElirePhoto) new JeuEntityToMetier<>().jeuEntityToMetier(jeuElireEntity);
		jeu.setDateFinInscription(jeuElireEntity.getDateFinInscription());
		jeu.setDateDebut(jeuElireEntity.getDateDebut());
		jeu.setDateFin(jeuElireEntity.getDateFin());
 
		Collection<EntityPhoto> photosEntity = jeuElireEntity.getPhotosEntity();
		ArrayList<Photo> convPhotos = new ArrayList<Photo>();
		Photo convPhoto = new Photo();
		EntityPhoto photoEntity = new EntityPhoto();
		Iterator<EntityPhoto> it = photosEntity.iterator();
 
		while (it.hasNext()) {
			photoEntity = it.next();
			convPhoto.setId(photoEntity.getId());
			System.out.println("dans convert id entity" + photoEntity.getId());
			System.out.println("dans convert id photo" + convPhoto.getId());
			convPhoto.setNom(photoEntity.getNom());
			convPhoto.setUrl(photoEntity.getUrl());
			System.out.println(convPhotos.getClass());
			convPhotos.add(convPhoto);
			Iterator<Photo> y = convPhotos.iterator();
			while (y.hasNext()) {
				Photo photoy = y.next();
				System.out.println("Iter photos dans while" + photoy.getId());
			}
 
			System.out.println("Avant le retour du hasNext" + convPhoto);
		}
 
		System.out.println("En dehors dans la boucle" + convPhoto);
 
		Iterator<Photo> i = convPhotos.iterator();
		while (i.hasNext()) {
			Photo photoi = i.next();
			System.out.println("iter convPhotos en dehors" + photoi.getId());
		}
		jeu.setPhotos(convPhotos);
		return jeu;
	}
}
et voici la trace de ce que j obtiens :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
15:01:33,446 INFO  [stdout] (default task-1) dans convert id entity612
 
15:01:33,447 INFO  [stdout] (default task-1) dans convert id photo612
 
15:01:33,447 INFO  [stdout] (default task-1) class java.util.ArrayList
 
15:01:33,447 INFO  [stdout] (default task-1) Iter photos dans while612
 
15:01:33,448 INFO  [stdout] (default task-1) Avant le retour du hasNextPhoto [ id=612nom=photo3, url=http://localhost:8080/mapGyverWeb/assets/img/jouer3.jpg]
 
15:01:33,448 INFO  [stdout] (default task-1) dans convert id entity613
 
15:01:33,448 INFO  [stdout] (default task-1) dans convert id photo613
 
15:01:33,449 INFO  [stdout] (default task-1) class java.util.ArrayList
 
15:01:33,449 INFO  [stdout] (default task-1) Iter photos dans while613
 
15:01:33,449 INFO  [stdout] (default task-1) Iter photos dans while613
 
15:01:33,450 INFO  [stdout] (default task-1) Avant le retour du hasNextPhoto [ id=613nom=photo4, url=http://localhost:8080/mapGyverWeb/assets/img/jouer4.jpg]
 
15:01:33,450 INFO  [stdout] (default task-1) dans convert id entity610
 
15:01:33,451 INFO  [stdout] (default task-1) dans convert id photo610
 
15:01:33,451 INFO  [stdout] (default task-1) class java.util.ArrayList
 
15:01:33,451 INFO  [stdout] (default task-1) Iter photos dans while610
 
15:01:33,451 INFO  [stdout] (default task-1) Iter photos dans while610
 
15:01:33,452 INFO  [stdout] (default task-1) Iter photos dans while610
 
15:01:33,452 INFO  [stdout] (default task-1) Avant le retour du hasNextPhoto [ id=610nom=photo1, url=http://localhost:8080/mapGyverWeb/assets/img/jouer1.jpg]
 
15:01:33,452 INFO  [stdout] (default task-1) En dehors dans la bouclePhoto [ id=610nom=photo1, url=http://localhost:8080/mapGyverWeb/assets/img/jouer1.jpg]
 
15:01:33,453 INFO  [stdout] (default task-1) iter convPhotos en dehors610
 
15:01:33,453 INFO  [stdout] (default task-1) iter convPhotos en dehors610
 
15:01:33,453 INFO  [stdout] (default task-1) iter convPhotos en dehors610

Donc si je ne me trompe pas ici mon add n'ajoute pas seulement une "case" a mon ArrayList mais réécrit toutes les cases déjà existante ce qui n'est pas son comportement normalement.
en gros au premier passage du while j'ai :
convPhotos = [case 0] id =612

au deuxieme passage convPhotos=[case 0]id=613 [case 1]id=613
Etc

Et j'avoue que je ne vois pas du tout pourquoi ....

Si quelqu'un a une piste je suis preneur
Merci d'avance