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
ecc90d78
authored
Oct 01, 2024
by
Antonio Rueda
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Implementación de operaciones de disponibilidad de un hotel y de hoteles
disponibles en una localidad
parent
f285aa39
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
154 additions
and
38 deletions
reserva-hoteles-uml.drawio
src/main/java/es/ujaen/dae/reservahoteles/entidades/Hotel.java
src/main/java/es/ujaen/dae/reservahoteles/entidades/Reserva.java
src/main/java/es/ujaen/dae/reservahoteles/servicios/ServicioReservas.java
src/test/java/es/ujaen/dae/reservahoteles/servicios/TestServicioReservas.java
reserva-hoteles-uml.drawio
View file @
ecc90d78
<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0" version="24.7.16">
<diagram name="Página-1" id="IpY-njWp8TfkcAYWz6vd">
<mxGraphModel dx="
2687" dy="728
" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1654" pageHeight="2336" math="0" shadow="0">
<mxGraphModel dx="
3605" dy="1376
" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1654" pageHeight="2336" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="a_C5hD_1tt0fRA46Nat0-1" value="<div><span style="font-weight: normal;">&lt;&lt;entidad&gt;&gt;</span><br></div><div>Reserva</div>" style="swimlane;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=40;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="1
160" y="150
" width="160" height="156" as="geometry" />
<mxGeometry x="1
470" y="148
" width="160" height="156" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-2" value="<div>- <u>num</u>: int<br></div><div>- fechaInicio: Fecha</div><div>- fechaFin: Fecha</div><div>- numHabSimple: init</div><div>- numHabDoble: int<br></div>" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;whiteSpace=wrap;html=1;" parent="a_C5hD_1tt0fRA46Nat0-1" vertex="1">
<mxGeometry y="40" width="160" height="80" as="geometry" />
...
...
@@ -17,19 +17,19 @@
<mxGeometry y="130" width="160" height="26" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-5" value="<div><span style="font-weight: normal;">&lt;&lt;entidad&gt;&gt;<br></span></div><div>Hotel</div>" style="swimlane;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=40;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="8
50" y="96" width="160" height="226
" as="geometry" />
<mxGeometry x="8
27" y="114" width="530" height="240
" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-6" value="<div>- <u>id</u>: int<br></div><div>- nombre: string</div><div>- direccion: string</div><div>- localidad: string</div><div>- provincia: string</div><div>- cp:
int
</div><div>- numHabSimple: int</div><div>- numHabDoble: int</div><div>- precioHabSimple: int</div><div>- precioHabDoble: int<br></div>" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;whiteSpace=wrap;html=1;" parent="a_C5hD_1tt0fRA46Nat0-5" vertex="1">
<mxGeometry y="40" width="
16
0" height="150" as="geometry" />
<mxCell id="a_C5hD_1tt0fRA46Nat0-6" value="<div>- <u>id</u>: int<br></div><div>- nombre: string</div><div>- direccion: string</div><div>- localidad: string</div><div>- provincia: string</div><div>- cp:
string
</div><div>- numHabSimple: int</div><div>- numHabDoble: int</div><div>- precioHabSimple: int</div><div>- precioHabDoble: int<br></div>" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;whiteSpace=wrap;html=1;" parent="a_C5hD_1tt0fRA46Nat0-5" vertex="1">
<mxGeometry y="40" width="
53
0" height="150" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-7" value="" style="line;strokeWidth=1;fillColor=none;align=left;verticalAlign=middle;spacingTop=-1;spacingLeft=3;spacingRight=3;rotatable=0;labelPosition=right;points=[];portConstraint=eastwest;strokeColor=inherit;" parent="a_C5hD_1tt0fRA46Nat0-5" vertex="1">
<mxGeometry y="190" width="
16
0" height="10" as="geometry" />
<mxGeometry y="190" width="
53
0" height="10" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-8" value="
&nbsp
;" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;whiteSpace=wrap;html=1;" parent="a_C5hD_1tt0fRA46Nat0-5" vertex="1">
<mxGeometry y="200" width="
160" height="26
" as="geometry" />
<mxCell id="a_C5hD_1tt0fRA46Nat0-8" value="
+ disponible(fechaInicio: Fecha, fechaFin: Fecha, numHabSimple: int, numHabDoble: int): bool<div>+ disponible(f<span style="background-color: initial;">echa: Fecha, numHabSimple: int, numHabDoble: int): bool</span></div>
;" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;whiteSpace=wrap;html=1;" parent="a_C5hD_1tt0fRA46Nat0-5" vertex="1">
<mxGeometry y="200" width="
530" height="40
" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-9" value="<div><span style="font-weight: normal;">&lt;&lt;entidad&gt;&gt;</span><br></div><div>Cliente</div>" style="swimlane;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=42;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="850" y="
368
" width="160" height="162" as="geometry" />
<mxGeometry x="850" y="
400
" width="160" height="162" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-10" value="<div>- nombre: string</div><div>- direccion: string</div><div>- tlf: string</div><div>- <u>email</u>: string</div><div>- clave: string<br></div>" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;whiteSpace=wrap;html=1;" parent="a_C5hD_1tt0fRA46Nat0-9" vertex="1">
<mxGeometry y="42" width="160" height="84" as="geometry" />
...
...
@@ -44,25 +44,19 @@
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-16" value="*" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" parent="1" vertex="1">
<mxGeometry x="1
130" y="225
" width="30" height="30" as="geometry" />
<mxGeometry x="1
440" y="234
" width="30" height="30" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-17" value="reserva" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" parent="1" vertex="1">
<mxGeometry x="1
100" y="195
" width="60" height="30" as="geometry" />
<mxGeometry x="1
410" y="204
" width="60" height="30" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-21" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=1;entryDx=0;entryDy=0;endArrow=none;endFill=0;" parent="1" source="a_C5hD_1tt0fRA46Nat0-10" target="a_C5hD_1tt0fRA46Nat0-1" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-22" value="cliente" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" parent="1" vertex="1">
<mxGeometry x="1010" y="423.5" width="60" height="30" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-23" value="reserva" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" parent="1" vertex="1">
<mxGeometry x="1180" y="300" width="60" height="30" as="geometry" />
<mxGeometry x="1010" y="453.5" width="60" height="30" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-24" value="1" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" parent="1" vertex="1">
<mxGeometry x="1010" y="452.5" width="30" height="30" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-25" value="*" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" parent="1" vertex="1">
<mxGeometry x="1240" y="300" width="30" height="30" as="geometry" />
<mxGeometry x="1010" y="482.5" width="30" height="30" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-30" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=open;endFill=0;startArrow=diamond;startFill=1;" parent="1" source="a_C5hD_1tt0fRA46Nat0-26" target="a_C5hD_1tt0fRA46Nat0-6" edge="1">
<mxGeometry relative="1" as="geometry" />
...
...
@@ -71,7 +65,7 @@
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-26" value="<div><span style="font-weight: normal;">&lt;&lt;servicio&gt;&gt;</span></div><div><span style="font-weight: normal;">&lt;&lt;repositorio&gt;&gt;</span><br></div><div>ServicioReservas</div>" style="swimlane;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=62;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="-10" y="114" width="670" height="
196
" as="geometry" />
<mxGeometry x="-10" y="114" width="670" height="
230
" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-27" value="<div>&nbsp;</div>" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;whiteSpace=wrap;html=1;" parent="a_C5hD_1tt0fRA46Nat0-26" vertex="1">
<mxGeometry y="62" width="670" height="24" as="geometry" />
...
...
@@ -79,20 +73,20 @@
<mxCell id="a_C5hD_1tt0fRA46Nat0-28" value="" style="line;strokeWidth=1;fillColor=none;align=left;verticalAlign=middle;spacingTop=-1;spacingLeft=3;spacingRight=3;rotatable=0;labelPosition=right;points=[];portConstraint=eastwest;strokeColor=inherit;" parent="a_C5hD_1tt0fRA46Nat0-26" vertex="1">
<mxGeometry y="86" width="670" height="10" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-29" value="<div>+ nuevoHotel(h: Hotel)</div><div>+ nuevoCliente(c: Cliente)</div><div>+ login(email: string, clave: string): Cliente</div><div>+ buscar
PorLocalidad(localidad: string, fechaInicio: Fecha, fechaFin: Fecha, numHabSimple, int, numHabDoble: int): Hotel[]</div><div>+ buscarHotel(nombreParcial: string, localidad: string): Hotel[]
</div><div>+ reservar(c: Cliente, h: Hotel, fechaInicio: Fecha, fechaFin: Fecha, numHabSimple: int, numHabDoble: int): Reserva <br></div>" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;whiteSpace=wrap;html=1;" parent="a_C5hD_1tt0fRA46Nat0-26" vertex="1">
<mxGeometry y="96" width="670" height="1
00
" as="geometry" />
<mxCell id="a_C5hD_1tt0fRA46Nat0-29" value="<div>+ nuevoHotel(h: Hotel)</div><div>+ nuevoCliente(c: Cliente)</div><div>+ login(email: string, clave: string): Cliente</div><div>+ buscar
HotelesDisponiblesPorLocalidad(localidad: string, fechaInicio: Fecha, fechaFin: Fecha, numHabSimple, int, numHabDoble: int): Hotel[]</div><div>+ buscarHotel(nombreParcial: string, localidad: string): Hotel[]</div><div>+ disponible(h: Hotel, fechaInicio: Fecha, fechaFin: Fecha, numHabSimple: int, numHabDoble: int): bool<br>
</div><div>+ reservar(c: Cliente, h: Hotel, fechaInicio: Fecha, fechaFin: Fecha, numHabSimple: int, numHabDoble: int): Reserva <br></div>" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;whiteSpace=wrap;html=1;" parent="a_C5hD_1tt0fRA46Nat0-26" vertex="1">
<mxGeometry y="96" width="670" height="1
34
" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-32" value="hotel" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" parent="1" vertex="1">
<mxGeometry x="
802" y="178
" width="50" height="30" as="geometry" />
<mxGeometry x="
780" y="194
" width="50" height="30" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-33" value="*" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" parent="1" vertex="1">
<mxGeometry x="
812" y="210
" width="30" height="30" as="geometry" />
<mxGeometry x="
790" y="226
" width="30" height="30" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-34" value="*" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" parent="1" vertex="1">
<mxGeometry x="82
2" y="456
.5" width="30" height="30" as="geometry" />
<mxGeometry x="82
0" y="482
.5" width="30" height="30" as="geometry" />
</mxCell>
<mxCell id="a_C5hD_1tt0fRA46Nat0-35" value="cliente" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" parent="1" vertex="1">
<mxGeometry x="79
2" y="423
.5" width="60" height="30" as="geometry" />
<mxGeometry x="79
0" y="449
.5" width="60" height="30" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
...
...
src/main/java/es/ujaen/dae/reservahoteles/entidades/Hotel.java
View file @
ecc90d78
...
...
@@ -2,7 +2,7 @@
package
es
.
ujaen
.
dae
.
reservahoteles
.
entidades
;
import
java.time.LocalDate
;
import
java.util.Map
;
import
java.util.
Sorted
Map
;
import
java.util.TreeMap
;
/**
...
...
@@ -16,7 +16,7 @@ public class Hotel {
// Dirección
String
localidad
;
String
provincia
;
int
cp
;
String
cp
;
// Disponibilidad habitaciones
int
numHabSimple
;
...
...
@@ -26,9 +26,9 @@ public class Hotel {
int
precioHabSimple
;
int
precioHabDoble
;
Map
<
LocalDate
,
Reserva
>
reservas
;
Sorted
Map
<
LocalDate
,
Reserva
>
reservas
;
public
Hotel
(
int
id
,
String
nombre
,
String
localidad
,
String
provincia
,
int
cp
,
int
numHabSimple
,
int
numHabDoble
,
int
precioHabSimple
,
int
precioHabDoble
)
{
public
Hotel
(
int
id
,
String
nombre
,
String
localidad
,
String
provincia
,
String
cp
,
int
numHabSimple
,
int
numHabDoble
,
int
precioHabSimple
,
int
precioHabDoble
)
{
this
.
id
=
id
;
this
.
nombre
=
nombre
;
this
.
localidad
=
localidad
;
...
...
@@ -42,6 +42,46 @@ public class Hotel {
reservas
=
new
TreeMap
<>();
}
/**
* Comprueba si hay disponibilidad en las fechas indicadas
* @param fechaInicio fecha de inicio de la reserva
* @param fechaFin fecha de final de la reserva
* @param numHabSimple número de habitaciones simples solicitadas
* @param numHabDoble número de habitaciones dobles solicitadas
* @return true si hay disponibilidad, false en caso contrario
*/
public
boolean
disponible
(
LocalDate
fechaInicio
,
LocalDate
fechaFin
,
int
numHabSimple
,
int
numHabDoble
)
{
for
(
var
fecha
=
fechaInicio
.
plusDays
(
0
);
fecha
.
isBefore
(
fechaFin
);
fecha
=
fecha
.
plusDays
(
1
))
if
(!
disponible
(
fecha
,
numHabSimple
,
numHabDoble
))
return
false
;
return
true
;
}
/**
* Comprueba si hay disponibilidad en un día concreto
* @param fecha día a comprobar
* @param numHabSimple número de habitaciones simples solicitadas
* @param numHabDoble número de habitaciones dobles solicitadas
* @return true si hay disponibilidad, false en caso contrario
*/
public
boolean
disponible
(
LocalDate
fecha
,
int
numHabSimple
,
int
numHabDoble
)
{
int
numHabSimpleDisponibles
=
numHabSimple
;
int
numHabDobleDisponibles
=
numHabDoble
;
for
(
var
reserva:
reservas
.
values
())
{
if
(
reserva
.
fechaInicio
().
isAfter
(
fecha
))
break
;
if
(
fechaEnIntervalo
(
fecha
,
reserva
.
fechaInicio
(),
reserva
.
fechaFin
()))
{
numHabSimpleDisponibles
-=
reserva
.
numHabSimple
();
numHabDobleDisponibles
-=
reserva
.
numHabDoble
();
}
}
return
numHabSimpleDisponibles
>=
numHabSimple
&&
numHabDobleDisponibles
>=
numHabDoble
;
}
public
int
id
()
{
return
id
;
}
...
...
@@ -53,4 +93,20 @@ public class Hotel {
public
String
localidad
()
{
return
localidad
;
}
public
void
nombre
(
String
nombre
)
{
this
.
nombre
=
nombre
;
}
/**
* Operación auxiliar para comprobar si una fecha están dentro de un intervalo dado
* (incluyendo extremos)
* @param fecha la fecha a comprobar
* @param fechaInicio la fecha de inicio del intervalo
* @param fechaFin la fecha de fin del intervalo
* @return true si la fecha está en el intervalo dado, false en caso contrario
*/
private
static
boolean
fechaEnIntervalo
(
LocalDate
fecha
,
LocalDate
fechaInicio
,
LocalDate
fechaFin
)
{
return
fecha
.
isAfter
(
fechaInicio
.
minusDays
(
1
))
&&
fecha
.
isBefore
(
fechaFin
.
plusDays
(
1
));
}
}
src/main/java/es/ujaen/dae/reservahoteles/entidades/Reserva.java
View file @
ecc90d78
...
...
@@ -29,4 +29,20 @@ public class Reserva {
this
.
numHabSimple
=
numHabSimple
;
this
.
numHabDoble
=
numHabDoble
;
}
public
LocalDate
fechaInicio
()
{
return
fechaInicio
;
}
public
LocalDate
fechaFin
()
{
return
fechaFin
;
}
public
int
numHabSimple
()
{
return
numHabSimple
;
}
public
int
numHabDoble
()
{
return
numHabDoble
;
}
}
src/main/java/es/ujaen/dae/reservahoteles/servicios/ServicioReservas.java
View file @
ecc90d78
...
...
@@ -7,6 +7,7 @@ import es.ujaen.dae.reservahoteles.entidades.Reserva;
import
es.ujaen.dae.reservahoteles.excepciones.ClienteYaRegistrado
;
import
es.ujaen.dae.reservahoteles.util.UtilString
;
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
...
...
@@ -47,16 +48,29 @@ public class ServicioReservas {
return
(
cliente
!=
null
&&
cliente
.
clave
().
equals
(
clave
))
?
Optional
.
of
(
cliente
):
Optional
.
empty
();
}
public
List
<
Hotel
>
buscarPorLocalidad
(
String
localidad
,
/**
* Búsqueda de hoteles disponibles en una localidad
* @param localidad el nombre total o parcial de la localidad
* @param fechaInicio fecha de inicio de la estancia
* @param fechaFin fecha de final de la estancia
* @param numHabSimple número de habitaciones simples solicitadas
* @param numHabDoble número de habitaciones dobles solicitadas
* @return la lista de hoteles candidatos
*/
public
List
<
Hotel
>
buscarHotelesDisponiblesPorLocalidad
(
String
localidad
,
LocalDate
fechaInicio
,
LocalDate
fechaFin
,
int
numHabSimple
,
int
numHabDoble
)
{
var
localidadNorm
=
UtilString
.
normalizar
(
localidad
);
// Por implementar
throw
new
UnsupportedOperationException
();
return
hoteles
.
values
().
stream
().
filter
(
h
->
UtilString
.
normalizar
(
h
.
localidad
()).
contains
(
localidadNorm
)
&&
h
.
disponible
(
fechaInicio
,
fechaFin
,
numHabSimple
,
numHabDoble
)
).
toList
();
}
/**
* Búsqueda de hoteles por nombre o localidad aproximados
* Búsqueda de hoteles por nombre o localidad aproximados (sin comprobar
* disponibilidad)
* @param nombre el nombre total o parcial del hotel
* @param localidad el nombre total o parcial de la localidad
* @return la lista de hoteles candidatos
...
...
@@ -71,6 +85,18 @@ public class ServicioReservas {
.
toList
();
}
/**
* Comprueba si hay disponibilidad en las fechas indicadas
* @param fechaInicio fecha de inicio de la reserva
* @param fechaFin fecha de final de la reserva
* @param numHabSimple número de habitaciones simples solicitadas
* @param numHabDoble número de habitaciones dobles solicitadas
* @return true si hay disponibilidad, false en caso contrario
*/
public
boolean
disponible
(
Hotel
h
,
LocalDate
fechaInicio
,
LocalDate
fechaFin
,
int
numHabSimple
,
int
numHabDoble
)
{
return
h
.
disponible
(
fechaInicio
,
fechaFin
,
numHabSimple
,
numHabDoble
);
}
public
Reserva
reserva
(
Cliente
cliente
,
Hotel
hotel
,
LocalDate
fechaInicio
,
LocalDate
fechaFin
,
int
numHabSimple
,
int
numHabDoble
)
{
...
...
src/test/java/es/ujaen/dae/reservahoteles/servicios/TestServicioReservas.java
View file @
ecc90d78
...
...
@@ -3,6 +3,7 @@ package es.ujaen.dae.reservahoteles.servicios;
import
es.ujaen.dae.reservahoteles.entidades.Cliente
;
import
es.ujaen.dae.reservahoteles.entidades.Hotel
;
import
java.time.LocalDate
;
import
java.util.List
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -35,13 +36,36 @@ public class TestServicioReservas {
@Test
@DirtiesContext
void
testBuscarHotel
()
{
var
hotel1
=
new
Hotel
(
1
,
"Gran Hotel Almería"
,
"Almería"
,
"Almería"
,
04001
,
25
,
50
,
100
,
180
);
var
hotel2
=
new
Hotel
(
2
,
"Hotel Infanta Cristina"
,
"Jaén"
,
"Jaén"
,
23009
,
30
,
60
,
120
,
200
);
var
hotel1
=
new
Hotel
(
1
,
"Gran Hotel Almería"
,
"Almería"
,
"Almería"
,
"04001"
,
25
,
50
,
100
,
180
);
var
hotel2
=
new
Hotel
(
2
,
"Hotel Infanta Cristina"
,
"Jaén"
,
"Jaén"
,
"23009"
,
30
,
60
,
120
,
200
);
servicio
.
nuevoHotel
(
hotel1
);
servicio
.
nuevoHotel
(
hotel2
);
List
<
Hotel
>
hoteles
=
servicio
.
buscarHotel
(
"gran hotel"
,
"almeria"
);
assertThat
(
hoteles
).
containsOnly
(
hotel1
);
List
<
Hotel
>
hoteles
=
servicio
.
buscarHotel
(
"gran hotel"
,
" almeria"
);
assertThat
(
hoteles
).
hasSize
(
1
);
assertThat
(
hoteles
.
getFirst
().
id
()).
isEqualTo
(
1
);
}
@Test
@DirtiesContext
void
testBuscarPorLocalidad
()
{
var
hotel1
=
new
Hotel
(
1
,
"Gran Hotel Almería"
,
"Almería"
,
"Almería"
,
"04001"
,
25
,
50
,
100
,
180
);
var
hotel2
=
new
Hotel
(
2
,
"Hotel Espejo del Mar"
,
"Almería"
,
"Almería"
,
"04001"
,
15
,
35
,
80
,
110
);
var
hotel3
=
new
Hotel
(
3
,
"Hotel Infanta Cristina"
,
"Jaén"
,
"Jaén"
,
"23009"
,
30
,
60
,
120
,
200
);
servicio
.
nuevoHotel
(
hotel1
);
servicio
.
nuevoHotel
(
hotel2
);
servicio
.
nuevoHotel
(
hotel3
);
List
<
Hotel
>
hoteles
=
servicio
.
buscarPorLocalidad
(
"almeria"
,
LocalDate
.
now
().
plusWeeks
(
2
),
LocalDate
.
now
().
plusWeeks
(
2
).
plusDays
(
2
),
0
,
2
);
assertThat
(
hoteles
).
hasSize
(
2
);
assertThat
(
hoteles
.
getFirst
().
id
()).
isEqualTo
(
1
);
assertThat
(
hoteles
.
getLast
().
id
()).
isEqualTo
(
2
);
}
}
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