Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ivagonz-practica4
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ivagonz
ivagonz-practica4
Commits
572d9bad
There was a problem fetching the pipeline summary.
Commit
572d9bad
authored
Jan 11, 2018
by
Ivan Gonzalez
Browse files
Options
Downloads
Patches
Plain Diff
Corregidos code smells
parent
f1657ed0
No related branches found
No related tags found
1 merge request
!3
Develop
Pipeline
#
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/inf/uva/es/ivagonz/practica4/ColaDeAmigos.java
+16
-13
16 additions, 13 deletions
src/main/java/inf/uva/es/ivagonz/practica4/ColaDeAmigos.java
src/main/java/inf/uva/es/ivagonz/practica4/Persona.java
+7
-6
7 additions, 6 deletions
src/main/java/inf/uva/es/ivagonz/practica4/Persona.java
with
23 additions
and
19 deletions
src/main/java/inf/uva/es/ivagonz/practica4/ColaDeAmigos.java
+
16
−
13
View file @
572d9bad
package
inf.uva.es.ivagonz.practica4
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* Implementación de una Cola de amigos para la última práctica de la asignatura
...
...
@@ -11,7 +12,9 @@ import java.util.ArrayList;
*/
public
class
ColaDeAmigos
{
private
ArrayList
<
Persona
>
cola
;
private
List
<
Persona
>
cola
;
private
final
String
ID_PERSONA
=
"El id de la Persona a buscar debe ser positivo."
;
private
final
String
ID_ASOCIADO
=
"El id pasado debe estar asociado a una Persona de la cola."
;
/**
* Constructor que recibe una lista, que simboliza las personas que hay al
...
...
@@ -24,7 +27,7 @@ public class ColaDeAmigos {
* si se incumple alguna de las condiciones impuestas al
* parámetro.
*/
public
ColaDeAmigos
(
Array
List
<
Persona
>
cola
)
{
public
ColaDeAmigos
(
List
<
Persona
>
cola
)
{
if
(
cola
==
null
)
throw
new
IllegalArgumentException
(
"La lista no puede ser nula."
);
if
(
hasElementoNull
(
cola
))
...
...
@@ -41,7 +44,7 @@ public class ColaDeAmigos {
* @return true si la lista tiene algún elemento nulo, false en caso
* contrario.
*/
public
boolean
hasElementoNull
(
Array
List
<
Persona
>
lista
)
{
public
boolean
hasElementoNull
(
List
<
Persona
>
lista
)
{
for
(
int
i
=
0
;
i
<
lista
.
size
();
i
++)
{
if
(
lista
.
get
(
i
)
==
null
)
return
true
;
...
...
@@ -53,7 +56,7 @@ public class ColaDeAmigos {
*
* @return lista que simboliza la cola de la cola de amigos.
*/
public
Array
List
<
Persona
>
getCola
()
{
public
List
<
Persona
>
getCola
()
{
return
cola
;
}
...
...
@@ -73,9 +76,9 @@ public class ColaDeAmigos {
*/
public
int
reservasParaAmigos
(
int
id
)
{
if
(
id
<
0
)
throw
new
IllegalArgumentException
(
"El id de la Persona a buscar debe ser positivo."
);
throw
new
IllegalArgumentException
(
ID_PERSONA
);
if
(!
containsPersona
(
id
))
throw
new
IllegalArgumentException
(
"El id pasado debe estar asociado a una Persona de la cola."
);
throw
new
IllegalArgumentException
(
ID_ASOCIADO
);
return
buscarPersona
(
id
).
getMaxAmigos
();
}
...
...
@@ -113,7 +116,7 @@ public class ColaDeAmigos {
*/
public
Persona
buscarPersona
(
int
id
)
{
if
(
id
<
0
)
throw
new
IllegalArgumentException
(
"El id de la Persona a buscar debe ser positivo."
);
throw
new
IllegalArgumentException
(
ID_PERSONA
);
for
(
int
i
=
0
;
i
<
getCola
().
size
();
i
++)
{
if
(
getCola
().
get
(
i
).
getId
()
==
id
)
return
getCola
().
get
(
i
);
...
...
@@ -137,9 +140,9 @@ public class ColaDeAmigos {
*/
public
int
amigosPorColar
(
int
id
)
{
if
(
id
<
0
)
throw
new
IllegalArgumentException
(
"El id de la Persona a buscar debe ser positivo."
);
throw
new
IllegalArgumentException
(
ID_PERSONA
);
if
(!
containsPersona
(
id
))
throw
new
IllegalArgumentException
(
"El id pasado debe estar asociado a una Persona de la cola."
);
throw
new
IllegalArgumentException
(
ID_ASOCIADO
);
return
buscarPersona
(
id
).
getAmigosPorColar
();
}
...
...
@@ -159,15 +162,15 @@ public class ColaDeAmigos {
* si se incumple alguna de las condiciones impuestas al
* parámetro.
*/
public
Array
List
<
Persona
>
amigosPorDelante
(
int
id
)
{
public
List
<
Persona
>
amigosPorDelante
(
int
id
)
{
if
(
id
<
0
)
throw
new
IllegalArgumentException
(
"El id de la Persona a buscar debe ser positivo."
);
throw
new
IllegalArgumentException
(
ID_PERSONA
);
if
(!
containsPersona
(
id
))
throw
new
IllegalArgumentException
(
"El id pasado debe estar asociado a una Persona de la cola."
);
throw
new
IllegalArgumentException
(
ID_ASOCIADO
);
Persona
p
=
buscarPersona
(
id
);
int
indicePersona
=
getCola
().
indexOf
(
p
);
int
indiceAmigos
=
indicePersona
-
(
p
.
getMaxAmigos
()
-
p
.
getAmigosPorColar
());
Array
List
<
Persona
>
amigosEnCola
=
new
ArrayList
<
Persona
>();
List
<
Persona
>
amigosEnCola
=
new
ArrayList
<>();
for
(
int
i
=
indiceAmigos
;
i
<
indicePersona
;
i
++)
{
amigosEnCola
.
add
(
getCola
().
get
(
i
));
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/inf/uva/es/ivagonz/practica4/Persona.java
+
7
−
6
View file @
572d9bad
package
inf.uva.es.ivagonz.practica4
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* Implementación de una Persona para poder llevar a cabo la funcionalidad de
...
...
@@ -13,8 +14,8 @@ public class Persona {
private
String
nombre
;
private
int
id
;
private
Array
List
<
Persona
>
amigos
;
private
Array
List
<
Persona
>
conocidos
;
private
List
<
Persona
>
amigos
;
private
List
<
Persona
>
conocidos
;
private
int
maxAmigos
;
private
int
amigosPorColar
;
...
...
@@ -39,7 +40,7 @@ public class Persona {
* si se incumple alguna de las condiciones impuestas a los
* parámetros.
*/
public
Persona
(
String
nombre
,
int
id
,
Array
List
<
Persona
>
amigos
,
Array
List
<
Persona
>
conocidos
)
{
public
Persona
(
String
nombre
,
int
id
,
List
<
Persona
>
amigos
,
List
<
Persona
>
conocidos
)
{
if
(
nombre
==
null
)
throw
new
IllegalArgumentException
(
"El nombre no puede ser null."
);
if
(
nombre
.
equals
(
""
))
...
...
@@ -70,7 +71,7 @@ public class Persona {
* correcto: no nulo.
* @return true si hay algún elemento nulo, false en caso contrario.
*/
public
boolean
hasElementoNull
(
Array
List
<
Persona
>
lista
)
{
public
boolean
hasElementoNull
(
List
<
Persona
>
lista
)
{
if
(
lista
==
null
)
throw
new
IllegalArgumentException
(
"La lista no puede ser nula."
);
for
(
int
i
=
0
;
i
<
lista
.
size
();
i
++)
{
...
...
@@ -238,7 +239,7 @@ public class Persona {
/**
* @return lista de amigos de this.
*/
public
Array
List
<
Persona
>
getAmigos
()
{
public
List
<
Persona
>
getAmigos
()
{
return
amigos
;
}
...
...
@@ -246,7 +247,7 @@ public class Persona {
*
* @return lista de conocidos de this.
*/
public
Array
List
<
Persona
>
getConocidos
()
{
public
List
<
Persona
>
getConocidos
()
{
return
conocidos
;
}
...
...
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