Skip to content

Commit 7b5e0b4

Browse files
committed
Add models methods. Remove deprecated. Fix tests
1 parent 8f742c8 commit 7b5e0b4

24 files changed

+530
-60
lines changed

library/src/main/java/com/pengrad/telegrambot/model/ChatFullInfo.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public enum Type {
7474
private String custom_emoji_sticker_set_name;
7575
private Long linked_chat_id;
7676
private ChatLocation location;
77-
private Boolean can_send_gift;
7877
private AcceptedGiftTypes accepted_gift_types;
7978
private UserRating rating;
8079
private Integer paid_message_star_count;
@@ -263,15 +262,6 @@ public ChatLocation location() {
263262
return location;
264263
}
265264

266-
/**
267-
*
268-
* @deprecated Use 'acceptedGiftTypes' instead
269-
*/
270-
@Deprecated
271-
public Boolean canSendGift() {
272-
return can_send_gift;
273-
}
274-
275265
public AcceptedGiftTypes acceptedGiftTypes() {
276266
return accepted_gift_types;
277267
}

library/src/main/java/com/pengrad/telegrambot/model/LocationAddress.kt

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.pengrad.telegrambot.model
22

3-
@Suppress("unused")
43
class LocationAddress private constructor(
54
@get:JvmName("countryCode") val countryCode: String,
65
@get:JvmName("state") var state: String?,
@@ -27,4 +26,31 @@ class LocationAddress private constructor(
2726
this.street = street
2827
}
2928

29+
override fun toString(): String {
30+
return "LocationAddress(countryCode='$countryCode', state=$state, city=$city, street=$street)"
31+
}
32+
33+
override fun equals(other: Any?): Boolean {
34+
if (this === other) return true
35+
if (javaClass != other?.javaClass) return false
36+
37+
other as LocationAddress
38+
39+
if (countryCode != other.countryCode) return false
40+
if (state != other.state) return false
41+
if (city != other.city) return false
42+
if (street != other.street) return false
43+
44+
return true
45+
}
46+
47+
override fun hashCode(): Int {
48+
var result = countryCode.hashCode()
49+
result = 31 * result + (state?.hashCode() ?: 0)
50+
result = 31 * result + (city?.hashCode() ?: 0)
51+
result = 31 * result + (street?.hashCode() ?: 0)
52+
return result
53+
}
54+
55+
3056
}

library/src/main/java/com/pengrad/telegrambot/model/business/BusinessConnection.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public class BusinessConnection {
1111
private Long user_chat_id;
1212
private Integer date;
1313
private BusinessBotRights rights;
14-
private Boolean can_reply;
1514
private Boolean is_enabled;
1615

1716
public String id() {
@@ -30,14 +29,6 @@ public Integer date() {
3029
return date;
3130
}
3231

33-
/**
34-
* @deprecated Use the 'rights' field instead.
35-
*/
36-
@Deprecated
37-
public Boolean canReply() {
38-
return can_reply;
39-
}
40-
4132
public BusinessBotRights rights() {
4233
return rights;
4334
}

library/src/main/java/com/pengrad/telegrambot/model/checklist/ChecklistTasksAdded.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package com.pengrad.telegrambot.model.checklist
22

33
import com.pengrad.telegrambot.model.Message
44

5-
data class ChecklistTasksAdded (
5+
data class ChecklistTasksAdded(
66
@get:JvmName("checklistMessage") val checklistMessage: Message?,
77
@get:JvmName("tasks") val tasks: Array<ChecklistTask>?
8-
){
8+
) {
99

1010
override fun equals(other: Any?): Boolean {
1111
if (this === other) return true
@@ -17,7 +17,7 @@ data class ChecklistTasksAdded (
1717

1818
override fun hashCode(): Int {
1919
var result = checklistMessage.hashCode()
20-
result = 31 * result + (tasks?.hashCode() ?: 0)
20+
result = 31 * result + (tasks.contentHashCode())
2121
return result
2222
}
2323

library/src/main/java/com/pengrad/telegrambot/model/checklist/ChecklistTasksDone.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ data class ChecklistTasksDone (
2121

2222
override fun hashCode(): Int {
2323
var result = checklistMessage.hashCode()
24-
result = 31 * result + (markedAsDoneTaskIds?.hashCode() ?: 0)
25-
result = 31 * result + (markedAsNotDoneTaskIds?.hashCode() ?: 0)
24+
result = 31 * result + (markedAsDoneTaskIds.contentHashCode())
25+
result = 31 * result + (markedAsNotDoneTaskIds.contentHashCode())
2626
return result
2727
}
2828

library/src/main/java/com/pengrad/telegrambot/model/checklist/InputChecklist.kt

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.pengrad.telegrambot.model.checklist
22

33
import com.pengrad.telegrambot.model.MessageEntity
44

5-
@Suppress("unused")
65
class InputChecklist private constructor(
76
@get:JvmName("title") val title: String,
87
@get:JvmName("parseMode") var parseMode: String?,
@@ -37,4 +36,38 @@ class InputChecklist private constructor(
3736
this.othersCanMarkTasksAsDone = othersCanMarkTasksAsDone
3837
}
3938

39+
override fun toString(): String {
40+
return "InputChecklist(title='$title', parseMode=$parseMode, titleEntities=${titleEntities?.contentToString()}, tasks=${tasks.contentToString()}, othersCanAddTasks=$othersCanAddTasks, othersCanMarkTasksAsDone=$othersCanMarkTasksAsDone)"
41+
}
42+
43+
override fun equals(other: Any?): Boolean {
44+
if (this === other) return true
45+
if (javaClass != other?.javaClass) return false
46+
47+
other as InputChecklist
48+
49+
if (title != other.title) return false
50+
if (parseMode != other.parseMode) return false
51+
if (titleEntities != null) {
52+
if (other.titleEntities == null) return false
53+
if (!titleEntities.contentEquals(other.titleEntities)) return false
54+
} else if (other.titleEntities != null) return false
55+
if (!tasks.contentEquals(other.tasks)) return false
56+
if (othersCanAddTasks != other.othersCanAddTasks) return false
57+
if (othersCanMarkTasksAsDone != other.othersCanMarkTasksAsDone) return false
58+
59+
return true
60+
}
61+
62+
override fun hashCode(): Int {
63+
var result = title.hashCode()
64+
result = 31 * result + (parseMode?.hashCode() ?: 0)
65+
result = 31 * result + (titleEntities?.contentHashCode() ?: 0)
66+
result = 31 * result + tasks.contentHashCode()
67+
result = 31 * result + (othersCanAddTasks?.hashCode() ?: 0)
68+
result = 31 * result + (othersCanMarkTasksAsDone?.hashCode() ?: 0)
69+
return result
70+
}
71+
72+
4073
}

library/src/main/java/com/pengrad/telegrambot/model/checklist/InputChecklistTask.kt

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ package com.pengrad.telegrambot.model.checklist
22

33
import com.pengrad.telegrambot.model.MessageEntity
44

5-
@Suppress("unused")
6-
class InputChecklistTask private constructor (
5+
class InputChecklistTask private constructor(
76
@get:JvmName("id") val id: Int,
87
@get:JvmName("text") val text: String,
98
@get:JvmName("parseMode") var parseMode: String?,
109
@get:JvmName("textEntities") var textEntities: Array<MessageEntity>?
11-
){
10+
) {
1211

1312
constructor(id: Int, text: String) : this(
1413
id = id,
@@ -25,4 +24,36 @@ class InputChecklistTask private constructor (
2524
this.textEntities = textEntities
2625
}
2726

27+
28+
29+
override fun toString(): String {
30+
return "InputChecklistTask(id=$id, text='$text', parseMode=$parseMode, textEntities=${textEntities?.contentToString()})"
31+
}
32+
33+
override fun equals(other: Any?): Boolean {
34+
if (this === other) return true
35+
if (javaClass != other?.javaClass) return false
36+
37+
other as InputChecklistTask
38+
39+
if (id != other.id) return false
40+
if (text != other.text) return false
41+
if (parseMode != other.parseMode) return false
42+
if (textEntities != null) {
43+
if (other.textEntities == null) return false
44+
if (!textEntities.contentEquals(other.textEntities)) return false
45+
} else if (other.textEntities != null) return false
46+
47+
return true
48+
}
49+
50+
override fun hashCode(): Int {
51+
var result = id
52+
result = 31 * result + text.hashCode()
53+
result = 31 * result + (parseMode?.hashCode() ?: 0)
54+
result = 31 * result + (textEntities?.contentHashCode() ?: 0)
55+
return result
56+
}
57+
58+
2859
}

library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGift.kt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,23 @@ package com.pengrad.telegrambot.model.gift.owned
22

33
open class OwnedGift(
44
@get:JvmName("type") val type: String
5-
)
5+
) {
6+
override fun toString(): String {
7+
return "OwnedGift(type='$type')"
8+
}
9+
10+
override fun equals(other: Any?): Boolean {
11+
if (this === other) return true
12+
if (javaClass != other?.javaClass) return false
13+
14+
other as OwnedGift
15+
16+
return type == other.type
17+
}
18+
19+
override fun hashCode(): Int {
20+
return type.hashCode()
21+
}
22+
23+
24+
}

library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import com.pengrad.telegrambot.model.MessageEntity
44
import com.pengrad.telegrambot.model.User
55
import com.pengrad.telegrambot.model.gift.Gift
66

7-
@Suppress("unused")
87
class OwnedGiftRegular private constructor(
98
@get:JvmName("gift") val gift: Gift,
109
@get:JvmName("ownedGiftId") var ownedGiftId: String?,
@@ -91,4 +90,56 @@ class OwnedGiftRegular private constructor(
9190
this.uniqueGiftNumber = uniqueGiftNumber
9291
}
9392

93+
override fun toString(): String {
94+
return "OwnedGiftRegular(gift=$gift, ownedGiftId=$ownedGiftId, senderUser=$senderUser, sendDate=$sendDate, text=$text, entities=${entities?.contentToString()}, isPrivate=$isPrivate, isSaved=$isSaved, canBeUpgraded=$canBeUpgraded, wasRefunded=$wasRefunded, convertStarCount=$convertStarCount, prepaidUpgradeStarCount=$prepaidUpgradeStarCount, isUpgradeSeparate=$isUpgradeSeparate, uniqueGiftNumber=$uniqueGiftNumber)"
95+
}
96+
97+
override fun equals(other: Any?): Boolean {
98+
if (this === other) return true
99+
if (javaClass != other?.javaClass) return false
100+
if (!super.equals(other)) return false
101+
102+
other as OwnedGiftRegular
103+
104+
if (gift != other.gift) return false
105+
if (ownedGiftId != other.ownedGiftId) return false
106+
if (senderUser != other.senderUser) return false
107+
if (sendDate != other.sendDate) return false
108+
if (text != other.text) return false
109+
if (entities != null) {
110+
if (other.entities == null) return false
111+
if (!entities.contentEquals(other.entities)) return false
112+
} else if (other.entities != null) return false
113+
if (isPrivate != other.isPrivate) return false
114+
if (isSaved != other.isSaved) return false
115+
if (canBeUpgraded != other.canBeUpgraded) return false
116+
if (wasRefunded != other.wasRefunded) return false
117+
if (convertStarCount != other.convertStarCount) return false
118+
if (prepaidUpgradeStarCount != other.prepaidUpgradeStarCount) return false
119+
if (isUpgradeSeparate != other.isUpgradeSeparate) return false
120+
if (uniqueGiftNumber != other.uniqueGiftNumber) return false
121+
122+
return true
123+
}
124+
125+
override fun hashCode(): Int {
126+
var result = super.hashCode()
127+
result = 31 * result + gift.hashCode()
128+
result = 31 * result + (ownedGiftId?.hashCode() ?: 0)
129+
result = 31 * result + (senderUser?.hashCode() ?: 0)
130+
result = 31 * result + sendDate.hashCode()
131+
result = 31 * result + (text?.hashCode() ?: 0)
132+
result = 31 * result + (entities?.contentHashCode() ?: 0)
133+
result = 31 * result + (isPrivate?.hashCode() ?: 0)
134+
result = 31 * result + (isSaved?.hashCode() ?: 0)
135+
result = 31 * result + (canBeUpgraded?.hashCode() ?: 0)
136+
result = 31 * result + (wasRefunded?.hashCode() ?: 0)
137+
result = 31 * result + (convertStarCount ?: 0)
138+
result = 31 * result + (prepaidUpgradeStarCount ?: 0)
139+
result = 31 * result + (isUpgradeSeparate?.hashCode() ?: 0)
140+
result = 31 * result + (uniqueGiftNumber ?: 0)
141+
return result
142+
}
143+
144+
94145
}

library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftUnique.kt

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ package com.pengrad.telegrambot.model.gift.owned
33
import com.pengrad.telegrambot.model.User
44
import com.pengrad.telegrambot.model.gift.Gift
55

6-
@Suppress("unused")
76
class OwnedGiftUnique(
8-
@get:JvmName("gift") val gift: Gift,
7+
@get:JvmName("gift") val gift: Gift,
98
@get:JvmName("ownedGiftId") var ownedGiftId: String?,
109
@get:JvmName("senderUser") var senderUser: User?,
1110
@get:JvmName("sendDate") var sendDate: Long,
@@ -19,4 +18,41 @@ class OwnedGiftUnique(
1918
const val TYPE = "unique"
2019
}
2120

21+
override fun toString(): String {
22+
return "OwnedGiftUnique(gift=$gift, ownedGiftId=$ownedGiftId, senderUser=$senderUser, sendDate=$sendDate, isSaved=$isSaved, canBeTransferred=$canBeTransferred, prepaidUpgradeStarCount=$prepaidUpgradeStarCount, nextTransferDate=$nextTransferDate)"
23+
}
24+
25+
override fun equals(other: Any?): Boolean {
26+
if (this === other) return true
27+
if (javaClass != other?.javaClass) return false
28+
if (!super.equals(other)) return false
29+
30+
other as OwnedGiftUnique
31+
32+
if (gift != other.gift) return false
33+
if (ownedGiftId != other.ownedGiftId) return false
34+
if (senderUser != other.senderUser) return false
35+
if (sendDate != other.sendDate) return false
36+
if (isSaved != other.isSaved) return false
37+
if (canBeTransferred != other.canBeTransferred) return false
38+
if (prepaidUpgradeStarCount != other.prepaidUpgradeStarCount) return false
39+
if (nextTransferDate != other.nextTransferDate) return false
40+
41+
return true
42+
}
43+
44+
override fun hashCode(): Int {
45+
var result = super.hashCode()
46+
result = 31 * result + gift.hashCode()
47+
result = 31 * result + (ownedGiftId?.hashCode() ?: 0)
48+
result = 31 * result + (senderUser?.hashCode() ?: 0)
49+
result = 31 * result + sendDate.hashCode()
50+
result = 31 * result + (isSaved?.hashCode() ?: 0)
51+
result = 31 * result + (canBeTransferred?.hashCode() ?: 0)
52+
result = 31 * result + (prepaidUpgradeStarCount ?: 0)
53+
result = 31 * result + (nextTransferDate?.hashCode() ?: 0)
54+
return result
55+
}
56+
57+
2258
}

0 commit comments

Comments
 (0)