From 3f95b0711fecbdeb1c3dd09c185162297979f52a Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 28 Feb 2024 15:40:29 +0000 Subject: [PATCH] Remove JavaExtensions This class was specifically intended to be used with Lombok's ExtensionMethod annotation. But it's not used anymore nor will be ever be used, particularly when we start supporting Kotlin. --- .../civmodcore/utilities/JavaExtensions.java | 153 ------------------ 1 file changed, 153 deletions(-) delete mode 100644 plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/utilities/JavaExtensions.java diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/utilities/JavaExtensions.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/utilities/JavaExtensions.java deleted file mode 100644 index fb9733033..000000000 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/utilities/JavaExtensions.java +++ /dev/null @@ -1,153 +0,0 @@ -package vg.civcraft.mc.civmodcore.utilities; - -import java.util.Objects; -import java.util.Optional; -import java.util.function.Predicate; -import java.util.function.Supplier; -import javax.annotation.Nonnull; - -/** - * Set of extension methods to make Java more tolerable. - */ -public final class JavaExtensions { - - /** - * @param The type of the instance. - * @param self The instance itself. - * @param fallback The fallback instance to use if "self" is missing. - * @return Returns the instance, or the fallback. - */ - public static T orElse(final T self, final T fallback) { - return self == null ? fallback : self; - } - - /** - * @param The type of the instance. - * @param self The instance itself. - * @param getter The fallback supplier to use if "self" is missing. - * @return Returns the instance, or generates a fallback. - */ - public static T orElseGet(final T self, final Supplier getter) { - return self == null ? getter.get() : self; - } - - /** - * @param The type of the instance. - * @param self The instance itself. - * @return Returns the instance. - * - * @throws NullPointerException Throws if the given instance is null. - */ - @Nonnull - public static T isRequired(final T self) { - return Objects.requireNonNull(self); - } - - /** - * @param The type of the instance. - * @param self The instance itself. - * @param message The message for {@link NullPointerException} should the instance be null. - * @return Returns the instance. - * - * @throws NullPointerException Throws if the given instance is null. - */ - @Nonnull - public static T isRequired(final T self, @Nonnull final String message) { - return Objects.requireNonNull(self, Objects.requireNonNull(message, "really?")); - } - - /** - * @param The type of the instance. - * @param self The instance itself. - * @return Returns an {@link Optional} wrapping the instance. - */ - @Nonnull - public static Optional asOptional(final T self) { - return Optional.ofNullable(self); - } - - /** - * @param The type of the instance. - * @param self The instance itself. - * @param tester The instance tester. - * @return Returns the instance if the test passes. - * - * @throws IllegalStateException This is thrown if the test is failed. - */ - @Nonnull - public static T testCompliance(final T self, - @Nonnull final Predicate tester) { - if (tester.test(self)) { - return self; - } - throw new IllegalStateException("Instance was found to be non-compliant!"); - } - - /** - * @param The type of the instance. - * @param self The instance itself. - * @param tester The instance tester. - * @param message The message to use if the test fails. - * @return Returns the instance if the test passes. - * - * @throws IllegalStateException This is thrown if the test is failed. - */ - @Nonnull - public static T testCompliance(final T self, - @Nonnull final Predicate tester, - @Nonnull final String message) { - if (tester.test(self)) { - return self; - } - throw new IllegalStateException(Objects.requireNonNull(message, "really?")); - } - - /** - * @param The type of the instance. - * @param self The instance itself. - * @param defaultString The string to use if the instance is null. - * @return Returns a stringified version of the instance, or the default string. - */ - @Nonnull - public static String toStringOr(final T self, - @Nonnull final String defaultString) { - if (self == null) { - return Objects.requireNonNull(defaultString); - } - return self.toString(); - } - - /** - * @param The type of the instance. - * @param self The instance itself. - * @param formatString The format string for the stringified instance to be formatted into. - * @param defaultString The string to use if the instance is null. - * @return Returns a formatted stringified version of the instance, or the default string. - * - * @see String#format(String, Object...) - */ - @Nonnull - public static String toFormattedString(final T self, - @Nonnull final String formatString, - @Nonnull final String defaultString) { - if (self == null) { - return Objects.requireNonNull(defaultString); - } - return String.format(Objects.requireNonNull(formatString), self); - } - - /** - * @param The type of the instance. - * @param self The instance itself. - * @param formatString The format string for the stringified instance to be formatted into. - * @return Returns a formatted stringified version of the instance. - * - * @see String#format(String, Object...) - */ - @Nonnull - public static String toFormattedString(final T self, - @Nonnull final String formatString) { - return String.format(Objects.requireNonNull(formatString), Objects.requireNonNull(self)); - } - -}