Some refactoring in pandalib-util

This commit is contained in:
Marc Baloup 2023-08-27 13:37:17 +02:00
parent 463a4d7e78
commit bd3bea8381
59 changed files with 176 additions and 182 deletions

View File

@ -7,7 +7,7 @@ import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.tree.LiteralCommandNode;
import fr.pandacube.lib.commands.BrigadierCommand;
import fr.pandacube.lib.commands.SuggestionsSupplier;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;

View File

@ -1,6 +1,6 @@
package fr.pandacube.lib.bungee.util;
import fr.pandacube.lib.util.logs.DailyLogRotateFileHandler;
import fr.pandacube.lib.util.log.DailyLogRotateFileHandler;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.log.ConciseFormatter;

View File

@ -8,7 +8,7 @@ import fr.pandacube.lib.cli.log.CLILogger;
import jline.console.ConsoleReader;
import org.fusesource.jansi.AnsiConsole;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/**
* Class to handle general standard IO operation for a CLI application. It uses Jlines {@link ConsoleReader} for the

View File

@ -2,7 +2,7 @@ package fr.pandacube.lib.cli;
import fr.pandacube.lib.cli.commands.CommandAdmin;
import fr.pandacube.lib.cli.commands.CommandStop;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;

View File

@ -1,7 +1,7 @@
package fr.pandacube.lib.cli.commands;
import fr.pandacube.lib.chat.Chat;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import net.kyori.adventure.audience.MessageType;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;

View File

@ -17,7 +17,7 @@ import fr.pandacube.lib.chat.Chat;
import fr.pandacube.lib.chat.Chat.FormatableChat;
import fr.pandacube.lib.chat.ChatTreeNode;
import fr.pandacube.lib.cli.CLIApplication;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import net.md_5.bungee.api.chat.BaseComponent;
import java.util.ArrayList;

View File

@ -1,9 +1,9 @@
package fr.pandacube.lib.cli.log;
import fr.pandacube.lib.cli.CLI;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import fr.pandacube.lib.util.ThrowableUtil;
import fr.pandacube.lib.util.logs.DailyLogRotateFileHandler;
import fr.pandacube.lib.util.log.DailyLogRotateFileHandler;
import net.md_5.bungee.log.ColouredWriter;
import net.md_5.bungee.log.ConciseFormatter;

View File

@ -10,7 +10,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import com.mojang.brigadier.tree.LiteralCommandNode;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import java.util.Arrays;
import java.util.function.Function;

View File

@ -6,7 +6,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.tree.LiteralCommandNode;
import fr.pandacube.lib.chat.Chat;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import net.kyori.adventure.text.ComponentLike;
import java.util.concurrent.CompletableFuture;

View File

@ -1,7 +1,7 @@
package fr.pandacube.lib.core.backup;
import fr.pandacube.lib.chat.Chat;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import net.md_5.bungee.api.ChatColor;
import java.io.File;

View File

@ -1,6 +1,6 @@
package fr.pandacube.lib.core.backup;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import java.io.File;
import java.time.ZonedDateTime;

View File

@ -3,7 +3,7 @@ package fr.pandacube.lib.core.backup;
import fc.cron.CronExpression;
import fr.pandacube.lib.core.cron.CronScheduler;
import fr.pandacube.lib.util.FileUtils;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import net.md_5.bungee.api.ChatColor;
import java.io.File;

View File

@ -3,7 +3,7 @@ package fr.pandacube.lib.core.backup;
import com.google.gson.JsonParseException;
import com.google.gson.reflect.TypeToken;
import fr.pandacube.lib.core.json.Json;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import java.io.File;
import java.io.FileReader;

View File

@ -1,7 +1,7 @@
package fr.pandacube.lib.core.backup;
import com.google.common.io.Files;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import net.md_5.bungee.api.ChatColor;
import java.io.File;

View File

@ -1,7 +1,7 @@
package fr.pandacube.lib.core.config;
import fr.pandacube.lib.chat.ChatColorUtil;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import java.io.BufferedReader;
import java.io.File;

View File

@ -4,7 +4,7 @@ import com.google.gson.JsonParseException;
import com.google.gson.reflect.TypeToken;
import fc.cron.CronExpression;
import fr.pandacube.lib.core.json.Json;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import java.io.File;
import java.io.FileReader;

View File

@ -10,7 +10,7 @@ import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.internal.bind.TreeTypeAdapter;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import fr.pandacube.lib.util.ThrowableUtil;
import java.lang.reflect.Constructor;

View File

@ -1,7 +1,7 @@
package fr.pandacube.lib.core.mc_version;
import fr.pandacube.lib.core.json.Json;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import fr.pandacube.lib.util.StringUtil;
import org.jetbrains.annotations.NotNull;
@ -156,8 +156,9 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
* @return all the {@link ProtocolVersion} currently known by this class.
*/
public static List<ProtocolVersion> allKnownProtocolVersions() {
return versionList.get().versionsOfProtocol().keySet().stream()
.map(ProtocolVersion::ofProtocol)
return versionList.get().versionsOfProtocol().entrySet().stream()
.filter(e -> e.getValue() != null && !e.getValue().isEmpty())
.map(e -> new ProtocolVersion(e.getKey(), List.copyOf(e.getValue())))
.toList();
}

