Bonjour,

J'ai une liste d'objets de type "FichePatient" qui a plusieurs attributs "nom, prénom,etc....".

Voici la méthode qui retourne cette liste:

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
 public List getAllFichesPatients(){
 
        FichePatient fichePatient1 = new FichePatient();
        fichePatient1.setNomPatient("Amine");
        fichePatient1.setPrenomPatient("Rachid");
        fichePatient1.setDatePremiereVisitePatient("01/01/2011");
        fichePatient1.setDateDerniereVisitePatient("30/01/2011");
        fichePatient1.setReferenceDossierPatient("refernec 1");
 
 
        FichePatient fichePatient2 = new FichePatient();
        fichePatient2.setNomPatient("talbi");
        fichePatient2.setPrenomPatient("mohammed");
        fichePatient2.setDatePremiereVisitePatient("02/02/2012");
        fichePatient2.setDateDerniereVisitePatient("30/02/2012");
        fichePatient2.setReferenceDossierPatient("refernec 2");
 
 
        FichePatient fichePatient3 = new FichePatient();
        fichePatient3.setNomPatient("zitouni");
        fichePatient3.setPrenomPatient("rabii");
        fichePatient3.setDatePremiereVisitePatient("01/01/2013");
        fichePatient3.setDateDerniereVisitePatient("30/01/2013");
        fichePatient3.setReferenceDossierPatient("refernec 3");
 
        FichePatient fichePatient4 = new FichePatient();
        fichePatient4.setNomPatient("charef");
        fichePatient4.setPrenomPatient("kika");
        fichePatient4.setDatePremiereVisitePatient("01/01/2014");
        fichePatient4.setDateDerniereVisitePatient("30/01/2014");
        fichePatient4.setReferenceDossierPatient("refernec 4");
 
        FichePatient fichePatient5 = new FichePatient();
        fichePatient5.setNomPatient("charef");
        fichePatient5.setPrenomPatient("mskouta");
        fichePatient5.setDatePremiereVisitePatient("01/01/2015");
        fichePatient5.setDateDerniereVisitePatient("30/01/2015");
        fichePatient5.setReferenceDossierPatient("refernec 5");
 
        FichePatient fichePatient6 = new FichePatient();
        fichePatient6.setNomPatient("do3dou3i");
        fichePatient6.setPrenomPatient("jawad");
        fichePatient6.setDatePremiereVisitePatient("01/01/2016");
        fichePatient6.setDateDerniereVisitePatient("30/01/2016");
        fichePatient6.setReferenceDossierPatient("refernec 6");
 
 
        FichePatient fichePatient7 = new FichePatient();
        fichePatient7.setNomPatient("talbi");
        fichePatient7.setPrenomPatient("abd elaziz");
        fichePatient7.setDatePremiereVisitePatient("01/01/2017");
        fichePatient7.setDateDerniereVisitePatient("30/01/2017");
        fichePatient7.setReferenceDossierPatient("refernec 7");
 
 
        FichePatient fichePatient8 = new FichePatient();
        fichePatient8.setNomPatient("Ben chekroun nizar");
        fichePatient8.setPrenomPatient("jamal");
        fichePatient8.setDatePremiereVisitePatient("01/01/2018");
        fichePatient8.setDateDerniereVisitePatient("30/01/2018");
        fichePatient8.setReferenceDossierPatient("refernec 8");
 
 
        fichePatientList.add(fichePatient1);
        fichePatientList.add(fichePatient2);
        fichePatientList.add(fichePatient3);
        fichePatientList.add(fichePatient4);
        fichePatientList.add(fichePatient5);
        fichePatientList.add(fichePatient6);
        fichePatientList.add(fichePatient7);
        fichePatientList.add(fichePatient8);
 
        return fichePatientList;
 
    }
Je veux faire une méthode qui va me permettre de chercher les patients dont le nom commence par la chaine de caractère passé en paramètre.

j'ai crée cette méthode :

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
private List getfichesPatientByNomOrPrenom(String nomPrenom, List fiches){
        //La requete a modifier.
        List result = null;
        if(fiches != null && fiches.size()>0){
           result = new ArrayList();
           Iterator iter = fiches.iterator();
           while(iter.hasNext()){
               FichePatient fichePatient = (FichePatient)iter.next();
               if((fichePatient.getNomPatient().startsWith(nomPrenom) )){
                        result.add(fichePatient);
               }
           }
        }
        return result;
    }

ça marche bien si par exemple je cherche par "ch" ou "cha", j'obtiens bien les deux objets "charef kika" et "charef mskouta".

Problème:

-Le problème que j'ai c'est que lorsque je passe en paramètre "charef k" seulement, je veux récupérer l'objet "charef kika" sachant que "kika" et le prénom.

J'ai pensé à prendre seulement les caractères qui sont avant l'espace, mais le problème se pose pour le cas de par exemple j'ai trois objet dont le nom commence par "ben" comme "ben chekroun" et "ben jelloun" et "ben taleb", donc ce cas j'aurais un problème si je tape "ben chek" car si je prends seulement l'avant espace la chaine "ben" ça va me renvoyer les trois objets.

J'espère bien que j'ai bien expliqué et merci de me donner une solution pour ça.

Merci d'avance.