#325 Implement equals() and hashCode() in reply keyboards

This commit is contained in:
Niels Ulrik Andersen 2017-11-20 13:29:17 +01:00
parent 4121a6f8c9
commit 19b0582322
6 changed files with 136 additions and 0 deletions

View File

@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
import java.util.Objects;
/** /**
* @author Ruben Bermudez * @author Ruben Bermudez
* @version 1.0 * @version 1.0
@ -56,6 +58,25 @@ public class ForceReplyKeyboard implements ReplyKeyboard {
} }
} }
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof ForceReplyKeyboard)) {
return false;
}
ForceReplyKeyboard forceReplyKeyboard = (ForceReplyKeyboard) o;
return Objects.equals(forceReply, forceReplyKeyboard.forceReply)
&& Objects.equals(selective, forceReplyKeyboard.selective)
;
}
@Override
public int hashCode() {
return Objects.hash(
forceReply,
selective);
}
@Override @Override
public String toString() { public String toString() {
return "ForceReplyKeyboard{" + return "ForceReplyKeyboard{" +

View File

@ -7,6 +7,7 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
/** /**
* @author Ruben Bermudez * @author Ruben Bermudez
@ -50,6 +51,21 @@ public class InlineKeyboardMarkup implements ReplyKeyboard {
} }
} }
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof InlineKeyboardMarkup)) {
return false;
}
InlineKeyboardMarkup inlineKeyboardMarkup = (InlineKeyboardMarkup) o;
return Objects.equals(keyboard, inlineKeyboardMarkup.keyboard);
}
@Override
public int hashCode() {
return Objects.hash(keyboard);
}
@Override @Override
public String toString() { public String toString() {
return "InlineKeyboardMarkup{" + return "InlineKeyboardMarkup{" +

View File

@ -7,6 +7,7 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
/** /**
* @author Ruben Bermudez * @author Ruben Bermudez
@ -87,6 +88,29 @@ public class ReplyKeyboardMarkup implements ReplyKeyboard {
} }
} }
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof ReplyKeyboardMarkup)) {
return false;
}
ReplyKeyboardMarkup replyKeyboardMarkup = (ReplyKeyboardMarkup) o;
return Objects.equals(keyboard, replyKeyboardMarkup.keyboard)
&& Objects.equals(oneTimeKeyboard, replyKeyboardMarkup.oneTimeKeyboard)
&& Objects.equals(resizeKeyboard, replyKeyboardMarkup.resizeKeyboard)
&& Objects.equals(selective, replyKeyboardMarkup.selective)
;
}
@Override
public int hashCode() {
return Objects.hash(
keyboard,
oneTimeKeyboard,
resizeKeyboard,
selective);
}
@Override @Override
public String toString() { public String toString() {
return "ReplyKeyboardMarkup{" + return "ReplyKeyboardMarkup{" +

View File

@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
import java.util.Objects;
/** /**
* @author Ruben Bermudez * @author Ruben Bermudez
* @version 1.0 * @version 1.0
@ -52,6 +54,25 @@ public class ReplyKeyboardRemove implements ReplyKeyboard {
} }
} }
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof ReplyKeyboardRemove)) {
return false;
}
ReplyKeyboardRemove replyKeyboardRemove = (ReplyKeyboardRemove) o;
return Objects.equals(removeKeyboard, replyKeyboardRemove.removeKeyboard)
&& Objects.equals(selective, replyKeyboardRemove.selective)
;
}
@Override
public int hashCode() {
return Objects.hash(
removeKeyboard,
selective);
}
@Override @Override
public String toString() { public String toString() {
return "ReplyKeyboardRemove{" + return "ReplyKeyboardRemove{" +

View File

@ -6,6 +6,8 @@ import org.telegram.telegrambots.api.interfaces.Validable;
import org.telegram.telegrambots.api.objects.games.CallbackGame; import org.telegram.telegrambots.api.objects.games.CallbackGame;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
/** /**
@ -146,6 +148,35 @@ public class InlineKeyboardButton implements InputBotApiObject, Validable {
} }
} }
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof InlineKeyboardButton)) {
return false;
}
InlineKeyboardButton inlineKeyboardButton = (InlineKeyboardButton) o;
return Objects.equals(callbackData, inlineKeyboardButton.callbackData)
&& Objects.equals(callbackGame, inlineKeyboardButton.callbackGame)
&& Objects.equals(pay, inlineKeyboardButton.pay)
&& Objects.equals(switchInlineQuery, inlineKeyboardButton.switchInlineQuery)
&& Objects.equals(switchInlineQueryCurrentChat, inlineKeyboardButton.switchInlineQueryCurrentChat)
&& Objects.equals(text, inlineKeyboardButton.text)
&& Objects.equals(url, inlineKeyboardButton.url)
;
}
@Override
public int hashCode() {
return Objects.hash(
callbackData,
callbackGame,
pay,
switchInlineQuery,
switchInlineQueryCurrentChat,
text,
url);
}
@Override @Override
public String toString() { public String toString() {
return "InlineKeyboardButton{" + return "InlineKeyboardButton{" +

View File

@ -6,6 +6,8 @@ import org.telegram.telegrambots.api.interfaces.InputBotApiObject;
import org.telegram.telegrambots.api.interfaces.Validable; import org.telegram.telegrambots.api.interfaces.Validable;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
import java.util.Objects;
/** /**
* @author Ruben Bermudez * @author Ruben Bermudez
* @version 1.0 * @version 1.0
@ -88,6 +90,27 @@ public class KeyboardButton implements InputBotApiObject, Validable {
} }
} }
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof KeyboardButton)) {
return false;
}
KeyboardButton keyboardButton = (KeyboardButton) o;
return Objects.equals(requestContact, keyboardButton.requestContact)
&& Objects.equals(requestLocation, keyboardButton.requestLocation)
&& Objects.equals(text, keyboardButton.text)
;
}
@Override
public int hashCode() {
return Objects.hash(
requestContact,
requestLocation,
text);
}
@Override @Override
public String toString() { public String toString() {
return "KeyboardButton{" + return "KeyboardButton{" +