11package io .snabble .sdk ;
22
3+ import android .os .Parcel ;
4+ import android .os .Parcelable ;
5+
6+ import com .google .gson .Gson ;
7+ import com .google .gson .GsonBuilder ;
8+ import com .google .gson .InstanceCreator ;
39import com .google .gson .JsonElement ;
410import com .google .gson .annotations .SerializedName ;
511
612import java .io .Serializable ;
13+ import java .lang .reflect .Type ;
14+ import java .util .Arrays ;
715import java .util .Map ;
816
917import io .snabble .sdk .utils .GsonHolder ;
1018import io .snabble .sdk .utils .Logger ;
1119
12- public class Shop implements Serializable {
20+ public class Shop implements Serializable , Parcelable {
1321 public enum Service {
1422 @ SerializedName ("euro" )
1523 EURO_PAYMENT ,
@@ -29,6 +37,13 @@ public enum Service {
2937
3038 public class Href {
3139 public String href ;
40+
41+ @ Override
42+ public String toString () {
43+ return "Href{" +
44+ "href='" + href + '\'' +
45+ '}' ;
46+ }
3247 }
3348
3449 public class OpeningHourSpecification {
@@ -47,6 +62,15 @@ public String getOpens() {
4762 public String getDayOfWeek () {
4863 return dayOfWeek ;
4964 }
65+
66+ @ Override
67+ public String toString () {
68+ return "OpeningHourSpecification{" +
69+ "closes='" + closes + '\'' +
70+ ", opens='" + opens + '\'' +
71+ ", dayOfWeek='" + dayOfWeek + '\'' +
72+ '}' ;
73+ }
5074 }
5175
5276 private String id ;
@@ -68,6 +92,10 @@ public String getDayOfWeek() {
6892 private OpeningHourSpecification [] openingHoursSpecification ;
6993 private JsonElement external ;
7094
95+ public Shop () {
96+
97+ }
98+
7199 public String getId () {
72100 return id ;
73101 }
@@ -137,107 +165,78 @@ static Shop[] fromJson(JsonElement json) {
137165 }
138166 }
139167
140- public static class Builder {
141- private String id ;
142- private String externalId ;
143- private String name ;
144- private Shop .Service [] services ;
145- private String street ;
146- private String zipCode ;
147- private String city ;
148- private String country ;
149- private String state ;
150- private String phone ;
151- private double latitude ;
152- private double longitude ;
153- private OpeningHourSpecification [] openingHoursSpecification ;
154- private JsonElement external ;
155-
156- public Builder id (String id ) {
157- this .id = id ;
158- return this ;
159- }
160-
161- public Builder name (String name ) {
162- this .name = name ;
163- return this ;
164- }
165-
166- public Builder services (Shop .Service [] services ) {
167- this .services = services ;
168- return this ;
169- }
168+ @ Override
169+ public int hashCode () {
170+ return id .hashCode ();
171+ }
170172
171- public Builder street ( String street ) {
172- this . street = street ;
173- return this ;
174- }
173+ @ Override
174+ public boolean equals ( Object o ) {
175+ if ( this == o ) return true ;
176+ if ( o == null || getClass () != o . getClass ()) return false ;
175177
176- public Builder zipCode (String zipCode ) {
177- this .zipCode = zipCode ;
178- return this ;
179- }
178+ Shop shop = (Shop ) o ;
180179
181- public Builder city (String city ) {
182- this .city = city ;
183- return this ;
184- }
180+ return id .equals (shop .id );
181+ }
185182
186- public Builder country (String country ) {
187- this .country = country ;
188- return this ;
189- }
183+ public String toShortString () {
184+ return "Shop{" +
185+ "id='" + id + '\'' +
186+ ", name='" + name + '\'' +
187+ '}' ;
188+ }
190189
191- public Builder state (String state ) {
192- this .state = state ;
193- return this ;
194- }
190+ @ Override
191+ public String toString () {
192+ return "Shop{" +
193+ "id='" + id + '\'' +
194+ ", externalId='" + externalId + '\'' +
195+ ", name='" + name + '\'' +
196+ ", services=" + Arrays .toString (services ) +
197+ ", street='" + street + '\'' +
198+ ", zipCode='" + zipCode + '\'' +
199+ ", city='" + city + '\'' +
200+ ", country='" + country + '\'' +
201+ ", state='" + state + '\'' +
202+ ", phone='" + phone + '\'' +
203+ ", links=" + links +
204+ ", latitude=" + latitude +
205+ ", longitude=" + longitude +
206+ ", openingHoursSpecification=" + Arrays .toString (openingHoursSpecification ) +
207+ ", external=" + external +
208+ '}' ;
209+ }
195210
196- public Builder phone ( String phone ) {
197- this . phone = phone ;
198- return this ;
199- }
211+ @ Override
212+ public int describeContents () {
213+ return 0 ;
214+ }
200215
201- public Builder latLng ( double latitude , double longitude ) {
202- this . latitude = latitude ;
203- this . longitude = longitude ;
204- return this ;
205- }
216+ @ Override
217+ public void writeToParcel ( Parcel dest , int flags ) {
218+ String str = GsonHolder . get (). toJson ( this ) ;
219+ dest . writeString ( str ) ;
220+ }
206221
207- public Builder openingHours ( OpeningHourSpecification [] openingHours ) {
208- this . openingHoursSpecification = openingHours ;
209- return this ;
210- }
222+ protected Shop ( Parcel in ) {
223+ InstanceCreator < Shop > creator = new InstanceCreator < Shop >() {
224+ public Shop createInstance ( Type type ) { return Shop . this ; }
225+ };
211226
212- public Builder externalId (String externalId ) {
213- this .externalId = externalId ;
214- return this ;
215- }
227+ Gson gson = new GsonBuilder ().registerTypeAdapter (Shop .class , creator ).create ();
228+ gson .fromJson (in .readString (), Shop .class );
229+ }
216230
217- public Builder external (JsonElement external ) {
218- this .external = external ;
219- return this ;
231+ public static final Parcelable .Creator <Shop > CREATOR = new Parcelable .Creator <Shop >() {
232+ @ Override
233+ public Shop createFromParcel (Parcel source ) {
234+ return new Shop (source );
220235 }
221236
222- public Shop create () {
223- Shop shop = new Shop ();
224-
225- shop .id = id ;
226- shop .externalId = externalId ;
227- shop .name = name ;
228- shop .services = services ;
229- shop .street = street ;
230- shop .zipCode = zipCode ;
231- shop .city = city ;
232- shop .country = country ;
233- shop .state = state ;
234- shop .phone = phone ;
235- shop .latitude = latitude ;
236- shop .longitude = longitude ;
237- shop .openingHoursSpecification = openingHoursSpecification ;
238- shop .external = external ;
239-
240- return shop ;
237+ @ Override
238+ public Shop [] newArray (int size ) {
239+ return new Shop [size ];
241240 }
242- }
241+ };
243242}
0 commit comments