Skip to content

Commit 4b80202

Browse files
committed
Update Stickers equals()
1 parent 1a7bc45 commit 4b80202

File tree

2 files changed

+23
-30
lines changed

2 files changed

+23
-30
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.pengrad.telegrambot.model;
22

33
import java.io.Serializable;
4+
import java.util.Objects;
45

56
/**
67
* stas
@@ -69,20 +70,18 @@ public Integer fileSize() {
6970
public boolean equals(Object o) {
7071
if (this == o) return true;
7172
if (o == null || getClass() != o.getClass()) return false;
72-
7373
Sticker sticker = (Sticker) o;
74-
75-
if (file_id != null ? !file_id.equals(sticker.file_id) : sticker.file_id != null) return false;
76-
if (file_unique_id != null ? !file_unique_id.equals(sticker.file_unique_id) : sticker.file_unique_id != null)
77-
return false;
78-
if (width != null ? !width.equals(sticker.width) : sticker.width != null) return false;
79-
if (height != null ? !height.equals(sticker.height) : sticker.height != null) return false;
80-
if (is_animated != null ? !is_animated.equals(sticker.is_animated) : sticker.is_animated != null) return false;
81-
if (thumb != null ? !thumb.equals(sticker.thumb) : sticker.thumb != null) return false;
82-
if (emoji != null ? !emoji.equals(sticker.emoji) : sticker.emoji != null) return false;
83-
if (set_name != null ? !set_name.equals(sticker.set_name) : sticker.set_name != null) return false;
84-
if (mask_position != null ? !mask_position.equals(sticker.mask_position) : sticker.mask_position != null) return false;
85-
return file_size != null ? file_size.equals(sticker.file_size) : sticker.file_size == null;
74+
return Objects.equals(file_id, sticker.file_id) &&
75+
Objects.equals(file_unique_id, sticker.file_unique_id) &&
76+
Objects.equals(width, sticker.width) &&
77+
Objects.equals(height, sticker.height) &&
78+
Objects.equals(is_animated, sticker.is_animated) &&
79+
Objects.equals(is_video, sticker.is_video) &&
80+
Objects.equals(thumb, sticker.thumb) &&
81+
Objects.equals(emoji, sticker.emoji) &&
82+
Objects.equals(set_name, sticker.set_name) &&
83+
Objects.equals(mask_position, sticker.mask_position) &&
84+
Objects.equals(file_size, sticker.file_size);
8685
}
8786

8887
@Override
@@ -98,6 +97,7 @@ public String toString() {
9897
", width=" + width +
9998
", height=" + height +
10099
", is_animated=" + is_animated +
100+
", is_video=" + is_video +
101101
", thumb=" + thumb +
102102
", emoji='" + emoji + '\'' +
103103
", set_name='" + set_name + '\'' +

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

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.Serializable;
44
import java.util.Arrays;
5+
import java.util.Objects;
56

67
/**
78
* Stas Parshin
@@ -50,29 +51,20 @@ public Boolean isVideo() {
5051
public boolean equals(Object o) {
5152
if (this == o) return true;
5253
if (o == null || getClass() != o.getClass()) return false;
53-
5454
StickerSet that = (StickerSet) o;
55-
56-
if (name != null ? !name.equals(that.name) : that.name != null) return false;
57-
if (title != null ? !title.equals(that.title) : that.title != null) return false;
58-
if (is_animated != null ? !is_animated.equals(that.is_animated) : that.is_animated != null) return false;
59-
if (contains_masks != null ? !contains_masks.equals(that.contains_masks) : that.contains_masks != null)
60-
return false;
61-
// Probably incorrect - comparing Object[] arrays with Arrays.equals
62-
if (!Arrays.equals(stickers, that.stickers)) return false;
63-
if (thumb != null ? !thumb.equals(that.thumb) : that.thumb != null) return false;
64-
65-
return true;
55+
return Objects.equals(name, that.name) &&
56+
Objects.equals(title, that.title) &&
57+
Objects.equals(is_animated, that.is_animated) &&
58+
Objects.equals(is_video, that.is_video) &&
59+
Objects.equals(contains_masks, that.contains_masks) &&
60+
Arrays.equals(stickers, that.stickers) &&
61+
Objects.equals(thumb, that.thumb);
6662
}
6763

6864
@Override
6965
public int hashCode() {
70-
int result = name != null ? name.hashCode() : 0;
71-
result = 31 * result + (title != null ? title.hashCode() : 0);
72-
result = 31 * result + (is_animated != null ? is_animated.hashCode() : 0);
73-
result = 31 * result + (contains_masks != null ? contains_masks.hashCode() : 0);
66+
int result = Objects.hash(name, title, is_animated, is_video, contains_masks, thumb);
7467
result = 31 * result + Arrays.hashCode(stickers);
75-
result = 31 * result + (thumb != null ? thumb.hashCode() : 0);
7668
return result;
7769
}
7870

@@ -82,6 +74,7 @@ public String toString() {
8274
"name='" + name + '\'' +
8375
", title='" + title + '\'' +
8476
", is_animated=" + is_animated +
77+
", is_video=" + is_video +
8578
", contains_masks=" + contains_masks +
8679
", stickers=" + Arrays.toString(stickers) +
8780
", thumb=" + thumb +

0 commit comments

Comments
 (0)