Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Antonio Rueda
/
reserva-hoteles
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
61614bfc
authored
Oct 03, 2024
by
Antonio Rueda
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Eliminado el mapa de reservas en Hotel al no admitir fechas repetidas
como clave
parent
1c4ecca3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
24 deletions
src/main/java/es/ujaen/dae/reservahoteles/entidades/Hotel.java
src/main/java/es/ujaen/dae/reservahoteles/entidades/Hotel.java
View file @
61614bfc
...
...
@@ -9,9 +9,8 @@ import jakarta.validation.constraints.Positive;
import
jakarta.validation.constraints.PositiveOrZero
;
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.SortedMap
;
import
java.util.TreeMap
;
/**
*
...
...
@@ -43,7 +42,7 @@ public class Hotel {
@PositiveOrZero
int
precioHabDoble
;
SortedMap
<
LocalDate
,
Reserva
>
reservas
;
List
<
Reserva
>
reservas
;
public
Hotel
(
int
id
,
String
nombre
,
String
localidad
,
String
provincia
,
String
cp
,
int
numHabSimple
,
int
numHabDoble
,
int
precioHabSimple
,
int
precioHabDoble
)
{
this
.
id
=
id
;
...
...
@@ -56,7 +55,7 @@ public class Hotel {
this
.
precioHabSimple
=
precioHabSimple
;
this
.
precioHabDoble
=
precioHabDoble
;
reservas
=
new
TreeMap
<>();
reservas
=
new
LinkedList
<>();
}
/**
...
...
@@ -69,8 +68,8 @@ public class Hotel {
if
(!
disponible
(
reserva
.
fechaInicio
(),
reserva
.
fechaFin
(),
reserva
.
numHabSimple
(),
reserva
.
numHabDoble
()))
throw
new
NoDisponibilidadReserva
();
reservas
.
put
(
reserva
.
fechaInicio
(),
reserva
);
reservas
.
add
(
reserva
);
}
/**
...
...
@@ -100,10 +99,7 @@ public class Hotel {
int
numHabSimpleDisponibles
=
numHabSimple
;
int
numHabDobleDisponibles
=
numHabDoble
;
for
(
var
reserva:
reservas
.
values
())
{
if
(
reserva
.
fechaInicio
().
isAfter
(
fecha
))
break
;
for
(
var
reserva:
reservas
)
{
if
(
fechaEnIntervalo
(
fecha
,
reserva
.
fechaInicio
(),
reserva
.
fechaFin
()))
{
numHabSimpleDisponibles
-=
reserva
.
numHabSimple
();
numHabDobleDisponibles
-=
reserva
.
numHabDoble
();
...
...
@@ -120,20 +116,8 @@ public class Hotel {
* @return la lista de reservas
*/
public
List
<
Reserva
>
reservasEntre
(
LocalDate
fechaInicio
,
LocalDate
fechaFin
)
{
var
resultados
=
new
ArrayList
<
Reserva
>();
for
(
var
reserva:
reservas
.
values
())
{
if
(
reserva
.
fechaInicio
().
isBefore
(
fechaFin
))
{
if
(
reserva
.
fechaFin
().
isAfter
(
fechaInicio
))
resultados
.
add
(
reserva
);
}
else
// Las reservas están ordenadas por fecha de inicio
// así que no puede haber más
break
;
}
return
resultados
;
return
reservas
.
stream
().
filter
(
r
->
r
.
fechaInicio
().
isBefore
(
fechaFin
)
&&
r
.
fechaFin
().
isAfter
(
fechaInicio
)).
toList
();
}
public
int
id
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment