Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Entrega_javcalv_victorm
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
Package registry
Model registry
Operate
Environments
Terraform modules
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
javcalv
Entrega_javcalv_victorm
Commits
c2b08cc8
Commit
c2b08cc8
authored
5 months ago
by
Javier Calvo
Browse files
Options
Downloads
Patches
Plain Diff
Cambios en Puerto: Comprobaciones
parent
2b1e6356
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/es/markse/Puerto.java
+34
-17
34 additions, 17 deletions
src/es/markse/Puerto.java
with
34 additions
and
17 deletions
src/es/markse/Puerto.java
+
34
−
17
View file @
c2b08cc8
...
...
@@ -6,6 +6,7 @@ package es.markse;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.regex.Pattern
;
import
es.uva.inf.poo.maps.GPSCoordinate
;
...
...
@@ -16,34 +17,47 @@ import es.uva.inf.poo.maps.GPSCoordinate;
*
*/
public
class
Puerto
{
private
String
pais
;
private
String
ciudad
;
private
List
<
Muelle
>
muelles
=
new
ArrayList
<>();
private
final
String
pais
;
private
final
String
ciudad
;
private
final
List
<
Muelle
>
muelles
=
new
ArrayList
<>();
private
final
String
PAIS_REGUEX
=
"[A-Za-z]{2}"
;
private
final
String
CIUDAD_REGUEX
=
"[A-Za-z]{3}"
;
/**
* Constructor del objeto Puerto.
* @param pais Pais al que pertenece el puerto (2 letras)
* @param ciudad Ciudad al que pertenece el puerto (3 letras)
*/
public
Puerto
(
String
pais
,
String
ciudad
)
{
comprobarIdentificador
(
pais
,
ciudad
);
if
(
comprobarIdentificadoresNulos
(
pais
,
ciudad
))
throw
new
IllegalArgumentException
(
"El pais o la ciudad no pueden ser nulos"
);
if
(!
comprobarIdentifiadores
(
pais
.
toUpperCase
(),
ciudad
.
toUpperCase
()))
throw
new
IllegalArgumentException
(
"El pais o la ciudad no tiene el formato incorrecto. 'XX' pais y 'XXX' ciudad."
);
this
.
pais
=
pais
.
toUpperCase
();
this
.
ciudad
=
ciudad
.
toUpperCase
();
}
/**
* Metodo que comprueba si tanto el pais como la ciudad son correctos (2 y 3 letras respectivamente)
* @param pais Pais del puerto (2 letras)
* @param ciudad Ciudad del puerto(3 letras)
* @throws IllegalArgumentException si el pais o la ciudad no corresponden con sus respectivos formatos o
* cuando son nulos
* Metodo que comprueba si la ciudad o el pais son nulos
* @param pais Pais del puerto a comprobar
* @param ciudad Ciudad del puerto a comprobar
* @return true si son nulos o false si no lo son
*/
private
void
comprobarIdentificador
(
String
pais
,
String
ciudad
)
{
if
(
pais
==
null
||
ciudad
==
null
)
{
throw
new
IllegalArgumentException
(
"El pais o la ciudad no pueden ser nulos"
);
}
if
(!(
pais
.
matches
(
"[A-Za-z]{2}"
)
&&
ciudad
.
matches
(
"[A-Za-z]{3}"
)))
{
throw
new
IllegalArgumentException
(
"Formato incorrecto. Debe ser en el formato 'XX-XXX', donde XX es el país y XXX es la ciudad, usando solo letras."
);
}
private
boolean
comprobarIdentificadoresNulos
(
String
pais
,
String
ciudad
)
{
return
(
pais
==
null
||
ciudad
==
null
)
?
true
:
false
;
}
/**
* Metodo que comprueba si el pais o la ciudad tienen el formato correcto mediante expresiones regulares.
* @param pais Pais del puerto a comprobar
* @param ciudad Ciudad del puerto a comprobar
* @return true si es el formto correcto o false si no lo es
*/
private
boolean
comprobarIdentifiadores
(
String
pais
,
String
ciudad
)
{
Pattern
paisPattern
=
Pattern
.
compile
(
this
.
PAIS_REGUEX
);
Pattern
ciudadPattern
=
Pattern
.
compile
(
this
.
CIUDAD_REGUEX
);
return
(
paisPattern
.
matcher
(
pais
).
matches
()
&&
ciudadPattern
.
matcher
(
ciudad
).
matches
())
?
true
:
false
;
}
/**
...
...
@@ -63,6 +77,7 @@ public class Puerto {
/**
* 1.1.2 Método que elimina un muelle del puerto.
* @param id : Identificador del muelle que se elimina
* @return true si se ha eliminado el muelle y false si no se ha eliminado ninguno (n)
*/
public
boolean
eliminarMuelle
(
String
id
)
{
if
(
id
==
null
)
throw
new
IllegalArgumentException
(
"Identificador no puede ser nulo"
);
...
...
@@ -78,6 +93,7 @@ public class Puerto {
public
boolean
comprobarMuelleEnPuerto
(
Muelle
m
)
{
String
id
=
m
.
getIdentificador
();
GPSCoordinate
cord
=
m
.
getGPSCoordinate
();
//Para daca muelle comprobamos si ya esta entro de este puerto
for
(
Muelle
muelle
:
this
.
muelles
)
{
if
(
id
.
equals
(
muelle
.
getIdentificador
())||
(
cord
.
getDistanceTo
(
muelle
.
getGPSCoordinate
())==
0
))
{
return
true
;
...
...
@@ -153,7 +169,8 @@ public class Puerto {
}
}
return
cercanos
.
toArray
(
new
Muelle
[
0
]);
}
}
/**
* Metodo que devuelve el pais del puerto
* @return pais del perto
...
...
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