some refactoring

This commit is contained in:
hdvtdev
2025-04-24 23:14:43 +03:00
parent 97e93f7feb
commit 66d2172f51
3 changed files with 26 additions and 82 deletions

View File

@@ -21,12 +21,22 @@ public interface TelegramBot {
void shutdown();
default CompletableFuture<File> downloadFile(TelegramFile telegramFile, Path targetDirectory) throws TelegramApiException, TelegramApiNetworkException {
return CompletableFuture.supplyAsync(() -> awaitDownloadFile(telegramFile, targetDirectory));
default CompletableFuture<File> downloadFile(TelegramFile telegramFile, Path targetDirectory) {
CompletableFuture<File> completableFuture = CompletableFuture.supplyAsync(() -> awaitDownloadFile(telegramFile, targetDirectory));
completableFuture.exceptionally(e -> {
e.printStackTrace();
return null;
});
return completableFuture;
}
default <T> CompletableFuture<T> execute(TelegramApiMethod<T> telegramApiMethod) throws TelegramApiException, TelegramApiNetworkException, TelegramMethodParsingException {
return CompletableFuture.supplyAsync(() -> awaitExecute(telegramApiMethod));
default <T> CompletableFuture<T> execute(TelegramApiMethod<T> telegramApiMethod) {
CompletableFuture<T> completableFuture = CompletableFuture.supplyAsync(() -> awaitExecute(telegramApiMethod));
completableFuture.exceptionally(e -> {
e.printStackTrace();
return null;
});
return completableFuture;
}
default int getPing() throws TelegramApiNetworkException {

View File

@@ -19,8 +19,12 @@ public final class TelegramApiMethodBody {
if (value != null) this.elements.add(new Element(name, value));
}
public void forEach(Consumer<? super Element> action) {
this.elements.forEach(action);
public int size() {
return this.elements.size();
}
public Element get(int i) {
return this.elements.get(i);
}
public record Element(String name, String value) {