Exemplo n.º 1
0
  private String jsonArtistes(Map<String, Artiste> artistes) {
    Map<String, Artiste> artistesTrie = new TreeMap<String, Artiste>(artistes);
    JSONObject jsonResultat = new JSONObject();
    JSONArray jsonArtistes = new JSONArray();
    for (String nome : artistesTrie.keySet()) {
      Artiste artiste = artistesTrie.get(nome);
      JSONObject jsonArtiste = new JSONObject();
      jsonArtiste.put("nom", nome);
      JSONArray jsonAlbums = new JSONArray();
      for (Integer annee : artiste.getAlbums().keySet()) {
        Album album = artiste.getAlbums().get(annee);
        JSONObject newAlbum = new JSONObject();
        newAlbum.put("id", album.getId());
        newAlbum.put("titre", album.getTitre());
        newAlbum.put("annee", album.getAnnee());
        newAlbum.put("qte", album.getQuantite());
        jsonAlbums.add(newAlbum);
      }
      jsonArtiste.accumulate("albums", jsonAlbums);
      jsonArtistes.add(jsonArtiste);
    }
    jsonResultat.accumulate("artistes", jsonArtistes);

    return jsonResultat.toString(2);
  }
Exemplo n.º 2
0
 public void addAlbum(Album album) {
   albums.put(album.getAnnee(), album);
 }