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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
javcalv
Entrega_javcalv_victorm
Commits
56c013cc
Commit
56c013cc
authored
10 months ago
by
Javier Calvo
Browse files
Options
Downloads
Patches
Plain Diff
Muelle modificado para añadir todos los contenedores
parent
699c9046
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/es/markse/Muelle.java
+105
-21
105 additions, 21 deletions
src/es/markse/Muelle.java
with
105 additions
and
21 deletions
src/es/markse/Muelle.java
+
105
−
21
View file @
56c013cc
...
@@ -49,12 +49,16 @@ public class Muelle {
...
@@ -49,12 +49,16 @@ public class Muelle {
}
}
/**
/**
* 1.1.8 Metodo que devuelve si una plaza esta llena o no
* 1.1.8 Metodo que devuelve si una plaza esta llena o no.
* - Si la cantidad de contenedores es la maxima
* - Si el ultimo contenedor no tiene techo
* - O si el contenedor es un FlatRack
* @return true si la plaza esta llena o si no lo esta
* @return true si la plaza esta llena o si no lo esta
*/
*/
public
boolean
plazaLlena
()
{
public
boolean
plazaLlena
()
{
return
(
this
.
contenedores
.
size
()
==
this
.
altura
return
(
this
.
contenedores
.
size
()
==
this
.
altura
()
||
(!
this
.
contenedores
.
isEmpty
()
&&
!
this
.
ultimoContenedor
().
tieneTecho
()))
?
true
:
false
;
||
(!
this
.
contenedores
.
isEmpty
()
&&
!
this
.
ultimoContenedor
().
tieneTecho
())
||
this
.
contenedores
.
get
(
0
)
instanceof
FlatRack
)
?
true
:
false
;
}
}
/**
/**
...
@@ -85,18 +89,24 @@ public class Muelle {
...
@@ -85,18 +89,24 @@ public class Muelle {
if
(
contenedor
==
null
)
if
(
contenedor
==
null
)
throw
new
IllegalArgumentException
(
"El contenedor no puede ser nulo"
);
throw
new
IllegalArgumentException
(
"El contenedor no puede ser nulo"
);
//Si el contenedor esta en transito
if
(
contenedor
.
contenedorEnTransito
())
if
(
contenedor
.
contenedorEnTransito
())
throw
new
IllegalStateException
(
"El Contenedor esta en transito, no se puede colocar"
);
throw
new
IllegalStateException
(
"El Contenedor esta en transito, no se puede colocar"
);
if
(
this
.
contenedores
.
size
()
==
this
.
altura
)
//Si la plaza esta llena
if
(
this
.
plazaLlena
())
throw
new
IllegalStateException
(
"La plaza está llena"
);
throw
new
IllegalStateException
(
"La plaza está llena"
);
if
(!
this
.
contenedores
.
isEmpty
()
&&
!
this
.
contenedores
.
get
(
this
.
contenedores
.
size
()-
1
).
tieneTecho
())
//Comprobamos si estan vacias o no para un tipo de contenedores
throw
new
IllegalStateException
(
"El ultimo contenedor no tiene techo"
);
if
((
contenedor
instanceof
FlatRack
||
contenedor
instanceof
Refrigerado
)
&&
this
.
plazaVacia
())
{
this
.
contenedores
.
add
(
contenedor
);
}
if
(
this
.
contenedores
.
isEmpty
()
||
(
this
.
ultimoContenedor
().
tieneTecho
()
&&
this
.
contenedores
.
size
()
<
this
.
altura
))
{
else
{
this
.
contenedores
.
add
(
contenedor
);
this
.
contenedores
.
add
(
contenedor
);
}
}
}
}
/**
/**
...
@@ -300,8 +310,8 @@ public class Muelle {
...
@@ -300,8 +310,8 @@ public class Muelle {
* @throws IllegalStateException si el muelle no esta operativo
* @throws IllegalStateException si el muelle no esta operativo
* @throws IllegalStateException si ese contenedor ya esta apilado
* @throws IllegalStateException si ese contenedor ya esta apilado
* @throws IllegalStateException si ese contenedor esta en transito,
* @throws IllegalStateException si ese contenedor esta en transito,
* @throws IllegalStateException si el contenedor donde se coloca encima no tiene techo
* @throws IllegalStateException si la plaza esta llena
* @throws IllegalStateException si la plaza esta llena
* @throws IllegalStateException si la plaza no esta vacia y queremos colocar un contenedor Regrigerado
*/
*/
public
void
colocarContenedorEnPlaza
(
Contenedor
contenedor
,
int
plaza
)
{
public
void
colocarContenedorEnPlaza
(
Contenedor
contenedor
,
int
plaza
)
{
//Comprobamos si el contenedor es nulo o la plaza no pertenece al rango
//Comprobamos si el contenedor es nulo o la plaza no pertenece al rango
...
@@ -326,15 +336,71 @@ public class Muelle {
...
@@ -326,15 +336,71 @@ public class Muelle {
//Verificar si la plaza esta llena
//Verificar si la plaza esta llena
Plaza
p
=
this
.
plazas
[
plaza
];
Plaza
p
=
this
.
plazas
[
plaza
];
if
(
p
.
contenedores
.
size
()
==
p
.
altura
())
if
(
p
.
plazaLlena
())
throw
new
IllegalStateException
(
"La plaza está llena"
);
throw
new
IllegalStateException
(
"La plaza está llena."
);
//Contenedor FlatRack
if
(
contenedor
instanceof
FlatRack
)
{
this
.
colocarContenedorFlatRack
(
contenedor
,
plaza
);
}
//Contenedor Refrigerado
else
if
(
contenedor
instanceof
Refrigerado
)
{
//Comprobamos si la plaza esta vacia
if
(!
this
.
plazas
[
plaza
].
plazaVacia
())
throw
new
IllegalStateException
(
"La plaza no esta vacía. No podemos colocar el contenedor Refrigerado en el suelo"
);
else
{
this
.
plazas
[
plaza
].
colocarContenedor
(
contenedor
);
}
}
//Verificamos si el ultimo contenedor tiene techo
//Contenedor Estandar
if
(
p
.
contenedores
.
size
()
>
0
&&
!
p
.
ultimoContenedor
().
tieneTecho
())
throw
new
IllegalStateException
(
"El contenedor no tiene techo"
);
else
{
else
{
this
.
plazas
[
plaza
].
colocarContenedor
(
contenedor
);
this
.
plazas
[
plaza
].
colocarContenedor
(
contenedor
);
}
}
}
/**
* Metodo para colocar un contenedor de tipo FlatRack
* @param contenedor Contenedor a colocar
* @param plaza numero de plaza a colocar
* @throws IllegalStateException Si el numero de plazas totales de este muelle es demasiado pequeño
* @throws IllegalStateException Si la plaza no esta vacia, no podemos colocar el FlatRack.
* @throws IllegalStateException Si las plazas de la izquierda y derecha estan ocupadas
*/
private
void
colocarContenedorFlatRack
(
Contenedor
contenedor
,
int
plaza
)
{
if
(
this
.
plazas
.
length
<
2
)
throw
new
IllegalStateException
(
"El numero de plazas totales de este muelle es demasiado pequeño"
);
if
(!
this
.
plazas
[
plaza
].
plazaVacia
())
throw
new
IllegalStateException
(
"La plaza no esta vacia, no podemos colocar el FlatRack"
);
boolean
sePuedeColocar
=
false
;
//Comprobamos la plaza de la izquierda
if
((
plaza
-
1
)
>=
0
)
{
//Si la plaza de la izquierda esta vacia, se coloca el contenedor
if
(
this
.
plazas
[
plaza
-
1
].
plazaVacia
())
{
sePuedeColocar
=
true
;
this
.
plazas
[
plaza
].
colocarContenedor
(
contenedor
);
this
.
plazas
[
plaza
-
1
].
colocarContenedor
(
contenedor
);
}
}
//La plaza de la derecha
if
((
plaza
+
1
)
<=
this
.
plazas
.
length
&&
!
sePuedeColocar
)
{
if
(
this
.
plazas
[
plaza
+
1
].
plazaVacia
())
{
sePuedeColocar
=
true
;
this
.
plazas
[
plaza
].
colocarContenedor
(
contenedor
);
this
.
plazas
[
plaza
+
1
].
colocarContenedor
(
contenedor
);
}
}
//Si no se ha colocado (izquierda y derecha ocupadas)
if
(!
sePuedeColocar
)
{
throw
new
IllegalStateException
(
"Las plazas de la izquierda y derecha estan ocupadas"
);
}
}
}
/**
/**
...
@@ -351,6 +417,7 @@ public class Muelle {
...
@@ -351,6 +417,7 @@ public class Muelle {
throw
new
IllegalArgumentException
(
"El Contenedor no puede ser nulo"
);
throw
new
IllegalArgumentException
(
"El Contenedor no puede ser nulo"
);
if
(
contenedor
.
contenedorEnTransito
())
if
(
contenedor
.
contenedorEnTransito
())
throw
new
IllegalStateException
(
"El Contenedor se encuentra en transito"
);
throw
new
IllegalStateException
(
"El Contenedor se encuentra en transito"
);
//Comprobar si se encuentra en funcionamiento
//Comprobar si se encuentra en funcionamiento
if
(!
this
.
estaOperativo
())
if
(!
this
.
estaOperativo
())
throw
new
IllegalStateException
(
"El muelle se encuentra fuera de servicio"
);
throw
new
IllegalStateException
(
"El muelle se encuentra fuera de servicio"
);
...
@@ -359,11 +426,28 @@ public class Muelle {
...
@@ -359,11 +426,28 @@ public class Muelle {
//Buscamos que el contenedor este en el muelle
//Buscamos que el contenedor este en el muelle
if
(
plazaActual
(
c
)
==
-
1
)
if
(
plazaActual
(
c
)
==
-
1
)
throw
new
IllegalStateException
(
"El contenedor no se encuentra apilado en este muelle"
);
throw
new
IllegalStateException
(
"El contenedor no se encuentra apilado en este muelle"
);
//Buscamos el contenedor y desapilamos el contenedor si se encuentra en el ultimo nivel
//Buscamos el contenedor y desapilamos el contenedor si se encuentra en el ultimo nivel
for
(
Plaza
plaza
:
this
.
plazas
)
{
for
(
int
i
=
0
;
i
<
this
.
plazas
.
length
;
i
++)
{
if
(
plaza
.
contieneContenedor
(
c
))
{
if
(
this
.
plazas
[
i
].
contieneContenedor
(
c
))
{
if
(
plaza
.
estaEnUltimoNivel
(
c
))
if
(
this
.
plazas
[
i
].
estaEnUltimoNivel
(
c
))
plaza
.
desapilarContenedor
();
//Desapilamos el contenedor
this
.
plazas
[
i
].
desapilarContenedor
();
//Comparamos si es un FlatRack (Desapilarlo por completo)
if
(
contenedor
instanceof
FlatRack
)
{
boolean
desapilado
=
false
;
if
(
i
-
1
>=
0
)
{
if
(
this
.
plazas
[
i
].
ultimoContenedor
().
getCodigo
().
equals
(
this
.
plazas
[
i
-
1
].
ultimoContenedor
().
getCodigo
()))
{
this
.
plazas
[
i
-
1
].
desapilarContenedor
();
desapilado
=
true
;
}
}
if
(!
desapilado
)
{
this
.
plazas
[
i
+
1
].
desapilarContenedor
();
}
}
else
else
throw
new
IllegalStateException
(
"El Contenedor no esta en el ultimo nivel, no se puede desapilar"
);
throw
new
IllegalStateException
(
"El Contenedor no esta en el ultimo nivel, no se puede desapilar"
);
}
}
...
...
...
...
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
sign in
to comment