View File

@ -2,7 +2,7 @@ package fr.pandacube.lib.core.search;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import java.util.ArrayList;
import java.util.HashMap;

View File

@ -15,7 +15,7 @@ import java.util.Objects;
import java.util.function.Consumer;
import fr.pandacube.lib.reflect.Reflect;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/**
* Static class to handle most of the database operations.

View File

@ -26,7 +26,7 @@ import java.util.UUID;
import java.util.stream.Collectors;
import fr.pandacube.lib.util.EnumUtil;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/**
* Represents an entry in a SQL table. Each subclass is for a specific table.

View File

@ -1,6 +1,6 @@
package fr.pandacube.lib.db;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/**
* A foreign key field in a SQL table.

View File

@ -6,7 +6,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/**
* Builder for a SQL {@code UPDATE} query.

View File

@ -4,7 +4,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/**
* A SQL {@code WHERE} expression.

View File

@ -5,7 +5,7 @@ import java.io.PrintStream;
import java.net.InetAddress;
import java.net.Socket;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
public abstract class AbstractRequestExecutor {

View File

@ -1,6 +1,6 @@
package fr.pandacube.lib.netapi.server;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import java.io.IOException;
import java.net.InetAddress;

View File

@ -5,7 +5,7 @@ import java.io.PrintStream;
import java.net.Socket;
import fr.pandacube.lib.netapi.server.RequestAnalyser.BadRequestException;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/**
* Prends en charge un socket client et le transmet au gestionnaire de paquet

View File

@ -23,7 +23,7 @@ import org.bukkit.permissions.ServerOperator;
import org.bukkit.plugin.java.JavaPlugin;
import fr.pandacube.lib.permissions.Permissions;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/**
* Class that integrates the {@code pandalib-permissions} system into a Bukkit/Spigot/Paper instance.

View File

@ -6,7 +6,7 @@ import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import fr.pandacube.lib.permissions.Permissions;
import fr.pandacube.lib.reflect.Reflect;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;

View File

@ -2,7 +2,7 @@ package fr.pandacube.lib.paper.permissions;
import fr.pandacube.lib.permissions.PermGroup;
import fr.pandacube.lib.permissions.Permissions;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;

View File

@ -11,7 +11,7 @@ import org.bukkit.plugin.ServicePriority;
import fr.pandacube.lib.permissions.PermPlayer;
import fr.pandacube.lib.permissions.Permissions;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/* package */ class PermissionsInjectorWEPIF {

View File

@ -2,7 +2,7 @@ package fr.pandacube.lib.paper.backup;
import fr.pandacube.lib.paper.scheduler.SchedulerUtil;
import fr.pandacube.lib.paper.util.WorldUtil;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.World;

View File

@ -31,7 +31,7 @@ import fr.pandacube.lib.players.standalone.AbstractOffPlayer;
import fr.pandacube.lib.players.standalone.AbstractOnlinePlayer;
import fr.pandacube.lib.players.standalone.AbstractPlayerManager;
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.World;

View File

@ -20,7 +20,7 @@ import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import fr.pandacube.lib.paper.util.BukkitEvent;
/**

View File

@ -13,7 +13,7 @@ import fr.pandacube.lib.paper.scheduler.SchedulerUtil;
import fr.pandacube.lib.paper.util.AutoUpdatedBossBar;
import fr.pandacube.lib.paper.util.AutoUpdatedBossBar.BarUpdater;
import fr.pandacube.lib.players.standalone.AbstractPlayerManager;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import fr.pandacube.lib.util.MemoryUtil;
import fr.pandacube.lib.util.MemoryUtil.MemoryUnit;
import fr.pandacube.lib.util.TimeUtil;

View File

@ -1,7 +1,7 @@
package fr.pandacube.lib.paper.players;
import fr.pandacube.lib.paper.PandaLibPaper;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;

View File

@ -19,7 +19,7 @@ import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import fr.pandacube.lib.reflect.Reflect;
import fr.pandacube.lib.reflect.ReflectClass;
import fr.pandacube.lib.reflect.ReflectField;

View File

@ -4,7 +4,7 @@ import fr.pandacube.lib.paper.PandaLibPaper;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.AABB;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.block.BambooStalkBlock;
import fr.pandacube.lib.paper.reflect.wrapper.paper.AABBVoxelShape;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;

View File

@ -15,7 +15,7 @@ import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import fr.pandacube.lib.chat.Chat;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import fr.pandacube.lib.paper.PandaLibPaper;
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.bossbar.BossBar.Color;

View File

@ -12,7 +12,7 @@ import org.bukkit.event.Listener;
import fr.pandacube.lib.util.BiMap;
import fr.pandacube.lib.util.FileUtils;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import fr.pandacube.lib.util.RandomUtil;
public class GameWorldUtils implements Listener {

View File

@ -1,6 +1,6 @@
package fr.pandacube.lib.permissions;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import java.util.UUID;

View File

@ -11,7 +11,7 @@ import fr.pandacube.lib.chat.ChatTreeNode;
import fr.pandacube.lib.permissions.PermissionExpressionParser.LiteralPermissionTester;
import fr.pandacube.lib.permissions.PermissionsCachedBackendReader.CachedEntity;
import fr.pandacube.lib.permissions.SQLPermissions.EntityType;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/**
* Represents an entity in the permission system, either a group or a player.

View File

@ -8,7 +8,7 @@ import java.util.function.Function;
import fr.pandacube.lib.db.DB;
import fr.pandacube.lib.db.DBConnection;
import fr.pandacube.lib.db.DBException;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/**
* Main class for the Pandalib permission system.

View File

@ -19,7 +19,7 @@ import fr.pandacube.lib.db.DB;
import fr.pandacube.lib.db.DBException;
import fr.pandacube.lib.db.SQLElementList;
import fr.pandacube.lib.permissions.SQLPermissions.EntityType;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/* package */ class PermissionsCachedBackendReader
{

View File

@ -23,7 +23,7 @@ import fr.pandacube.lib.permissions.PermissionsCachedBackendReader.CachedEntity;
import fr.pandacube.lib.permissions.PermissionsCachedBackendReader.CachedGroup;
import fr.pandacube.lib.permissions.PermissionsCachedBackendReader.CachedPlayer;
import fr.pandacube.lib.permissions.SQLPermissions.EntityType;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/* package */ class PermissionsResolver {

View File

@ -2,7 +2,7 @@ package fr.pandacube.lib.reflect.wrapper;
import fr.pandacube.lib.reflect.Reflect;
import fr.pandacube.lib.reflect.ReflectConstructor;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import java.lang.reflect.Modifier;
import java.util.HashMap;

View File

@ -4,43 +4,39 @@ import java.util.Objects;
import java.util.function.Supplier;
/**
* Represents a lazy loaded value.
* A Supplier that cache the value the first time it is called.
*
* The value will be computed using the Supplier provided in the
* constructor, only the first time the {@link #get()} method is
* called.
*
* @param <T> the type of the enclosed value.
* @param <T> the type of the supplied value.
*/
public class Lazy<T> implements Supplier<T> {
public class CachedSupplier<T> implements Supplier<T> {
private T cachedValue;
private final Supplier<T> supplier;
private final Supplier<T> source;
private boolean cached = false;
/**
* Create a lazy value loader that will call the provided supplier to get the value.
* @param s the supplier from which the value is fetched.
*/
public Lazy(Supplier<T> s) {
supplier = Objects.requireNonNull(s);
public CachedSupplier(Supplier<T> s) {
source = Objects.requireNonNull(s);
}
/**
* Get the wrapped value, from cache or from the provider if it is not yet cached.
*
* Get the value, from cache or from the source supplier if it's not yet cached.
* <p>
* If the provider throws an exception, it will be redirected to the caller as is, and no value will be cached
* (the next call to this method will execute the supplier again).
*/
@Override
public synchronized T get() {
if (!cached)
set(supplier.get());
set(source.get());
return cachedValue;
}
/**
* Reset the cached value. The next call to {@link #get()} will get the value from the provider.
* Reset the cached value. The next call to {@link #get()} will get the value from the source.
*/
public synchronized void reset() {
cached = false;

View File

@ -1,35 +1,31 @@
package fr.pandacube.lib.util;
import fr.pandacube.lib.util.function.SupplierException;
import java.util.Objects;
import fr.pandacube.lib.util.ThrowableUtil.SupplierException;
/**
* Represents a lazy loaded value.
* <p>
* The value will be computed using the Supplier provided in the
* constructor, only the first time the {@link #get()} method is
* called.
* A Supplier that cache the value the first time it is called.
*
* @param <T> the type of the enclosed value.
* @param <E> the exception type
* @param <T> the type of the supplied value.
* @param <E> the exception type that may be thrown by the source supplier.
*/
public class LazyOrException<T, E extends Exception> implements SupplierException<T, E> {
public class CachedSupplierException<T, E extends Exception> implements SupplierException<T, E> {
private T cachedValue;
private final SupplierException<T, E> supplier;
private final SupplierException<T, E> source;
private boolean cached = false;
/**
* Create a lazy value loader that will call the provided supplier to get the value.
* @param s the supplier from which the value is fetched.
*/
public LazyOrException(SupplierException<T, E> s) {
supplier = Objects.requireNonNull(s);
public CachedSupplierException(SupplierException<T, E> s) {
source = Objects.requireNonNull(s);
}
/**
* Get the wrapped value, from cache or from the provider if it is not yet cached.
* Get the value, from cache or from the provider if it's not yet cached.
* <p>
* If the provider throws an exception, it will be redirected to the caller as is, and no value will be cached
* (the next call to this method will execute the supplier again).
@ -37,12 +33,12 @@ public class LazyOrException<T, E extends Exception> implements SupplierExceptio
@Override
public synchronized T get() throws E {
if (!cached)
set(supplier.get());
set(source.get());
return cachedValue;
}
/**
* Reset the cached value. The next call to {@link #get()} will get the value from the provider.
* Reset the cached value. The next call to {@link #get()} will get the value from the source.
*/
public synchronized void reset() {
cached = false;

View File

@ -1,7 +1,7 @@
package fr.pandacube.lib.util;
import fr.pandacube.lib.util.ThrowableUtil.RunnableException;
import fr.pandacube.lib.util.ThrowableUtil.SupplierException;
import fr.pandacube.lib.util.function.RunnableException;
import fr.pandacube.lib.util.function.SupplierException;
import java.util.function.Supplier;

View File

@ -1,5 +1,8 @@
package fr.pandacube.lib.util;
import fr.pandacube.lib.util.function.RunnableException;
import fr.pandacube.lib.util.function.SupplierException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
@ -145,101 +148,4 @@ public class ThrowableUtil {
}
/**
* A supplier that can possibly throw a checked exception.
*/
@FunctionalInterface
public interface SupplierException<T, E extends Exception> {
/**
* Gets a result.
* @return a result.
* @throws E if implementation failed to run.
*/
T get() throws E;
}
/**
* A runnable that can possibly throw a checked exception.
*/
@FunctionalInterface
public interface RunnableException<E extends Exception> {
/**
* Run any code implemented.
* @throws E if implementation failed to run.
*/
void run() throws E;
}
/**
* A predicate that can possibly throw a checked exception.
*/
@FunctionalInterface
public interface PredicateException<T, E extends Exception> {
/**
* Test the predicate on the specified value.
* @param value the value to test against.
* @return the result of the test.
* @throws E if implementation failed to run.
*/
boolean test(T value) throws E;
}
/**
* A function that can possibly throw a checked exception.
*/
public interface ToIntBiFunctionException<T, U, E extends Exception> {
/**
* Run on the specified parameters to return an int value.
* @param t the first parameter of the function.
* @param u the second parameter of the function.
* @return the result of the function.
* @throws E if the function fails.
*/
int applyAsInt(T t, U u) throws E;
}
/**
* A consumer that can possibly throw a checked exception.
*/
public interface BiConsumerException<T, U, E extends Exception> {
/**
* Run the consumer on the specified parameters.
* @param t the first parameter of the consumer.
* @param u the second parameter of the consumer.
* @throws E if the function fails.
*/
void accept(T t, U u) throws E;
}
/**
* A consumer that can possibly throw a checked exception.
*/
public interface TriConsumerException<T, U, V, E extends Exception> {
/**
* Run the consumer on the specified parameters.
* @param t the first parameter of the consumer.
* @param u the second parameter of the consumer.
* @param v the tird parameter of the consumer.
* @throws E if the function fails.
*/
void accept(T t, U u, V v) throws E;
}
}

View File

@ -0,0 +1,16 @@
package fr.pandacube.lib.util.function;
/**
* A consumer that can possibly throw a checked exception.
*/
@FunctionalInterface
public interface BiConsumerException<T, U, E extends Exception> {
/**
* Run the consumer on the specified parameters.
*
* @param t the first parameter of the consumer.
* @param u the second parameter of the consumer.
* @throws E if the function fails.
*/
void accept(T t, U u) throws E;
}

View File

@ -0,0 +1,16 @@
package fr.pandacube.lib.util.function;
/**
* A predicate that can possibly throw a checked exception.
*/
@FunctionalInterface
public interface PredicateException<T, E extends Exception> {
/**
* Test the predicate on the specified value.
*
* @param value the value to test against.
* @return the result of the test.
* @throws E if implementation failed to run.
*/
boolean test(T value) throws E;
}

View File

@ -0,0 +1,14 @@
package fr.pandacube.lib.util.function;
/**
* A runnable that can possibly throw a checked exception.
*/
@FunctionalInterface
public interface RunnableException<E extends Exception> {
/**
* Run any code implemented.
*
* @throws E if implementation failed to run.
*/
void run() throws E;
}

View File

@ -0,0 +1,15 @@
package fr.pandacube.lib.util.function;
/**
* A supplier that can possibly throw a checked exception.
*/
@FunctionalInterface
public interface SupplierException<T, E extends Exception> {
/**
* Gets a result.
*
* @return a result.
* @throws E if implementation failed to run.
*/
T get() throws E;
}

View File

@ -0,0 +1,17 @@
package fr.pandacube.lib.util.function;
/**
* A function that can possibly throw a checked exception.
*/
@FunctionalInterface
public interface ToIntBiFunctionException<T, U, E extends Exception> {
/**
* Run on the specified parameters to return an int value.
*
* @param t the first parameter of the function.
* @param u the second parameter of the function.
* @return the result of the function.
* @throws E if the function fails.
*/
int applyAsInt(T t, U u) throws E;
}

View File

@ -0,0 +1,17 @@
package fr.pandacube.lib.util.function;
/**
* A consumer that can possibly throw a checked exception.
*/
@FunctionalInterface
public interface TriConsumerException<T, U, V, E extends Exception> {
/**
* Run the consumer on the specified parameters.
*
* @param t the first parameter of the consumer.
* @param u the second parameter of the consumer.
* @param v the third parameter of the consumer.
* @throws E if the function fails.
*/
void accept(T t, U u, V v) throws E;
}

View File

@ -1,4 +1,4 @@
package fr.pandacube.lib.util.logs;
package fr.pandacube.lib.util.log;
import java.io.BufferedWriter;
import java.io.File;

View File

@ -1,4 +1,4 @@
package fr.pandacube.lib.util;
package fr.pandacube.lib.util.log;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;

View File

@ -1,8 +1,8 @@
package fr.pandacube.lib.ws;
import com.google.gson.JsonParseException;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.ThrowableUtil.RunnableException;
import fr.pandacube.lib.util.log.Log;
import fr.pandacube.lib.util.function.RunnableException;
import fr.pandacube.lib.ws.payloads.ErrorPayload;
import fr.pandacube.lib.ws.payloads.Payload;