Skip to content

Commit 82128fb

Browse files
committed
No-args constructor in all response classes to support Google App Engine
1 parent 0fb7cfb commit 82128fb

21 files changed

+183
-264
lines changed

src/main/java/com/pengrad/telegrambot/model/Audio.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,14 @@
66
*/
77
public class Audio {
88

9-
private final String file_id;
10-
private final Integer duration;
11-
private final String performer;
12-
private final String title;
13-
private final String mime_type;
14-
private final Integer file_size;
9+
private String file_id;
10+
private Integer duration;
11+
private String performer;
12+
private String title;
13+
private String mime_type;
14+
private Integer file_size;
1515

16-
public Audio(String file_id, Integer duration, String performer, String title, String mime_type, Integer filesize) {
17-
this.file_id = file_id;
18-
this.duration = duration;
19-
this.performer = performer;
20-
this.title = title;
21-
this.mime_type = mime_type;
22-
this.file_size = filesize;
16+
Audio() {
2317
}
2418

2519
public String fileId() {
@@ -53,13 +47,12 @@ public boolean equals(Object o) {
5347

5448
Audio audio = (Audio) o;
5549

56-
if (!file_id.equals(audio.file_id)) return false;
57-
if (!duration.equals(audio.duration)) return false;
50+
if (file_id != null ? !file_id.equals(audio.file_id) : audio.file_id != null) return false;
51+
if (duration != null ? !duration.equals(audio.duration) : audio.duration != null) return false;
5852
if (performer != null ? !performer.equals(audio.performer) : audio.performer != null) return false;
5953
if (title != null ? !title.equals(audio.title) : audio.title != null) return false;
6054
if (mime_type != null ? !mime_type.equals(audio.mime_type) : audio.mime_type != null) return false;
61-
return !(file_size != null ? !file_size.equals(audio.file_size) : audio.file_size != null);
62-
55+
return file_size != null ? file_size.equals(audio.file_size) : audio.file_size == null;
6356
}
6457

6558
@Override

src/main/java/com/pengrad/telegrambot/model/Chat.java

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,20 @@ public enum Type {
1212
@SerializedName("private")Private, group, supergroup, channel
1313
}
1414

15-
private final Long id;
16-
private final Type type;
15+
private Long id;
16+
private Type type;
1717

1818
//Private
19-
private final String first_name;
20-
private final String last_name;
19+
private String first_name;
20+
private String last_name;
2121

2222
//Private and Channel
23-
private final String username;
23+
private String username;
2424

2525
//Channel and Group
26-
private final String title;
27-
28-
public Chat(Long id, Type type, String first_name, String last_name, String username, String title) {
29-
this.id = id;
30-
this.type = type;
31-
this.first_name = first_name;
32-
this.last_name = last_name;
33-
this.username = username;
34-
this.title = title;
26+
private String title;
27+
28+
Chat() {
3529
}
3630

3731
public Long id() {
@@ -58,6 +52,26 @@ public String title() {
5852
return title;
5953
}
6054

55+
@Override
56+
public boolean equals(Object o) {
57+
if (this == o) return true;
58+
if (o == null || getClass() != o.getClass()) return false;
59+
60+
Chat chat = (Chat) o;
61+
62+
if (id != null ? !id.equals(chat.id) : chat.id != null) return false;
63+
if (type != chat.type) return false;
64+
if (first_name != null ? !first_name.equals(chat.first_name) : chat.first_name != null) return false;
65+
if (last_name != null ? !last_name.equals(chat.last_name) : chat.last_name != null) return false;
66+
if (username != null ? !username.equals(chat.username) : chat.username != null) return false;
67+
return title != null ? title.equals(chat.title) : chat.title == null;
68+
}
69+
70+
@Override
71+
public int hashCode() {
72+
return id.hashCode();
73+
}
74+
6175
@Override
6276
public String toString() {
6377
return "Chat{" +

src/main/java/com/pengrad/telegrambot/model/Contact.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@
66
*/
77
public class Contact {
88

9-
private final String phone_number;
10-
private final String first_name;
11-
private final String last_name;
12-
private final Integer user_id;
9+
private String phone_number;
10+
private String first_name;
11+
private String last_name;
12+
private Integer user_id;
1313

14-
public Contact(String phone_number, String first_name, String last_name, Integer user_id) {
15-
this.phone_number = phone_number;
16-
this.first_name = first_name;
17-
this.last_name = last_name;
18-
this.user_id = user_id;
14+
Contact() {
1915
}
2016

2117
public String phoneNumber() {
@@ -41,11 +37,11 @@ public boolean equals(Object o) {
4137

4238
Contact contact = (Contact) o;
4339

44-
if (!phone_number.equals(contact.phone_number)) return false;
45-
if (!first_name.equals(contact.first_name)) return false;
40+
if (phone_number != null ? !phone_number.equals(contact.phone_number) : contact.phone_number != null)
41+
return false;
42+
if (first_name != null ? !first_name.equals(contact.first_name) : contact.first_name != null) return false;
4643
if (last_name != null ? !last_name.equals(contact.last_name) : contact.last_name != null) return false;
47-
return !(user_id != null ? !user_id.equals(contact.user_id) : contact.user_id != null);
48-
44+
return user_id != null ? user_id.equals(contact.user_id) : contact.user_id == null;
4945
}
5046

5147
@Override

src/main/java/com/pengrad/telegrambot/model/Document.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@
66
*/
77
public class Document {
88

9-
private final String file_id;
10-
private final PhotoSize thumb;
11-
private final String file_name;
12-
private final String mime_type;
13-
private final Integer file_size;
9+
private String file_id;
10+
private PhotoSize thumb;
11+
private String file_name;
12+
private String mime_type;
13+
private Integer file_size;
1414

15-
public Document(String file_id, PhotoSize thumb, String file_name, String mime_type, Integer file_size) {
16-
this.file_id = file_id;
17-
this.thumb = thumb;
18-
this.file_name = file_name;
19-
this.mime_type = mime_type;
20-
this.file_size = file_size;
15+
Document() {
2116
}
2217

2318
public String fileId() {
@@ -47,12 +42,11 @@ public boolean equals(Object o) {
4742

4843
Document document = (Document) o;
4944

50-
if (!file_id.equals(document.file_id)) return false;
45+
if (file_id != null ? !file_id.equals(document.file_id) : document.file_id != null) return false;
5146
if (thumb != null ? !thumb.equals(document.thumb) : document.thumb != null) return false;
5247
if (file_name != null ? !file_name.equals(document.file_name) : document.file_name != null) return false;
5348
if (mime_type != null ? !mime_type.equals(document.mime_type) : document.mime_type != null) return false;
54-
return !(file_size != null ? !file_size.equals(document.file_size) : document.file_size != null);
55-
49+
return file_size != null ? file_size.equals(document.file_size) : document.file_size == null;
5650
}
5751

5852
@Override

src/main/java/com/pengrad/telegrambot/model/File.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@
66
*/
77
public class File {
88

9-
private final String file_id;
10-
private final Integer file_size;
11-
private final String file_path;
12-
13-
public File(String file_id, Integer file_size, String file_path) {
14-
this.file_id = file_id;
15-
this.file_size = file_size;
16-
this.file_path = file_path;
9+
private String file_id;
10+
private Integer file_size;
11+
private String file_path;
12+
13+
File() {
1714
}
1815

1916
public String fileId() {
@@ -35,9 +32,9 @@ public boolean equals(Object o) {
3532

3633
File file = (File) o;
3734

38-
if (!file_id.equals(file.file_id)) return false;
35+
if (file_id != null ? !file_id.equals(file.file_id) : file.file_id != null) return false;
3936
if (file_size != null ? !file_size.equals(file.file_size) : file.file_size != null) return false;
40-
return !(file_path != null ? !file_path.equals(file.file_path) : file.file_path != null);
37+
return file_path != null ? file_path.equals(file.file_path) : file.file_path == null;
4138
}
4239

4340
@Override

src/main/java/com/pengrad/telegrambot/model/Location.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
*/
77
public class Location {
88

9-
private final Float longitude;
10-
private final Float latitude;
9+
private Float longitude;
10+
private Float latitude;
1111

12-
public Location(Float longitude, Float latitude) {
13-
this.longitude = longitude;
14-
this.latitude = latitude;
12+
Location() {
1513
}
1614

1715
public Float longitude() {
@@ -29,9 +27,8 @@ public boolean equals(Object o) {
2927

3028
Location location = (Location) o;
3129

32-
if (!longitude.equals(location.longitude)) return false;
33-
return latitude.equals(location.latitude);
34-
30+
if (longitude != null ? !longitude.equals(location.longitude) : location.longitude != null) return false;
31+
return latitude != null ? latitude.equals(location.latitude) : location.latitude == null;
3532
}
3633

3734
@Override

src/main/java/com/pengrad/telegrambot/model/Message.java

Lines changed: 32 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,62 +8,35 @@
88
*/
99
public class Message {
1010

11-
private final Integer message_id;
12-
private final User from;
13-
private final Integer date;
14-
private final Chat chat;
15-
private final User forward_from;
16-
private final Integer forward_date;
17-
private final Message reply_to_message;
18-
private final String text;
19-
private final Audio audio;
20-
private final Document document;
21-
private final PhotoSize[] photo;
22-
private final Sticker sticker;
23-
private final Video video;
24-
private final Voice voice;
25-
private final String caption;
26-
private final Contact contact;
27-
private final Location location;
28-
private final User new_chat_participant;
29-
private final User left_chat_participant;
30-
private final String new_chat_title;
31-
private final PhotoSize[] new_chat_photo;
32-
private final Boolean delete_chat_photo;
33-
private final Boolean group_chat_created;
34-
private final Boolean supergroup_chat_created;
35-
private final Boolean channel_chat_created;
36-
private final Long migrate_to_chat_id;
37-
private final Long migrate_from_chat_id;
38-
39-
public Message(Integer message_id, User from, Integer date, Chat chat, User forward_from, Integer forward_date, Message reply_to_message, String text, Audio audio, Document document, PhotoSize[] photo, Sticker sticker, Video video, Voice voice, String caption, Contact contact, Location location, User new_chat_participant, User left_chat_participant, String new_chat_title, PhotoSize[] new_chat_photo, Boolean delete_chat_photo, Boolean group_chat_created, Boolean supergroup_chat_created, Boolean channel_chat_created, Long migrate_to_chat_id, Long migrate_from_chat_id) {
40-
this.message_id = message_id;
41-
this.from = from;
42-
this.date = date;
43-
this.chat = chat;
44-
this.forward_from = forward_from;
45-
this.forward_date = forward_date;
46-
this.reply_to_message = reply_to_message;
47-
this.text = text;
48-
this.audio = audio;
49-
this.document = document;
50-
this.photo = photo;
51-
this.sticker = sticker;
52-
this.video = video;
53-
this.voice = voice;
54-
this.caption = caption;
55-
this.contact = contact;
56-
this.location = location;
57-
this.new_chat_participant = new_chat_participant;
58-
this.left_chat_participant = left_chat_participant;
59-
this.new_chat_title = new_chat_title;
60-
this.new_chat_photo = new_chat_photo;
61-
this.delete_chat_photo = delete_chat_photo;
62-
this.group_chat_created = group_chat_created;
63-
this.supergroup_chat_created = supergroup_chat_created;
64-
this.channel_chat_created = channel_chat_created;
65-
this.migrate_to_chat_id = migrate_to_chat_id;
66-
this.migrate_from_chat_id = migrate_from_chat_id;
11+
private Integer message_id;
12+
private User from;
13+
private Integer date;
14+
private Chat chat;
15+
private User forward_from;
16+
private Integer forward_date;
17+
private Message reply_to_message;
18+
private String text;
19+
private Audio audio;
20+
private Document document;
21+
private PhotoSize[] photo;
22+
private Sticker sticker;
23+
private Video video;
24+
private Voice voice;
25+
private String caption;
26+
private Contact contact;
27+
private Location location;
28+
private User new_chat_participant;
29+
private User left_chat_participant;
30+
private String new_chat_title;
31+
private PhotoSize[] new_chat_photo;
32+
private Boolean delete_chat_photo;
33+
private Boolean group_chat_created;
34+
private Boolean supergroup_chat_created;
35+
private Boolean channel_chat_created;
36+
private Long migrate_to_chat_id;
37+
private Long migrate_from_chat_id;
38+
39+
Message() {
6740
}
6841

6942
public Integer messageId() {
@@ -181,10 +154,10 @@ public boolean equals(Object o) {
181154

182155
Message message = (Message) o;
183156

184-
if (!message_id.equals(message.message_id)) return false;
157+
if (message_id != null ? !message_id.equals(message.message_id) : message.message_id != null) return false;
185158
if (from != null ? !from.equals(message.from) : message.from != null) return false;
186-
if (!date.equals(message.date)) return false;
187-
if (!chat.equals(message.chat)) return false;
159+
if (date != null ? !date.equals(message.date) : message.date != null) return false;
160+
if (chat != null ? !chat.equals(message.chat) : message.chat != null) return false;
188161
if (forward_from != null ? !forward_from.equals(message.forward_from) : message.forward_from != null)
189162
return false;
190163
if (forward_date != null ? !forward_date.equals(message.forward_date) : message.forward_date != null)
@@ -221,7 +194,6 @@ public boolean equals(Object o) {
221194
if (migrate_to_chat_id != null ? !migrate_to_chat_id.equals(message.migrate_to_chat_id) : message.migrate_to_chat_id != null)
222195
return false;
223196
return migrate_from_chat_id != null ? migrate_from_chat_id.equals(message.migrate_from_chat_id) : message.migrate_from_chat_id == null;
224-
225197
}
226198

227199
@Override

src/main/java/com/pengrad/telegrambot/model/PhotoSize.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@
66
*/
77
public class PhotoSize {
88

9-
private final String file_id;
10-
private final Integer width;
11-
private final Integer height;
12-
private final Integer file_size;
9+
private String file_id;
10+
private Integer width;
11+
private Integer height;
12+
private Integer file_size;
1313

14-
public PhotoSize(String file_id, Integer width, Integer height, Integer file_size) {
15-
this.file_id = file_id;
16-
this.width = width;
17-
this.height = height;
18-
this.file_size = file_size;
14+
PhotoSize() {
1915
}
2016

2117
public String fileId() {
@@ -41,11 +37,10 @@ public boolean equals(Object o) {
4137

4238
PhotoSize photoSize = (PhotoSize) o;
4339

44-
if (!file_id.equals(photoSize.file_id)) return false;
45-
if (!width.equals(photoSize.width)) return false;
46-
if (!height.equals(photoSize.height)) return false;
47-
return !(file_size != null ? !file_size.equals(photoSize.file_size) : photoSize.file_size != null);
48-
40+
if (file_id != null ? !file_id.equals(photoSize.file_id) : photoSize.file_id != null) return false;
41+
if (width != null ? !width.equals(photoSize.width) : photoSize.width != null) return false;
42+
if (height != null ? !height.equals(photoSize.height) : photoSize.height != null) return false;
43+
return file_size != null ? file_size.equals(photoSize.file_size) : photoSize.file_size == null;
4944
}
5045

5146
@Override

0 commit comments

Comments
 (0)