Remove guava dep from main modules (#1173)

* Remove Guava Dep

* Update pom.xml

* Update ExponentialBackOff.java

* Update ExponentialBackOff.java

* Update WebhookUtils.java

* Update pom.xml
This commit is contained in:
Ruben Bermudez 2023-01-04 02:35:02 +01:00 committed by GitHub
parent d1c70210f1
commit 4c36c432f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 66 additions and 47 deletions

View File

@ -76,6 +76,7 @@
<jakarta.annotation.version>2.1.1</jakarta.annotation.version>
<lombok.version>1.18.24</lombok.version>
<guava.version>31.1-jre</guava.version>
<commons.version>3.12.0</commons.version>
</properties>
<dependencyManagement>
@ -134,6 +135,12 @@
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons.version}</version>
</dependency>
<!-- Included to enforce common version-->
<dependency>
<groupId>jakarta.annotation</groupId>

View File

@ -90,6 +90,10 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commonslang.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.mapdb</groupId>

View File

@ -87,15 +87,14 @@
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>

View File

@ -1,6 +1,6 @@
package org.telegram.telegrambots.meta;
import com.google.common.base.Strings;
import org.apache.commons.lang3.StringUtils;
import org.telegram.telegrambots.meta.api.methods.updates.SetWebhook;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.generics.BotSession;
@ -106,7 +106,7 @@ public class TelegramBotsApi {
* @return False if username or token are empty or null, true otherwise
*/
private boolean validateBotUsernameAndToken(TelegramBot telegramBot) {
return !Strings.isNullOrEmpty(telegramBot.getBotToken()) &&
!Strings.isNullOrEmpty(telegramBot.getBotUsername());
return StringUtils.isNotEmpty(telegramBot.getBotToken()) &&
StringUtils.isNotEmpty(telegramBot.getBotUsername());
}
}

View File

