Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
UyTube_obligatorio_PdA
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Juan José Álvarez Pérez
UyTube_obligatorio_PdA
Commits
300ed430
Commit
300ed430
authored
5 years ago
by
JotaJota96
Browse files
Options
Downloads
Patches
Plain Diff
Clase Video testeada
parent
9625927e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
UyTube_aplicacion/src/Logica/Clases/Video.java
+89
-17
89 additions, 17 deletions
UyTube_aplicacion/src/Logica/Clases/Video.java
UyTube_aplicacion/src/Logica/main.java
+50
-0
50 additions, 0 deletions
UyTube_aplicacion/src/Logica/main.java
with
139 additions
and
17 deletions
UyTube_aplicacion/src/Logica/Clases/Video.java
+
89
−
17
View file @
300ed430
...
...
@@ -5,12 +5,12 @@ import Logica.DataType.DtVideo;
import
java.sql.Time
;
import
java.sql.Date
;
import
Logica.Enumerados.Privacidad
;
import
Logica.Enumerados.TipoValoracion
;
import
java.util.ArrayList
;
import
java.util.Map
;
import
java.util.TreeMap
;
public
class
Video
{
public
class
Video
{
private
int
id
;
private
String
nombre
;
private
String
descripcion
;
...
...
@@ -26,10 +26,16 @@ public class Video {
private
static
int
idActual
=
1
;
public
Video
(){
}
/********************** Constructor *********************/
public
Video
(
int
_id
,
String
_nombre
,
String
_descripcion
,
Time
_duracion
,
Date
_fechaPublicacion
,
String
_urlVideoOriginal
,
String
_categoria
){
if
(
_id
<
0
){
throw
new
RuntimeException
(
"Error, el id del video es un negativo o cero."
);
}
if
(
_nombre
==
""
){
throw
new
RuntimeException
(
"Error, el nombre del video está vacío"
);}
if
(
_duracion
==
null
){
throw
new
RuntimeException
(
"Error, la duración del video es null."
);}
if
(
_fechaPublicacion
==
null
){
throw
new
RuntimeException
(
"Error, la fecha de publicación del video es null."
);}
if
(
_urlVideoOriginal
==
""
){
throw
new
RuntimeException
(
"Error, la url del video está vacía."
);}
if
(
_categoria
==
""
){
throw
new
RuntimeException
(
"Error, la descripción del video está vacía."
);}
this
.
id
=
_id
;
this
.
nombre
=
_nombre
;
this
.
descripcion
=
_descripcion
;
...
...
@@ -43,6 +49,13 @@ public class Video {
/** Agregar un nuevo comentario **/
public
void
agregarComentario
(
DtComentario
dtComentario
,
Usuario
usuario
){
if
(
dtComentario
==
null
){
throw
new
RuntimeException
(
"El DataType es null"
);
}
if
(
usuario
==
null
){
throw
new
RuntimeException
(
"El usuario es null"
);
}
int
nuevoId
=
Comentario
.
getNuevoID
();
Comentario
nuevoComentario
=
new
Comentario
(
nuevoId
,
dtComentario
.
getFecha
(),
dtComentario
.
getTexto
(),
0
,
usuario
);
comentarios
.
put
(
nuevoId
,
nuevoComentario
);
...
...
@@ -50,6 +63,13 @@ public class Video {
/* Agregar un subcomentario a un comentario existente */
public
void
agregarComentario
(
int
idCom
,
DtComentario
dtComentario
,
Usuario
usuario
){
if
(
dtComentario
==
null
){
throw
new
RuntimeException
(
"El DataType es null"
);
}
if
(
usuario
==
null
){
throw
new
RuntimeException
(
"El usuario es null"
);
}
for
(
Map
.
Entry
<
Integer
,
Comentario
>
coment
:
comentarios
.
entrySet
())
{
if
(
coment
.
getValue
().
agregarSubComentario
(
idCom
,
dtComentario
,
usuario
)){
break
;
...
...
@@ -58,24 +78,58 @@ public class Video {
}
/* Agrega o midifica una valoración */
public
void
agregarModificarValoracion
(
DtValoracion
dtValoracion
,
Usuario
usuario
){
public
void
agregarModificarValoracion
(
DtValoracion
dtValoracion
,
Usuario
usuario
)
{
if
(
dtValoracion
==
null
)
{
throw
new
RuntimeException
(
"El DataType es null"
);
}
if
(
usuario
==
null
){
throw
new
RuntimeException
(
"El usuario es null"
);
}
String
nickname
=
usuario
.
getNickname
();
for
(
Valoracion
val:
valoraciones
){
if
(
val
.
modificar
(
dtValoracion
,
nickname
)){
break
;
// por las dudas, para que los contadores de likes no queden inconsistentes:
// obtengo la valoracion que le habia dado antes el usuario (si es que lo habia alorado)
DtValoracion
dtv
=
this
.
obtenerValoracion
(
nickname
);
// si el usuario ya lo valoro
if
(
dtv
!=
null
)
{
// segun cual fuera la valoracion anterior, resta 1 al contador
if
(
dtv
.
getVal
()
==
TipoValoracion
.
LIKE
)
{
cantLikes
--;
}
else
{
cantDisLikes
--;
}
for
(
Valoracion
val
:
valoraciones
)
{
if
(
val
.
modificar
(
dtValoracion
,
nickname
))
{
break
;
}
}
}
else
{
Valoracion
nuevaValoracion
=
new
Valoracion
(
dtValoracion
.
getVal
(),
usuario
);
valoraciones
.
add
(
nuevaValoracion
);
}
// segun cual sea la nueva valoracion, suma 1 al contador
if
(
dtValoracion
.
getVal
()
==
TipoValoracion
.
LIKE
)
{
cantLikes
++;
}
else
{
cantDisLikes
++;
}
}
public
DtVideo
getDt
(){
return
new
DtVideo
(
this
.
id
,
this
.
nombre
,
this
.
descripcion
,
this
.
duracion
,
this
.
fechaPublicacion
,
this
.
urlVideoOriginal
,
this
.
privacidad
,
this
.
categoria
,
this
.
cantLikes
,
this
.
cantDisLikes
);
}
public
ArrayList
<
DtComentario
>
listarComentarios
(){
ArrayList
<
DtComentario
>
listaComent
=
new
ArrayList
<
DtComentario
>();
for
(
Map
.
Entry
<
Integer
,
Comentario
>
coment
:
comentarios
.
entrySet
())
{
DtComentario
dtComent
=
new
DtComentario
(
coment
.
getValue
().
getId
(),
coment
.
getValue
().
getUsr
().
getNickname
(),
coment
.
getValue
().
getFecha
(),
coment
.
getValue
().
getTexto
(),
coment
.
getValue
().
getNivelSubComentario
());
listaComent
.
add
(
dtComent
);
ArrayList
<
DtComentario
>
listaComent
=
new
ArrayList
<
DtComentario
>();
// recorro los comentarios sobre el video
for
(
Map
.
Entry
<
Integer
,
Comentario
>
coment
:
comentarios
.
entrySet
())
{
// le obtengo el DT y lo agrego a la lista resultado
listaComent
.
add
(
coment
.
getValue
().
getDT
());
// agrego a la lista resultado, la lista de sub comentarios
listaComent
.
addAll
(
coment
.
getValue
().
listarSubComentarios
());
}
return
listaComent
;
}
...
...
@@ -100,8 +154,8 @@ public class Video {
throw
new
RuntimeException
(
"El nombre no puede ser vacío"
);
}
if
(
dtVideo
.
getD
escrip
cion
()
==
""
)
{
throw
new
RuntimeException
(
"La d
escrip
cion no puede ser vacía"
);
if
(
dtVideo
.
getD
ura
cion
()==
null
)
{
throw
new
RuntimeException
(
"La d
ura
cion no puede ser vacía"
);
}
if
(
dtVideo
.
getFechaPublicacion
()
==
null
)
{
...
...
@@ -122,13 +176,16 @@ public class Video {
}
/* Obtiene la valoracion que hizo un usuario */
public
DtValoracion
obtenerValoracion
(
String
nickname
){
public
DtValoracion
obtenerValoracion
(
String
nickname
)
{
if
(
nickname
.
equals
(
""
))
{
throw
new
RuntimeException
(
"El nickname no puede ser vacio"
);
}
for
(
int
i
=
0
;
i
<
this
.
valoraciones
.
size
();
i
++){
if
(
valoraciones
.
get
(
i
).
getNicknameDeUsuario
()
==
nickname
){
return
valoraciones
.
get
(
i
).
getDT
();
}
}
return
n
ew
DtValoracion
()
;
return
n
ull
;
}
public
void
quitarValoracion
(
String
nickname
){
...
...
@@ -137,11 +194,26 @@ public class Video {
}
// Recorrer todas las valoraciones hasta encontrar la valoracion cuyo usuario sea el que tiene ese nickname
// cuando la encuentre, la saca de la coleccion
for
(
int
i
=
0
;
i
<
this
.
valoraciones
.
size
();
i
++){
if
(
valoraciones
.
get
(
i
).
getNicknameDeUsuario
().
equals
(
nickname
)
){
// segun cual fuera la valoracion anterior, resta 1 al contador
if
(
valoraciones
.
get
(
i
).
getVal
()
==
TipoValoracion
.
LIKE
)
{
cantLikes
--;
}
else
{
cantDisLikes
--;
}
// remueve de la coleccion
valoraciones
.
remove
(
i
);
break
;
}
}
}
public
static
int
getNuevoId
(){
int
nuevoId
=
idActual
++;
int
nuevoId
=
idActual
++;
return
nuevoId
;
}
...
...
This diff is collapsed.
Click to expand it.
UyTube_aplicacion/src/Logica/main.java
+
50
−
0
View file @
300ed430
package
Logica
;
import
Logica.Clases.Usuario
;
import
Logica.Clases.Video
;
import
Logica.DataType.DtCanal
;
import
Logica.DataType.DtComentario
;
import
Logica.DataType.DtValoracion
;
import
Logica.Enumerados.Privacidad
;
import
Logica.Enumerados.TipoValoracion
;
import
java.sql.Date
;
import
java.sql.Time
;
import
java.util.ArrayList
;
public
class
main
{
public
static
void
main
(
String
[]
args
)
{
Video
v
=
new
Video
(
Video
.
getNuevoId
(),
"nombe"
,
""
,
new
Time
(
0
,
4
,
25
),
new
Date
(
2019
-
1900
,
1
,
1
),
"url"
,
"UNDEFINED"
);
Usuario
u1
=
new
Usuario
(
"nk1"
,
"nk1"
,
new
Date
(
2019
-
1900
,
1
,
1
),
""
,
"1234"
,
""
,
""
,
new
DtCanal
(
0
,
"can_1"
,
""
,
Privacidad
.
PRIVADO
));
Usuario
u2
=
new
Usuario
(
"nk2"
,
"nk2"
,
new
Date
(
2019
-
1900
,
1
,
1
),
""
,
"1234"
,
""
,
""
,
new
DtCanal
(
0
,
"can_2"
,
""
,
Privacidad
.
PRIVADO
));
Usuario
u3
=
new
Usuario
(
"nk3"
,
"nk3"
,
new
Date
(
2019
-
1900
,
1
,
1
),
""
,
"1234"
,
""
,
""
,
new
DtCanal
(
0
,
"can_3"
,
""
,
Privacidad
.
PRIVADO
));
v
.
agregarComentario
(
new
DtComentario
(
0
,
""
,
new
Date
(
2019
-
1900
,
1
,
1
),
"com_1"
,
0
),
u1
);
v
.
agregarComentario
(
new
DtComentario
(
0
,
""
,
new
Date
(
2019
-
1900
,
1
,
1
),
"com_2"
,
0
),
u2
);
v
.
agregarComentario
(
new
DtComentario
(
0
,
""
,
new
Date
(
2019
-
1900
,
1
,
1
),
"com_3"
,
0
),
u1
);
v
.
agregarComentario
(
new
DtComentario
(
0
,
""
,
new
Date
(
2019
-
1900
,
1
,
1
),
"com_4"
,
0
),
u2
);
v
.
agregarComentario
(
1
,
new
DtComentario
(
0
,
""
,
new
Date
(
2019
-
1900
,
1
,
1
),
"com_1.1"
,
0
),
u1
);
v
.
agregarComentario
(
1
,
new
DtComentario
(
0
,
""
,
new
Date
(
2019
-
1900
,
1
,
1
),
"com_1.2"
,
0
),
u2
);
v
.
agregarComentario
(
2
,
new
DtComentario
(
0
,
""
,
new
Date
(
2019
-
1900
,
1
,
1
),
"com_2.1"
,
0
),
u1
);
v
.
agregarComentario
(
4
,
new
DtComentario
(
0
,
""
,
new
Date
(
2019
-
1900
,
1
,
1
),
"com_4.1"
,
0
),
u2
);
v
.
agregarComentario
(
6
,
new
DtComentario
(
0
,
""
,
new
Date
(
2019
-
1900
,
1
,
1
),
"com_1.2.1"
,
0
),
u1
);
v
.
agregarComentario
(
9
,
new
DtComentario
(
0
,
""
,
new
Date
(
2019
-
1900
,
1
,
1
),
"com_1.2.1.1"
,
0
),
u2
);
/*
ArrayList<DtComentario> l = v.listarComentarios();
for (int i = 0; i < l.size(); i++){
System.out.println(l.get(i).toString());
}
*/
v
.
agregarModificarValoracion
(
new
DtValoracion
(
TipoValoracion
.
LIKE
,
"nk1"
),
u1
);
v
.
agregarModificarValoracion
(
new
DtValoracion
(
TipoValoracion
.
DISLIKE
,
"nk2"
),
u2
);
v
.
agregarModificarValoracion
(
new
DtValoracion
(
TipoValoracion
.
LIKE
,
"nk3"
),
u3
);
v
.
quitarValoracion
(
"nk3"
);
System
.
out
.
println
(
"Likes: "
+
v
.
getCantLikes
());
System
.
out
.
println
(
"DisLikes: "
+
v
.
getCantDisLikes
());
ArrayList
<
DtValoracion
>
l
=
v
.
listarValoraciones
();
for
(
int
i
=
0
;
i
<
l
.
size
();
i
++){
System
.
out
.
println
(
l
.
get
(
i
).
toString
());
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment