public boolean modifierVideo( String oldTitre, String titre, int annee, int eval, boolean type, String comments, String categories) { ArrayList<String> arrayCategories = liste.obtenirCles(); Video video; try { video = new Video(titre, annee, eval, type); } catch (Exception ex) { this.messageErreur(ex.getMessage()); return false; } video.setCommentaires(comments); Video oldVideo = obtenirVideo(oldTitre); int indexOfVideo; boolean confirmation = false; for (String categorie : arrayCategories) { indexOfVideo = liste.obtenirIndex(categorie, oldVideo); if (indexOfVideo >= 0) { confirmation = liste.modifier(categorie, video, indexOfVideo); } } modeModification(); return confirmation; }
// Big bunch of AJOUTS public boolean ajouterVideo( String titre, int annee, boolean type, int eval, String comments, String categories) { try { // Creer un objet video avec TITRE ANNEE TYPE EVAL COMMENTS Video video = new Video(titre, annee, eval, type); video.setCommentaires(comments); String[] arrayCategories = categories.split(System.getProperty("line.separator")); boolean confirmation = false; // Ajouter cette video dans toutes les categories for (String categorie : arrayCategories) { confirmation = liste.ajouter(categorie, video); } if (confirmation) { JOptionPane.showMessageDialog(fenetre, video.getTitre() + " ajouté à la liste!"); return true; } else { JOptionPane.showMessageDialog( fenetre, video.getTitre() + " n'a pas été ajouté à la liste!"); return false; } } catch (Exception ex) { this.messageErreur(ex.getMessage()); return false; } }
public void charger() throws Exception { String PATH = "./videos.txt"; ArrayList<String> stringVideos = new ArrayList(); // Regex String pattern = "\\[(.*?)\\]"; String backupPattern = "/\\\\[(.*?)\\\\]/"; Pattern r = Pattern.compile(pattern); String line = null; try { BufferedReader bufferedReader = new BufferedReader(new FileReader(PATH)); while ((line = bufferedReader.readLine()) != null) { line = line.replace("[*]", "\n"); stringVideos.add(line); } bufferedReader.close(); } catch (FileNotFoundException ex) { this.messageErreurFatale(ex.getMessage()); } catch (IOException ex) { this.messageErreurFatale(ex.getMessage()); } for (String stringer : stringVideos) { String[] elements = stringer.split("::"); String titre = elements[0]; int annee = Integer.parseInt(elements[1]); boolean type = false; if (elements[2] /*.toString()*/.equals("FILM")) { type = true; } else if (elements[2] /*.toString()*/.equals("SÉRIE TV")) { type = false; } else { this.messageErreur("ERREUR TYPE"); } int eval = Integer.parseInt(elements[3]); String commentaires = elements[4]; Video video = new Video(titre, annee, eval, type); video.setCommentaires(commentaires); for (int i = 5; i < elements.length; i++) { liste.ajouter(elements[i], video); } } }