diff --git a/UyTube_aplicacion/src/Logica/Clases/Comentario.java b/UyTube_aplicacion/src/Logica/Clases/Comentario.java index 6ef756d79fcff8df5c260293107a04198124533f..29c9a406c3869cf0af284523decd047b5b7a827f 100644 --- a/UyTube_aplicacion/src/Logica/Clases/Comentario.java +++ b/UyTube_aplicacion/src/Logica/Clases/Comentario.java @@ -5,8 +5,9 @@ import java.sql.Date; import java.util.ArrayList; public class Comentario { + private static int contadorComentarios = 1; - + private int id; private Date fecha; private String texto; @@ -18,7 +19,7 @@ public class Comentario { this.id = Comentario.getNuevoID(); this.misComentario = new ArrayList(); } - + public Comentario(int id, Date fecha, String texto, int nivelSubComentario, Usuario usr) { this.id = id; this.fecha = fecha; @@ -28,10 +29,10 @@ public class Comentario { this.misComentario = new ArrayList(); } - public static int getNuevoID(){ + public static int getNuevoID() { return contadorComentarios++; } - + public int getId() { return id; } @@ -76,38 +77,36 @@ public class Comentario { public String toString() { return "Comentario{" + "id=" + id + ", fecha=" + fecha + ", texto=" + texto + ", nivelSubComentario=" + nivelSubComentario + '}'; } - - - public boolean agregarSubComentario(int idComPadre, DtComentario dtC, Usuario usr){ - if(this.id==idComPadre){ + + public boolean agregarSubComentario(int idComPadre, DtComentario dtC, Usuario usr) { + if (this.id == idComPadre) { Comentario com = new Comentario(Comentario.getNuevoID(), dtC.getFecha(), dtC.getTexto(), - this.nivelSubComentario+1, + this.nivelSubComentario + 1, usr); this.misComentario.add(com); return true; - } - else{ - - for (int i = 0; i< misComentario.size();i++){ - if(this.misComentario.get(i).agregarSubComentario(idComPadre,dtC,usr)){ + } else { + + for (int i = 0; i < misComentario.size(); i++) { + if (this.misComentario.get(i).agregarSubComentario(idComPadre, dtC, usr)) { return true; } } return false; } } - - public DtComentario getDT(){ + + public DtComentario getDT() { DtComentario dtC = new DtComentario(this.id, this.usr.getNickname(), this.fecha, this.texto, this.nivelSubComentario); return dtC; } - - public ArrayList<DtComentario> listarSubComentarios(){ + + public ArrayList<DtComentario> listarSubComentarios() { ArrayList lsc = new ArrayList(); - - for(int i = 0; i< this.misComentario.size();i++){ + + for (int i = 0; i < this.misComentario.size(); i++) { lsc.add(this.misComentario.get(i).getDT()); lsc.addAll(this.misComentario.get(i).listarSubComentarios()); } diff --git a/UyTube_aplicacion/src/Logica/main.java b/UyTube_aplicacion/src/Logica/main.java index d6adedcb9c0a46eb79e8633b7c6175861aeb16d7..dc43689d7891bd6b04564ba8c3aaf97424324383 100644 --- a/UyTube_aplicacion/src/Logica/main.java +++ b/UyTube_aplicacion/src/Logica/main.java @@ -9,32 +9,28 @@ import java.util.ArrayList; public class main { public static void main(String[] args) { System.out.println("Hola mundo"); - /*Usuario u1 = new Usuario("nicku1", "email1", new Date(2019-1900,7,15), "c/imagenes/algo1.jpg", "1234", "carlos1", "perez1", null); + Usuario u1 = new Usuario("nicku1", "email1", new Date(2019-1900,7,15), "c/imagenes/algo1.jpg", "1234", "carlos1", "perez1", null); Usuario u2 = new Usuario("nicku2", "email2", new Date(2019-1900,7,15), "c/imagenes/algo2.jpg", "1234", "carlos2", "perez2", null); Usuario u3 = new Usuario("nicku3", "email3", new Date(2019-1900,7,15), "c/imagenes/algo3.jpg", "1234", "carlos3", "perez3", null); Usuario u4 = new Usuario("nicku4", "email4", new Date(2019-1900,7,15), "c/imagenes/algo4.jpg", "1234", "carlos4", "perez4", null); Usuario u5 = new Usuario("nicku5", "email5", new Date(2019-1900,7,15), "c/imagenes/algo5.jpg", "1234", "carlos5", "perez5", null); - Comentario c1 = new Comentario(Comentario.getNuevoID(), new Date(2019-1900,7,15), "1: exelente video", 0, u1); + Comentario c1 = new Comentario(Comentario.getNuevoID(), new Date(2019-1900,7,15), "1", 0, u1); - c1.agregarSubComentario(c1.getId(), new DtComentario(1, null,new Date(2019-1900,7,15), "sub_1_1: mas o menos", 1), u2); - c1.agregarSubComentario(c1.getId(), new DtComentario(1, null,new Date(2019-1900,7,15), "sub_1_2: mas o menos", 1), u3); - c1.agregarSubComentario(c1.getId(), new DtComentario(1, null,new Date(2019-1900,7,15), "sub_1_3: mas o menos", 1), u4); + c1.agregarSubComentario(c1.getId(), new DtComentario(1, null,new Date(2019-1900,7,15), "1.2", 1), u2); + c1.agregarSubComentario(c1.getId(), new DtComentario(1, null,new Date(2019-1900,7,15), "1.3", 1), u3); + c1.agregarSubComentario(c1.getId(), new DtComentario(1, null,new Date(2019-1900,7,15), "1.4", 1), u4); - c1.agregarSubComentario(c1.getId(), new DtComentario(1, null,new Date(2019-1900,7,15), "sub_1_sub_1_1: mas o menos", 2), u3); + c1.agregarSubComentario(4, new DtComentario(1, null,new Date(2019-1900,7,15), "1.4.5", 2), u3); + + c1.agregarSubComentario(2, new DtComentario(1, null,new Date(2019-1900,7,15), "1.2.6", 2), u3); + c1.agregarSubComentario(6, new DtComentario(1, null,new Date(2019-1900,7,15), "1.2.6.7", 2), u3); + c1.agregarSubComentario(4, new DtComentario(1, null,new Date(2019-1900,7,15), "1.4.8", 2), u3); + c1.agregarSubComentario(5, new DtComentario(1, null,new Date(2019-1900,7,15), "1.4.5.9", 2), u3); ArrayList l = c1.listarSubComentarios(); for(int i=0;i<l.size();i++){ System.out.println(l.get(i).toString()); - }*/ - ArrayList<Integer> l = new ArrayList(); - l.add(2); - l.add(8); - l.add(15); - l.add(22); - l.add(7); - for(int i=0;i<l.size();i++){ - System.out.println(l.get(i)); } } }