From 0d245b665e856d0a45d6f2a7f5982db810e78905 Mon Sep 17 00:00:00 2001 From: Gab Caser Date: Tue, 8 Apr 2025 17:19:36 +0200 Subject: [PATCH] hecho --- .idea/.gitignore | 3 + .idea/compiler.xml | 13 + .idea/encodings.xml | 7 + .idea/jarRepositories.xml | 20 + .idea/lab-maven-gson.iml | 9 + .idea/misc.xml | 14 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + lab-maven/pom.xml | 24 ++ lab-maven/src/main/java/Apartment.java | 93 +++++ lab-maven/src/main/java/ApartmentCreator.java | 60 +++ lab-maven/src/main/java/ApartmentManager.java | 43 ++ .../src/main/resources/apartments.json | 0 .../src/main/resources/new-apartments.json | 29 ++ lab-maven/target/classes/Apartment.class | Bin 0 -> 2650 bytes .../target/classes/ApartmentCreator.class | Bin 0 -> 2174 bytes .../target/classes/ApartmentManager.class | Bin 0 -> 1544 bytes lab-maven/target/classes/apartments.json | 394 ++++++++++++++++++ lab-maven/target/classes/new-apartments.json | 29 ++ 19 files changed, 752 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/lab-maven-gson.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 lab-maven/pom.xml create mode 100644 lab-maven/src/main/java/Apartment.java create mode 100644 lab-maven/src/main/java/ApartmentCreator.java create mode 100644 lab-maven/src/main/java/ApartmentManager.java rename apartments.json => lab-maven/src/main/resources/apartments.json (100%) create mode 100644 lab-maven/src/main/resources/new-apartments.json create mode 100644 lab-maven/target/classes/Apartment.class create mode 100644 lab-maven/target/classes/ApartmentCreator.class create mode 100644 lab-maven/target/classes/ApartmentManager.class create mode 100644 lab-maven/target/classes/apartments.json create mode 100644 lab-maven/target/classes/new-apartments.json diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..e3f6846 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..c66bc72 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/lab-maven-gson.iml b/.idea/lab-maven-gson.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/lab-maven-gson.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7403127 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..00f30c4 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/lab-maven/pom.xml b/lab-maven/pom.xml new file mode 100644 index 0000000..7931e9d --- /dev/null +++ b/lab-maven/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + org.example + lab-maven + 1.0-SNAPSHOT + + + 21 + 21 + UTF-8 + + + + com.google.code.gson + gson + 2.10 + + + + \ No newline at end of file diff --git a/lab-maven/src/main/java/Apartment.java b/lab-maven/src/main/java/Apartment.java new file mode 100644 index 0000000..abd6855 --- /dev/null +++ b/lab-maven/src/main/java/Apartment.java @@ -0,0 +1,93 @@ +import java.util.UUID; + +public class Apartment { + private long id; + private String address; + private double price; + private int rooms; + private String description; + private String owner; + private boolean available; + + public Apartment(String address, double price, int rooms, String description, String owner, boolean available) { + this.id=UUID.randomUUID().getMostSignificantBits(); + setAddress(address); + setPrice(price); + setRooms(rooms); + setDescription(description); + setOwner(owner); + setAvailable(available); + } + + public Apartment() { + this.id=UUID.randomUUID().getMostSignificantBits(); + } + + //Setters + public void setAddress(String address) { + this.address = address; + } + + public void setAvailable(boolean available) { + this.available = available; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setRooms(int rooms) { + this.rooms = rooms; + } + + public void setPrice(double price) { + this.price = price; + } + + //Getters + + public long getId() { + return id; + } + + public String getAddress() { + return address; + } + + public double getPrice() { + return price; + } + + public int getRooms() { + return rooms; + } + + public String getDescription() { + return description; + } + + public String getOwner() { + return owner; + } + + public boolean isAvailable() { + return available; + } + + @Override + public String toString() { + return "Apartment{" + + "id=" + id + + ", address='" + address + '\'' + + ", price=" + price + + ", rooms=" + rooms + + ", description='" + description + '\'' + + ", owner='" + owner + '\'' + + ", available=" + available + + '}'; + } +} diff --git a/lab-maven/src/main/java/ApartmentCreator.java b/lab-maven/src/main/java/ApartmentCreator.java new file mode 100644 index 0000000..7e909ad --- /dev/null +++ b/lab-maven/src/main/java/ApartmentCreator.java @@ -0,0 +1,60 @@ +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class ApartmentCreator { + public static void main(String[] args) throws IOException { + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + List newApartments = new ArrayList<>(); + + Apartment apartamento1 = new Apartment( + "Calle Mayor 123, Madrid", + 1200.00, + 3, + "Luminoso piso en el centro con balcón y cocina equipada", + "Agencia López", + true + ); + + Apartment apartamento2 = new Apartment( + "Avenida de Andalucía 45, Sevilla", + 950.50, + 2, + "Acogedor apartamento cerca del parque, ideal para parejas", + "Inmobiliaria Sur", + false + ); + + Apartment apartamento3 = new Apartment( + "Passeig de Gràcia 78, Barcelona", + 1800.75, + 4, + "Ático de lujo con terraza privada y vistas a la ciudad", + "Grupo BCN Homes", + true + ); + + Apartment apartamento4 = new Apartment( + "Rúa do Franco 12, Santiago de Compostela", + 750.00, + 1, + "Estudio económico en zona histórica, perfecto para estudiantes", + "Galicia Gestión", + true + ); + + newApartments.add(apartamento1); + newApartments.add(apartamento2); + newApartments.add(apartamento3); + + System.out.println(newApartments); + + FileWriter writer = new FileWriter("lab-maven/src/main/resources/new-apartments.json"); + gson.toJson(newApartments,writer); + writer.close(); + } +} diff --git a/lab-maven/src/main/java/ApartmentManager.java b/lab-maven/src/main/java/ApartmentManager.java new file mode 100644 index 0000000..4e96bd7 --- /dev/null +++ b/lab-maven/src/main/java/ApartmentManager.java @@ -0,0 +1,43 @@ +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +public class ApartmentManager { + public static void main(String[] args) throws IOException { + //inicializamos el Gson + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + // localizamos el archivo que queremos leer + String fileLocation = "lab-maven/src/main/resources/apartments.json"; + FileReader reader = new FileReader(fileLocation); + + Apartment[] apartmentArray = gson.fromJson(reader, Apartment[].class); + + //JsonArray pisosArray = gson.fromJson(reader, JsonArray.class); + //System.out.println(pisosArray.get(1)); + + /* for (JsonElement apartment:pisosArray ){ + System.out.println("apartment: " + apartment); + Apartment piso = gson.fromJson(apartment, Apartment.class); + System.out.println("piso: "+ piso); + apartmentList.add(piso); + }*/ + + List apartmentList = new ArrayList<>(); + Collections.addAll(apartmentList, apartmentArray); + + System.out.println(apartmentArray[0]); + System.out.println(apartmentList.get(0)); + + reader.close(); + + } +} diff --git a/apartments.json b/lab-maven/src/main/resources/apartments.json similarity index 100% rename from apartments.json rename to lab-maven/src/main/resources/apartments.json diff --git a/lab-maven/src/main/resources/new-apartments.json b/lab-maven/src/main/resources/new-apartments.json new file mode 100644 index 0000000..44585e5 --- /dev/null +++ b/lab-maven/src/main/resources/new-apartments.json @@ -0,0 +1,29 @@ +[ + { + "id": 2181885421108543604, + "address": "Calle Mayor 123, Madrid", + "price": 1200.0, + "rooms": 3, + "description": "Luminoso piso en el centro con balcón y cocina equipada", + "owner": "Agencia López", + "available": true + }, + { + "id": 8801280920911431920, + "address": "Avenida de Andalucía 45, Sevilla", + "price": 950.5, + "rooms": 2, + "description": "Acogedor apartamento cerca del parque, ideal para parejas", + "owner": "Inmobiliaria Sur", + "available": false + }, + { + "id": -8073628784739201477, + "address": "Passeig de Gràcia 78, Barcelona", + "price": 1800.75, + "rooms": 4, + "description": "Ático de lujo con terraza privada y vistas a la ciudad", + "owner": "Grupo BCN Homes", + "available": true + } +] \ No newline at end of file diff --git a/lab-maven/target/classes/Apartment.class b/lab-maven/target/classes/Apartment.class new file mode 100644 index 0000000000000000000000000000000000000000..aef8669f1b8cc3ddc2deb0a831fa3872d78c6980 GIT binary patch literal 2650 zcma)7Yg5}s6g>-mfKhljKthvHLLnFfaY#!_V;<#Eim3@{c(tT2VJjdo5+eyZnNI&l ze?&WNXA0@$Lw`VjRHx@k#u!_4I-d2euI@ee+`VU4fB*CLF935mNT30YaYQsk5mRVC z&`>g?SQpHQYn5LKEGe zJ7&R9h@=*ScYPY}qd$1}!nThH6iMZRcLN#*B~2^i77e%Hn8%)JTLL+xAtkQ_a_xJ| zaKxC_FoID9O=z9!W=Y>I`MGw6x1_L#8ZvmK5Z5m_C+jJT<6{l);{%q@u3Vs~9eMLa z!-oP9wI!)oKGN`1EG@-LhGL)6Fb%dZ>I7A(oLE2B*!_80kArb%hIRkls^DJzG^ zfr1x9SuQl>s1X{fG!l6D%3xm8t&#)%cl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qKB zf3ORO)A=L$qp3B#F`bCs?7~}Z`M2}EtrQKV64{9^6wUnU{2Bdhs4bE8b)i3%Kc62+ zWa;9mKQYvTJH^AP=bN_X=68%1S8;V6mHGVi8fJ#flf}d4DrWUEud`}}&T0sqTsyet z(8INWgSZF_H@TDOLk;J!gnoRE^Y{`2_zr{kfm%OtPTi;Gt!B1-`+%oTe2Xd`5}h7= z4TVLbQb3H);L_hk;#K1=Me9@WxND={Abjr9w7ds(JmSB0Kua3orj3v`B1%$}#QZ+y Iz6DSI14(H`LjV8( literal 0 HcmV?d00001 diff --git a/lab-maven/target/classes/ApartmentManager.class b/lab-maven/target/classes/ApartmentManager.class new file mode 100644 index 0000000000000000000000000000000000000000..23093415e58893a2298a0dac9838cc357310ed61 GIT binary patch literal 1544 zcmaJ>Yg5}s6g`V&1dc+$7!s4Fc|vRgC{3F_5T$j2zX4S6I)^@FOc)lj=oc8?mG7kO z%fPkQws%!M5$Ip=0xww<$dt;PCI$p9*29MFhN0^#+l|A(enfMx>G?Y<%E3fNn==+H zoD~>}Rk9wbB-vk&ydd!cSKxA~T>VT9N9UijFpLo%Uyqbbl)!~gBsl{Z6`1km_H0AG zQ-K{vb-N+Gz>ZWLHlw6JrATv{f&(A9}ueu4D?nfb*J(3j$-M zYLAOrLhP=i`=1c7-c&0`1&Q?wTr%;ch0C}iP&lnGfq}PC*m%OD1@3kV^W^ra&as1* zd>O}1`Ix6Y2FJuTfzcFEGx2=85=C;q>cvS8S2f|2m@;wGLJ4JJ@5L>JzRxjwVGxr` zxwBL8eX`ZTke2F&IBz~axcqt$w=iR3*1{a@6B4QI$BAlC8DWz`8EYrAuXNJnOvwiM z`3iSTd~M+y+&yaHWQ>5hr?ugeofEWodM|ID!FTxH#19tc;Rp=%`qLB;fU7is(()n(t|$Q-}Z!tv`YB(s4q&BI3S`T;`6Rvdv9>r8WY} zAL*2nCifIH_1GOsPv)Az?u|%=ByhItXfrz8&PxTNJu-6W;{6Tesb*9T4${j?RXY(52_+35p_ z-_q@Sw0avD!V<034#0gp;A#*L@rXrq@_)!M64*F|xpjcS7IG~NRrC3kLlm}V4lurY zYc^kO;o?6i&Krlg%Bbt}*