forked from fabienrenaud/java-json-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClients.java
469 lines (381 loc) · 12.4 KB
/
Clients.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
package com.github.fabienrenaud.jjb.model;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter;
import com.dslplatform.json.CompiledJson;
import com.dslplatform.json.JsonAttribute;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
@io.avaje.jsonb.Json
@JsonObject
@CompiledJson
@jodd.json.meta.JSON
public class Clients {
@JsonField
@jodd.json.meta.JSON
private List<Client> clients;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Clients)) {
return false;
}
Clients that = (Clients) o;
return Objects.equals(clients, that.clients);
}
@Override
public int hashCode() {
return Objects.hashCode(clients);
}
@Override
public String toString() {
return "Clients{" + "clients=" + clients + '}';
}
public List<Client> getClients() {
return clients;
}
public void setClients(List<Client> clients) {
this.clients = clients;
}
@io.avaje.jsonb.Json
@JsonObject
public static final class Client {
@JsonField
private long id;
@JsonField
private int index;
@JsonField(typeConverter = LoganUUIDConverter.class)
private UUID guid;
@JsonField
private boolean isActive;
@JsonField(typeConverter = LoganBigDecimalConverter.class)
private BigDecimal balance;
@JsonField
private String picture;
@JsonField
private int age;
@JsonField(typeConverter = LoganEnumConverter.class)
private EyeColor eyeColor;
@JsonField
private String name;
@JsonField
private String gender;
@JsonField
private String company;
@JsonField
@jodd.json.meta.JSON
private String[] emails;
@JsonField
@jodd.json.meta.JSON
private long[] phones;
@JsonField
private String address;
@JsonField
private String about;
@JsonField(typeConverter = LoganLocalDateConverter.class)
private LocalDate registered;
@JsonField
private double latitude;
@JsonField
private double longitude;
@JsonField
@JsonAttribute(nullable = false)
@jodd.json.meta.JSON
private List<String> tags;
@JsonField
@JsonAttribute(nullable = false)
@jodd.json.meta.JSON
private List<Partner> partners;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Client)) {
return false;
}
Client client = (Client) o;
return index == client.index &&
isActive == client.isActive &&
age == client.age &&
Math.abs(Double.doubleToLongBits(client.latitude) - Double.doubleToLongBits(latitude)) < 3 &&
Math.abs(Double.doubleToLongBits(client.longitude) - Double.doubleToLongBits(longitude)) < 3 &&
Objects.equals(id, client.id) &&
Objects.equals(guid, client.guid) &&
balance.compareTo(client.balance) == 0 &&
Objects.equals(picture, client.picture) &&
Objects.equals(eyeColor, client.eyeColor) &&
Objects.equals(name, client.name) &&
Objects.equals(gender, client.gender) &&
Objects.equals(company, client.company) &&
Arrays.equals(emails, client.emails) &&
Arrays.equals(phones, client.phones) &&
Objects.equals(address, client.address) &&
Objects.equals(about, client.about) &&
Objects.equals(registered, client.registered) &&
Objects.equals(tags, client.tags) &&
Objects.equals(partners, client.partners);
}
@Override
public int hashCode() {
return Objects.hash(id, index, guid, isActive, balance, picture, age, eyeColor, name, gender, company,
Arrays.hashCode(emails), Arrays.hashCode(phones), address, about, registered, tags, partners);
}
private String toStr(long[] nums) {
StringBuilder sb = new StringBuilder();
sb.append('[');
boolean first = true;
for(long l : nums) {
if (first) first = false;
else sb.append(',');
sb.append(l);
}
sb.append(']');
return sb.toString();
}
@Override
public String toString() {
return "JsonDataObj{" + "id=" + id + ", index=" + index + ", guid=" + guid + ", isActive=" + isActive + ", balance=" + balance + ", picture=" + picture + ", age=" + age + ", eyeColor=" + eyeColor + ", name=" + name + ", gender=" + gender + ", company=" + company + ", emails=" + (emails != null ? Arrays.asList(emails) : null) + ", phones=" + toStr(phones) + ", address=" + address + ", about=" + about + ", registered=" + registered + ", latitude=" + latitude + ", longitude=" + longitude + ", tags=" + tags + ", partners=" + partners + '}';
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public UUID getGuid() {
return guid;
}
public void setGuid(UUID guid) {
this.guid = guid;
}
public boolean getIsActive() {
return isActive;
}
public void setIsActive(boolean isActive) {
this.isActive = isActive;
}
public BigDecimal getBalance() {
return balance;
}
public void setBalance(BigDecimal balance) {
this.balance = balance;
}
public String getPicture() {
return picture;
}
public void setPicture(String picture) {
this.picture = picture;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public EyeColor getEyeColor() {
return eyeColor;
}
public void setEyeColor(EyeColor eyeColor) {
this.eyeColor = eyeColor;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public String[] getEmails() {
return emails;
}
public void setEmails(String[] emails) {
this.emails = emails;
}
public long[] getPhones() {
return phones;
}
public void setPhones(long[] phones) {
this.phones = phones;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getAbout() {
return about;
}
public void setAbout(String about) {
this.about = about;
}
public LocalDate getRegistered() {
return registered;
}
public void setRegistered(LocalDate registered) {
this.registered = registered;
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
public List<String> getTags() {
return tags;
}
public void setTags(List<String> tags) {
this.tags = tags;
}
public List<Partner> getPartners() {
return partners;
}
public void setPartners(List<Partner> partners) {
this.partners = partners;
}
}
public static class LoganEnumConverter extends StringBasedTypeConverter<EyeColor> {
@Override
public Clients.EyeColor getFromString(String s) {
return Clients.EyeColor.valueOf(s);
}
public String convertToString(Clients.EyeColor object) {
return object.toString();
}
}
public static class LoganBigDecimalConverter extends StringBasedTypeConverter<BigDecimal> {
@Override
public BigDecimal getFromString(String s) {
return new BigDecimal(s);
}
public String convertToString(BigDecimal object) {
return object.toPlainString();
}
}
public static class LoganUUIDConverter extends StringBasedTypeConverter<UUID> {
@Override
public UUID getFromString(String s) {
return UUID.fromString(s);
}
public String convertToString(UUID object) {
return object.toString();
}
}
public static class LoganLocalDateConverter extends StringBasedTypeConverter<LocalDate> {
@Override
public LocalDate getFromString(String s) {
return LocalDate.parse(s);
}
public String convertToString(LocalDate object) {
return object.toString();
}
}
public static class LoganODTConverter extends StringBasedTypeConverter<OffsetDateTime> {
@Override
public OffsetDateTime getFromString(String s) {
return OffsetDateTime.parse(s);
}
public String convertToString(OffsetDateTime object) {
return object.toString();
}
}
public enum EyeColor {
BROWN,
BLUE,
GREEN;
public static EyeColor fromNumber(int i) {
if (i == 0) return BROWN;
if (i == 1) return BLUE;
return GREEN;
}
}
@io.avaje.jsonb.Json
@JsonObject
public static final class Partner {
@JsonField
private long id;
@JsonField
private String name;
@JsonField(typeConverter = LoganODTConverter.class)
private OffsetDateTime since;
public Partner() {
}
public static Partner create(long id, String name, OffsetDateTime since) {
Partner partner = new Partner();
partner.id = id;
partner.name = name;
partner.since = since;
return partner;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Partner)) {
return false;
}
Partner partner = (Partner) o;
return id == partner.id &&
Objects.equals(since, partner.since) &&
Objects.equals(name, partner.name);
}
@Override
public int hashCode() {
return Objects.hash(id, since, name);
}
@Override
public String toString() {
return "Partner{" + "id=" + id + ", name=" + name + ", since=" + since + '}';
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public OffsetDateTime getSince() {
return since;
}
public void setSince(OffsetDateTime since) {
this.since = since;
}
}
}