@ -1,7 +1,6 @@
package org.telegram.telegrambots.meta.api.methods.groupadministration;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Strings;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
@ -12,6 +11,7 @@ import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Tolerate;
import org.apache.commons.lang3.StringUtils;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ChatInviteLink;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
@ -88,10 +88,10 @@ public class EditChatInviteLink extends BotApiMethod<ChatInviteLink> {
@Override
public void validate() throws TelegramApiValidationException {
if (Strings.isNullOrEmpty(chatId)) {
if (StringUtils.isEmpty(chatId)) {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
if (Strings.isNullOrEmpty(inviteLink)) {
if (StringUtils.isEmpty(inviteLink)) {
throw new TelegramApiValidationException("InviteLink can't be empty", this);
}
if (name != null && name.length() > 32) {

View File

@ -1,7 +1,6 @@
package org.telegram.telegrambots.meta.api.methods.groupadministration;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Strings;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
@ -11,6 +10,7 @@ import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Tolerate;
import org.apache.commons.lang3.StringUtils;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ChatInviteLink;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
@ -65,10 +65,10 @@ public class RevokeChatInviteLink extends BotApiMethod<ChatInviteLink> {
@Override
public void validate() throws TelegramApiValidationException {
if (Strings.isNullOrEmpty(chatId)) {
if (StringUtils.isEmpty(chatId)) {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
if (Strings.isNullOrEmpty(inviteLink)) {
if (StringUtils.isEmpty(inviteLink)) {
throw new TelegramApiValidationException("InviteLink can't be empty", this);
}
}

View File

@ -1,7 +1,6 @@
package org.telegram.telegrambots.meta.api.methods.invoices;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Strings;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
@ -12,6 +11,7 @@ import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.Singular;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.payments.LabeledPrice;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
@ -134,19 +134,19 @@ public class CreateInvoiceLink extends BotApiMethod<String> {
@Override
public void validate() throws TelegramApiValidationException {
if (Strings.isNullOrEmpty(title) || title.length() > 32) {
if (StringUtils.isEmpty(title) || title.length() > 32) {
throw new TelegramApiValidationException("Title parameter can't be empty or longer than 32 chars", this);
}
if (Strings.isNullOrEmpty(description) || description.length() > 255) {
if (StringUtils.isEmpty(description) || description.length() > 255) {
throw new TelegramApiValidationException("Description parameter can't be empty or longer than 255 chars", this);
}
if (Strings.isNullOrEmpty(payload)) {
if (StringUtils.isEmpty(payload)) {
throw new TelegramApiValidationException("Payload parameter can't be empty", this);
}
if (Strings.isNullOrEmpty(providerToken)) {
if (StringUtils.isEmpty(providerToken)) {
throw new TelegramApiValidationException("ProviderToken parameter can't be empty", this);
}
if (Strings.isNullOrEmpty(currency)) {
if (StringUtils.isEmpty(currency)) {
throw new TelegramApiValidationException("Currency parameter can't be empty", this);
}
if (prices.isEmpty()) {

View File

@ -1,7 +1,6 @@
package org.telegram.telegrambots.meta.api.methods.invoices;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Strings;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
@ -13,6 +12,7 @@ import lombok.Setter;
import lombok.Singular;
import lombok.ToString;
import lombok.experimental.Tolerate;
import org.apache.commons.lang3.StringUtils;
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage;
import org.telegram.telegrambots.meta.api.objects.payments.LabeledPrice;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
@ -180,22 +180,22 @@ public class SendInvoice extends BotApiMethodMessage {
@Override
public void validate() throws TelegramApiValidationException {
if (Strings.isNullOrEmpty(chatId)) {
if (StringUtils.isEmpty(chatId)) {
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
}
if (Strings.isNullOrEmpty(title) || title.length() > 32) {
if (StringUtils.isEmpty(title) || title.length() > 32) {
throw new TelegramApiValidationException("Title parameter can't be empty or longer than 32 chars", this);
}
if (Strings.isNullOrEmpty(description) || description.length() > 255) {
if (StringUtils.isEmpty(description) || description.length() > 255) {
throw new TelegramApiValidationException("Description parameter can't be empty or longer than 255 chars", this);
}
if (Strings.isNullOrEmpty(payload)) {
if (StringUtils.isEmpty(payload)) {
throw new TelegramApiValidationException("Payload parameter can't be empty", this);
}
if (Strings.isNullOrEmpty(providerToken)) {
if (StringUtils.isEmpty(providerToken)) {
throw new TelegramApiValidationException("ProviderToken parameter can't be empty", this);
}
if (Strings.isNullOrEmpty(currency)) {
if (StringUtils.isEmpty(currency)) {
throw new TelegramApiValidationException("Currency parameter can't be empty", this);
}
if (prices.isEmpty()) {

View File

@ -1,7 +1,6 @@
package org.telegram.telegrambots.meta.api.methods.send;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Strings;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
@ -13,6 +12,7 @@ import lombok.Setter;
import lombok.Singular;
import lombok.ToString;
import lombok.experimental.Tolerate;
import org.apache.commons.lang3.StringUtils;
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage;
import org.telegram.telegrambots.meta.api.objects.payments.LabeledPrice;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
@ -176,22 +176,22 @@ public class SendInvoice extends BotApiMethodMessage {
@Override
public void validate() throws TelegramApiValidationException {
if (Strings.isNullOrEmpty(chatId)) {
if (StringUtils.isEmpty(chatId)) {
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
}
if (Strings.isNullOrEmpty(title)) {
if (StringUtils.isEmpty(title)) {
throw new TelegramApiValidationException("Title parameter can't be empty", this);
}
if (Strings.isNullOrEmpty(description)) {
if (StringUtils.isEmpty(description)) {
throw new TelegramApiValidationException("Description parameter can't be empty", this);
}
if (Strings.isNullOrEmpty(payload)) {
if (StringUtils.isEmpty(payload)) {
throw new TelegramApiValidationException("Payload parameter can't be empty", this);
}
if (Strings.isNullOrEmpty(providerToken)) {
if (StringUtils.isEmpty(providerToken)) {
throw new TelegramApiValidationException("ProviderToken parameter can't be empty", this);
}
if (Strings.isNullOrEmpty(currency)) {
if (StringUtils.isEmpty(currency)) {
throw new TelegramApiValidationException("Currency parameter can't be empty", this);
}
if (prices.isEmpty()) {

View File

@ -2,7 +2,6 @@ package org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessageconte
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.base.Strings;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
@ -13,6 +12,7 @@ import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.Singular;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
import org.telegram.telegrambots.meta.api.objects.payments.LabeledPrice;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
@ -189,19 +189,19 @@ public class InputInvoiceMessageContent implements InputMessageContent {
@Override
public void validate() throws TelegramApiValidationException {
if (Strings.isNullOrEmpty(title) || title.length() > 32) {
if (StringUtils.isEmpty(title) || title.length() > 32) {
throw new TelegramApiValidationException("Title parameter must be between 1 and 32 characters", this);
}
if (Strings.isNullOrEmpty(description) || description.length() > 32) {
if (StringUtils.isEmpty(description) || description.length() > 32) {
throw new TelegramApiValidationException("Description parameter must be between 1 and 255 characters", this);
}
if (Strings.isNullOrEmpty(payload) || payload.length() > 32) {
if (StringUtils.isEmpty(payload) || payload.length() > 32) {
throw new TelegramApiValidationException("Payload parameter must be between 1 and 128 characters", this);
}
if (Strings.isNullOrEmpty(providerToken)) {
if (StringUtils.isEmpty(providerToken)) {
throw new TelegramApiValidationException("ProviderToken parameter must not be empty", this);
}
if (Strings.isNullOrEmpty(currency)) {
if (StringUtils.isEmpty(currency)) {
throw new TelegramApiValidationException("Currency parameter must not be empty", this);
}
if (prices == null || prices.isEmpty()) {

View File

@ -13,7 +13,6 @@
*/
package org.telegram.telegrambots.updatesreceivers;
import com.google.common.base.Preconditions;
import org.telegram.telegrambots.meta.generics.BackOff;
/**
@ -153,11 +152,21 @@ public class ExponentialBackOff implements BackOff {
multiplier = builder.multiplier;
maxIntervalMillis = builder.maxIntervalMillis;
maxElapsedTimeMillis = builder.maxElapsedTimeMillis;
Preconditions.checkArgument(initialIntervalMillis > 0);
Preconditions.checkArgument(0 <= randomizationFactor && randomizationFactor < 1);
Preconditions.checkArgument(multiplier >= 1);
Preconditions.checkArgument(maxIntervalMillis >= initialIntervalMillis);
Preconditions.checkArgument(maxElapsedTimeMillis > 0);
if (initialIntervalMillis <= 0) {
throw new IllegalArgumentException("InitialIntervalMillis must not be negative");
}
if (maxElapsedTimeMillis <= 0) {
throw new IllegalArgumentException("MaxElapsedTimeMillis must not be negative");
}
if (multiplier < 1) {
throw new IllegalArgumentException("Multiplier must be bigger than 0");
}
if (maxIntervalMillis < initialIntervalMillis) {
throw new IllegalArgumentException("InitialIntervalMillis must be smaller or equal maxIntervalMillis");
}
if (randomizationFactor < 0 || randomizationFactor >= 1) {
throw new IllegalArgumentException("RandomizationFactor must be between 0 and 1");
}
reset();
}

View File

@ -2,7 +2,7 @@ package org.telegram.telegrambots.util;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
@ -124,7 +124,7 @@ public final class WebhookUtils {
externalUrl += "/";
}
externalUrl += Constants.WEBHOOK_URL_PATH;
if (!Strings.isNullOrEmpty(botPath)) {
if (StringUtils.isNotEmpty(botPath)) {
if (!botPath.startsWith("/")) {
externalUrl += "/";
}