From 415db7e546773b6896044817cde273a842034c8a Mon Sep 17 00:00:00 2001 From: rafal <63915083+rchomczyk@users.noreply.github.com> Date: Sun, 17 Nov 2024 13:38:37 +0100 Subject: [PATCH] Add publishing of javadocs and reformat code --- .../src/main/kotlin/honey-publish.gradle.kts | 1 + .../compiler/AdventureMessageCompiler.java | 44 ++-- .../AdventureMessageCompilerFactory.java | 27 +- .../AdventureMessageDispatcher.java | 37 ++- .../AdventureTitleMessageDispatcher.java | 238 +++++++++--------- .../formatter/AdventureMessageFormatter.java | 53 ++-- .../AdventureMessageFormatterFactory.java | 106 ++++---- .../adventure/placeholder/ParsableValue.java | 11 +- .../honey/conversion/ImplicitConversion.java | 50 ++-- .../ImplicitConversionException.java | 8 +- .../conversion/ImplicitConversionUnit.java | 26 +- .../src/dev/shiza/honey/message/Message.java | 38 +-- .../message/compiler/MessageCompiler.java | 22 +- .../dispatcher/MessageBaseDispatcher.java | 2 +- .../message/dispatcher/MessageDispatcher.java | 97 ++++--- .../MessageDispatchingException.java | 6 +- .../message/dispatcher/MessageRenderer.java | 105 ++++---- .../dispatcher/TitleMessageDispatcher.java | 76 +++--- .../formatter/MessageBaseFormatter.java | 37 +-- .../message/formatter/MessageFormatter.java | 30 +-- .../visitor/PlaceholderVisitorImpl.java | 2 +- .../visitor/PromisingPlaceholderVisitor.java | 2 +- .../dev/shiza/honey/processor/Processor.java | 28 +-- .../honey/processor/ProcessorRegistry.java | 46 ++-- .../processor/ProcessorRegistryFactory.java | 25 +- .../processor/ProcessorRegistryImpl.java | 36 +-- .../ReflectivePlaceholderEvaluatorTest.java | 4 +- ...flectivePlaceholderEvaluatorTestUtils.java | 5 +- 28 files changed, 585 insertions(+), 577 deletions(-) diff --git a/buildSrc/src/main/kotlin/honey-publish.gradle.kts b/buildSrc/src/main/kotlin/honey-publish.gradle.kts index d8167d3..5a6776c 100644 --- a/buildSrc/src/main/kotlin/honey-publish.gradle.kts +++ b/buildSrc/src/main/kotlin/honey-publish.gradle.kts @@ -8,6 +8,7 @@ version = "2.0.2-SNAPSHOT" java { withSourcesJar() + withJavadocJar() } publishing { diff --git a/honey-common/src/dev/shiza/honey/adventure/message/compiler/AdventureMessageCompiler.java b/honey-common/src/dev/shiza/honey/adventure/message/compiler/AdventureMessageCompiler.java index 35f43f9..98d998b 100644 --- a/honey-common/src/dev/shiza/honey/adventure/message/compiler/AdventureMessageCompiler.java +++ b/honey-common/src/dev/shiza/honey/adventure/message/compiler/AdventureMessageCompiler.java @@ -14,12 +14,11 @@ import org.intellij.lang.annotations.Subst; /** -* This class provides a mechanism to compile messages using the Adventure API MiniMessage format. -* It translates sanitized content and placeholders into formatted Adventure {@link Component}s. -*/ + * This class provides a mechanism to compile messages using the Adventure API MiniMessage format. + * It translates sanitized content and placeholders into formatted Adventure {@link Component}s. + */ final class AdventureMessageCompiler implements MessageCompiler { - private final MiniMessage miniMessage; AdventureMessageCompiler(final MiniMessage miniMessage) { @@ -27,12 +26,12 @@ final class AdventureMessageCompiler implements MessageCompiler { } /** - * Compiles the sanitized content and placeholders into an Adventure {@link Component}. - * - * @param sanitizedContent The sanitized content string to be compiled. - * @param placeholders The list of sanitized placeholders to be included in the content. - * @return The compiled message as an Adventure {@link Component}. - */ + * Compiles the sanitized content and placeholders into an Adventure {@link Component}. + * + * @param sanitizedContent The sanitized content string to be compiled. + * @param placeholders The list of sanitized placeholders to be included in the content. + * @return The compiled message as an Adventure {@link Component}. + */ @Override public Component compile( final String sanitizedContent, final List placeholders) { @@ -41,11 +40,11 @@ public Component compile( } /** - * Converts a list of {@link SanitizedPlaceholder} into an array of {@link TagResolver}. - * - * @param placeholders The list of placeholders to be converted. - * @return An array of {@link TagResolver}. - */ + * Converts a list of {@link SanitizedPlaceholder} into an array of {@link TagResolver}. + * + * @param placeholders The list of placeholders to be converted. + * @return An array of {@link TagResolver}. + */ private TagResolver[] getPlaceholderTags(final List placeholders) { final TagResolver[] tagResolvers = new TagResolver[placeholders.size()]; for (int index = 0; index < tagResolvers.length; index++) { @@ -56,13 +55,14 @@ private TagResolver[] getPlaceholderTags(final List placeh } /** - * Creates a {@link TagResolver} based on the key and the evaluated value of the placeholder. - * The method handles different types of evaluated values by converting them into suitable tag resolutions. - * - * @param key The key associated with the placeholder. - * @param evaluatedValue The evaluated value of the placeholder. - * @return The appropriate {@link TagResolver} based on the type of evaluated value. - */ + * Creates a {@link TagResolver} based on the key and the evaluated value of the placeholder. The + * method handles different types of evaluated values by converting them into suitable tag + * resolutions. + * + * @param key The key associated with the placeholder. + * @param evaluatedValue The evaluated value of the placeholder. + * @return The appropriate {@link TagResolver} based on the type of evaluated value. + */ private TagResolver getPlaceholderTags( final @Subst("default") String key, final Object evaluatedValue) { if (evaluatedValue instanceof Component component) { diff --git a/honey-common/src/dev/shiza/honey/adventure/message/compiler/AdventureMessageCompilerFactory.java b/honey-common/src/dev/shiza/honey/adventure/message/compiler/AdventureMessageCompilerFactory.java index 48546c0..3f06c3e 100644 --- a/honey-common/src/dev/shiza/honey/adventure/message/compiler/AdventureMessageCompilerFactory.java +++ b/honey-common/src/dev/shiza/honey/adventure/message/compiler/AdventureMessageCompilerFactory.java @@ -6,29 +6,28 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; -/** -* Factory for creating Adventure message compilers. -*/ +/** Factory for creating Adventure message compilers. */ public final class AdventureMessageCompilerFactory { - private AdventureMessageCompilerFactory() { - } + private AdventureMessageCompilerFactory() {} /** - * Creates a message compiler using a specific MiniMessage. - * - * @param miniMessage the MiniMessage instance to use for the compiler. - * @return a new instance of {@link MessageCompiler} configured with the given MiniMessage. - */ + * Creates a message compiler using a specific MiniMessage. + * + * @param miniMessage the MiniMessage instance to use for the compiler. + * @return a new instance of {@link MessageCompiler} configured with the given + * MiniMessage. + */ public static MessageCompiler create(final MiniMessage miniMessage) { return new AdventureMessageCompiler(miniMessage); } /** - * Creates a default message compiler with default MiniMessage configuration. - * - * @return a new instance of {@link MessageCompiler} with the default MiniMessage configuration. - */ + * Creates a default message compiler with default MiniMessage configuration. + * + * @return a new instance of {@link MessageCompiler} with the default MiniMessage + * configuration. + */ public static MessageCompiler create() { return new AdventureMessageCompiler(miniMessage()); } diff --git a/honey-common/src/dev/shiza/honey/adventure/message/dispatcher/AdventureMessageDispatcher.java b/honey-common/src/dev/shiza/honey/adventure/message/dispatcher/AdventureMessageDispatcher.java index 1860588..044b676 100644 --- a/honey-common/src/dev/shiza/honey/adventure/message/dispatcher/AdventureMessageDispatcher.java +++ b/honey-common/src/dev/shiza/honey/adventure/message/dispatcher/AdventureMessageDispatcher.java @@ -7,39 +7,38 @@ import net.kyori.adventure.text.Component; /** -* AdventureMessageDispatcher provides static factory methods to create various types of message dispatchers -* for use in an adventure game context. This class cannot be instantiated and provides centralized -* access to functions creating dispatchers for chat messages, action bars, and titles. -*/ + * AdventureMessageDispatcher provides static factory methods to create various types of message + * dispatchers for use in an adventure game context. This class cannot be instantiated and provides + * centralized access to functions creating dispatchers for chat messages, action bars, and titles. + */ public final class AdventureMessageDispatcher { - private AdventureMessageDispatcher() { - } + private AdventureMessageDispatcher() {} /** - * Creates a MessageDispatcher for sending chat messages. - * - * @return A MessageDispatcher instance configured to send chat messages to an Audience. - */ + * Creates a MessageDispatcher for sending chat messages. + * + * @return A MessageDispatcher instance configured to send chat messages to an Audience. + */ public static MessageDispatcher createChat() { return new MessageBaseDispatcher<>(Audience.empty(), Audience::sendMessage); } /** - * Creates a MessageDispatcher for sending action bar messages. - * - * @return A MessageDispatcher instance configured to send action bar messages to an Audience. - */ + * Creates a MessageDispatcher for sending action bar messages. + * + * @return A MessageDispatcher instance configured to send action bar messages to an Audience. + */ public static MessageDispatcher createActionBar() { return new MessageBaseDispatcher<>(Audience.empty(), Audience::sendActionBar); } /** - * Creates a TitleMessageDispatcher for sending title messages. - * - * @return A TitleMessageDispatcher instance configured to send title messages to an Audience. - */ + * Creates a TitleMessageDispatcher for sending title messages. + * + * @return A TitleMessageDispatcher instance configured to send title messages to an Audience. + */ public static TitleMessageDispatcher createTitle() { return new AdventureTitleMessageDispatcher(); } -} \ No newline at end of file +} diff --git a/honey-common/src/dev/shiza/honey/adventure/message/dispatcher/AdventureTitleMessageDispatcher.java b/honey-common/src/dev/shiza/honey/adventure/message/dispatcher/AdventureTitleMessageDispatcher.java index 51042f1..9cbd8dd 100644 --- a/honey-common/src/dev/shiza/honey/adventure/message/dispatcher/AdventureTitleMessageDispatcher.java +++ b/honey-common/src/dev/shiza/honey/adventure/message/dispatcher/AdventureTitleMessageDispatcher.java @@ -16,135 +16,135 @@ import net.kyori.adventure.title.TitlePart; /** -* This class is responsible for dispatching title messages to an audience in the Adventure framework. -* It manages separate dispatchers for times, title, and subtitle, as well as keeping track of the recipient. -* -* @param IN the audience type that the messages are dispatched to -* @param OUT the message component type -*/ + * This class is responsible for dispatching title messages to an audience in the Adventure + * framework. It manages separate dispatchers for times, title, and subtitle, as well as keeping + * track of the recipient. + * + * @param IN the audience type that the messages are dispatched to + * @param OUT the message component type + */ public final class AdventureTitleMessageDispatcher implements TitleMessageDispatcher { - private final MessageDispatcher times; - private final MessageDispatcher title; - private final MessageDispatcher subtitle; - private final Audience recipient; + private final MessageDispatcher times; + private final MessageDispatcher title; + private final MessageDispatcher subtitle; + private final Audience recipient; - /** - * Constructs a new AdventureTitleMessageDispatcher with specified dispatchers for times, title, subtitle and a recipient. - * - * @param times the dispatcher for handling the timing of title messages - * @param title the dispatcher for handling the main title messages - * @param subtitle the dispatcher for handling the subtitle messages - * @param recipient the audience that will receive the title messages - */ - public AdventureTitleMessageDispatcher( - final MessageDispatcher times, - final MessageDispatcher title, - final MessageDispatcher subtitle, - final Audience recipient) { - this.times = times; - this.title = title; - this.subtitle = subtitle; - this.recipient = recipient; - } + /** + * Constructs a new AdventureTitleMessageDispatcher with specified dispatchers for times, title, + * subtitle and a recipient. + * + * @param times the dispatcher for handling the timing of title messages + * @param title the dispatcher for handling the main title messages + * @param subtitle the dispatcher for handling the subtitle messages + * @param recipient the audience that will receive the title messages + */ + public AdventureTitleMessageDispatcher( + final MessageDispatcher times, + final MessageDispatcher title, + final MessageDispatcher subtitle, + final Audience recipient) { + this.times = times; + this.title = title; + this.subtitle = subtitle; + this.recipient = recipient; + } - /** - * Default constructor that initializes with default dispatchers for times, title, and subtitle, - * with an empty recipient. - */ - public AdventureTitleMessageDispatcher() { - this( - new MessageBaseDispatcher<>( - Audience.empty(), - (audience, component) -> audience.sendTitlePart(TitlePart.TIMES, Title.DEFAULT_TIMES)), - new MessageBaseDispatcher<>( - Audience.empty(), - (audience, component) -> audience.sendTitlePart(TitlePart.TITLE, component)), - new MessageBaseDispatcher<>( - Audience.empty(), - (audience, component) -> audience.sendTitlePart(TitlePart.SUBTITLE, component)), - Audience.empty()); - } + /** + * Default constructor that initializes with default dispatchers for times, title, and subtitle, + * with an empty recipient. + */ + public AdventureTitleMessageDispatcher() { + this( + new MessageBaseDispatcher<>( + Audience.empty(), + (audience, component) -> audience.sendTitlePart(TitlePart.TIMES, Title.DEFAULT_TIMES)), + new MessageBaseDispatcher<>( + Audience.empty(), + (audience, component) -> audience.sendTitlePart(TitlePart.TITLE, component)), + new MessageBaseDispatcher<>( + Audience.empty(), + (audience, component) -> audience.sendTitlePart(TitlePart.SUBTITLE, component)), + Audience.empty()); + } - /** - * Sets the times for the title message. - * - * @param fadeIn duration in seconds for title fade-in - * @param stay duration in seconds the title should stay visible - * @param fadeOut duration in seconds for title fade-out - * @return a new instance of AdventureTitleMessageDispatcher with updated times dispatcher - */ - @Override - public TitleMessageDispatcher times( - final int fadeIn, final int stay, final int fadeOut) { - final Times titleTime = - Times.times( - Duration.ofSeconds(fadeIn), Duration.ofSeconds(stay), Duration.ofSeconds(fadeOut)); - final MessageDispatcher timesDispatcher = - new MessageBaseDispatcher<>( + /** + * Sets the times for the title message. + * + * @param fadeIn duration in seconds for title fade-in + * @param stay duration in seconds the title should stay visible + * @param fadeOut duration in seconds for title fade-out + * @return a new instance of AdventureTitleMessageDispatcher with updated times dispatcher + */ + @Override + public TitleMessageDispatcher times( + final int fadeIn, final int stay, final int fadeOut) { + final Times titleTime = + Times.times( + Duration.ofSeconds(fadeIn), Duration.ofSeconds(stay), Duration.ofSeconds(fadeOut)); + final MessageDispatcher timesDispatcher = + new MessageBaseDispatcher<>( recipient, (audience, component) -> audience.sendTitlePart(TitlePart.TIMES, titleTime)); - return new AdventureTitleMessageDispatcher( - timesDispatcher.template(Component.empty()), title, subtitle, recipient); - } + return new AdventureTitleMessageDispatcher( + timesDispatcher.template(Component.empty()), title, subtitle, recipient); + } - /** - * Modifies the title dispatcher. - * - * @param consumer the function to modify the title dispatcher - * @return a new instance of AdventureTitleMessageDispatcher with updated title dispatcher - */ - @Override - public TitleMessageDispatcher title( - final UnaryOperator> consumer) { - return new AdventureTitleMessageDispatcher(times, consumer.apply(title), subtitle, recipient); - } + /** + * Modifies the title dispatcher. + * + * @param consumer the function to modify the title dispatcher + * @return a new instance of AdventureTitleMessageDispatcher with updated title dispatcher + */ + @Override + public TitleMessageDispatcher title( + final UnaryOperator> consumer) { + return new AdventureTitleMessageDispatcher(times, consumer.apply(title), subtitle, recipient); + } - /** - * Modifies the subtitle dispatcher. - * - * @param consumer the function to modify the subtitle dispatcher - * @return a new instance of AdventureTitleMessageDispatcher with updated subtitle dispatcher - */ - @Override - public TitleMessageDispatcher subtitle( - final UnaryOperator> consumer) { - return new AdventureTitleMessageDispatcher(times, title, consumer.apply(subtitle), recipient); - } + /** + * Modifies the subtitle dispatcher. + * + * @param consumer the function to modify the subtitle dispatcher + * @return a new instance of AdventureTitleMessageDispatcher with updated subtitle dispatcher + */ + @Override + public TitleMessageDispatcher subtitle( + final UnaryOperator> consumer) { + return new AdventureTitleMessageDispatcher(times, title, consumer.apply(subtitle), recipient); + } - /** - * Updates the recipient of title messages. - * - * @param recipient the new recipient for the title messages - * @return a new instance of AdventureTitleMessageDispatcher with the updated recipient - */ - @Override - public TitleMessageDispatcher recipient(final Audience recipient) { - return new AdventureTitleMessageDispatcher(times, title, subtitle, recipient); - } + /** + * Updates the recipient of title messages. + * + * @param recipient the new recipient for the title messages + * @return a new instance of AdventureTitleMessageDispatcher with the updated recipient + */ + @Override + public TitleMessageDispatcher recipient(final Audience recipient) { + return new AdventureTitleMessageDispatcher(times, title, subtitle, recipient); + } - /** - * Dispatches the title, subtitle, and timing messages to the recipient synchronously. - */ - @Override - public void dispatch() { - times.recipient(recipient).dispatch(); - title.recipient(recipient).dispatch(); - subtitle.recipient(recipient).dispatch(); - } + /** Dispatches the title, subtitle, and timing messages to the recipient synchronously. */ + @Override + public void dispatch() { + times.recipient(recipient).dispatch(); + title.recipient(recipient).dispatch(); + subtitle.recipient(recipient).dispatch(); + } - /** - * Dispatches the title, subtitle, and timing messages to the recipient asynchronously. - * - * @return a CompletableFuture representing pending completion of the task, - * with a list of Void, indicating when all dispatches are complete - */ - @Override - public CompletableFuture> dispatchAsync() { - return CompletableFutures.allAsList( - ImmutableList.of( - times.recipient(recipient).dispatchAsync(), - title.recipient(recipient).dispatchAsync(), - subtitle.recipient(recipient).dispatchAsync())); - } + /** + * Dispatches the title, subtitle, and timing messages to the recipient asynchronously. + * + * @return a CompletableFuture representing pending completion of the task, with a list of Void, + * indicating when all dispatches are complete + */ + @Override + public CompletableFuture> dispatchAsync() { + return CompletableFutures.allAsList( + ImmutableList.of( + times.recipient(recipient).dispatchAsync(), + title.recipient(recipient).dispatchAsync(), + subtitle.recipient(recipient).dispatchAsync())); + } } diff --git a/honey-common/src/dev/shiza/honey/adventure/message/formatter/AdventureMessageFormatter.java b/honey-common/src/dev/shiza/honey/adventure/message/formatter/AdventureMessageFormatter.java index 4c3cef8..3c34858 100644 --- a/honey-common/src/dev/shiza/honey/adventure/message/formatter/AdventureMessageFormatter.java +++ b/honey-common/src/dev/shiza/honey/adventure/message/formatter/AdventureMessageFormatter.java @@ -10,34 +10,37 @@ import net.kyori.adventure.text.Component; /** -* Represents a specific implementation of {@link MessageBaseFormatter} for handling Adventure components. -* This class leverages the message formatting system specifically tailored for Adventure library components. -*/ + * Represents a specific implementation of {@link MessageBaseFormatter} for handling Adventure + * components. This class leverages the message formatting system specifically tailored for + * Adventure library components. + */ public final class AdventureMessageFormatter extends MessageBaseFormatter { /** - * Constructs an AdventureMessageFormatter with required components for message compiling and processing. - * - * @param messageCompiler the compiler responsible for message compilation. - * @param placeholderContext the context for processing placeholders. - * @param placeholderResolver responsible for resolving placeholders. - * @param placeholderProcessor processor to apply transformations on placeholders. - * @param placeholderSanitizer sanitizer to clean or adjust placeholders according to specific rules. - * @param processorRegistry registry to keep track of processors and manage them. - */ + * Constructs an AdventureMessageFormatter with required components for message compiling and + * processing. + * + * @param messageCompiler the compiler responsible for message compilation. + * @param placeholderContext the context for processing placeholders. + * @param placeholderResolver responsible for resolving placeholders. + * @param placeholderProcessor processor to apply transformations on placeholders. + * @param placeholderSanitizer sanitizer to clean or adjust placeholders according to specific + * rules. + * @param processorRegistry registry to keep track of processors and manage them. + */ AdventureMessageFormatter( - final MessageCompiler messageCompiler, - final PlaceholderContext placeholderContext, - final PlaceholderResolver placeholderResolver, - final PlaceholderProcessor placeholderProcessor, - final PlaceholderSanitizer placeholderSanitizer, - final ProcessorRegistry processorRegistry) { + final MessageCompiler messageCompiler, + final PlaceholderContext placeholderContext, + final PlaceholderResolver placeholderResolver, + final PlaceholderProcessor placeholderProcessor, + final PlaceholderSanitizer placeholderSanitizer, + final ProcessorRegistry processorRegistry) { super( - messageCompiler, - placeholderContext, - placeholderResolver, - placeholderProcessor, - placeholderSanitizer, - processorRegistry); + messageCompiler, + placeholderContext, + placeholderResolver, + placeholderProcessor, + placeholderSanitizer, + processorRegistry); } -} \ No newline at end of file +} diff --git a/honey-common/src/dev/shiza/honey/adventure/message/formatter/AdventureMessageFormatterFactory.java b/honey-common/src/dev/shiza/honey/adventure/message/formatter/AdventureMessageFormatterFactory.java index ec8e811..773ec9b 100644 --- a/honey-common/src/dev/shiza/honey/adventure/message/formatter/AdventureMessageFormatterFactory.java +++ b/honey-common/src/dev/shiza/honey/adventure/message/formatter/AdventureMessageFormatterFactory.java @@ -17,64 +17,64 @@ import net.kyori.adventure.text.Component; /** -* Provides factory methods to create instances of AdventureMessageFormatter. -* This class is utility-based and should not be instantiated. -*/ + * Provides factory methods to create instances of AdventureMessageFormatter. This class is + * utility-based and should not be instantiated. + */ public final class AdventureMessageFormatterFactory { - private AdventureMessageFormatterFactory() { - } + private AdventureMessageFormatterFactory() {} - /** - * Creates an instance of AdventureMessageFormatter with specified dependencies. - * - * @param messageCompiler the compiler used to compile messages. - * @param placeholderContext the context holding placeholder values. - * @param placeholderResolver the resolver used to resolve placeholders. - * @param placeholderProcessor the processor to process the placeholders. - * @param placeholderSanitizer the sanitizer to sanitize placeholders. - * @param processorRegistry the registry holding different processors. - * @return an instance of AdventureMessageFormatter. - */ - public static AdventureMessageFormatter create( - final MessageCompiler messageCompiler, - final PlaceholderContext placeholderContext, - final PlaceholderResolver placeholderResolver, - final PlaceholderProcessor placeholderProcessor, - final PlaceholderSanitizer placeholderSanitizer, - final ProcessorRegistry processorRegistry) { - return new AdventureMessageFormatter( - messageCompiler, - placeholderContext, - placeholderResolver, - placeholderProcessor, - placeholderSanitizer, - processorRegistry); - } + /** + * Creates an instance of AdventureMessageFormatter with specified dependencies. + * + * @param messageCompiler the compiler used to compile messages. + * @param placeholderContext the context holding placeholder values. + * @param placeholderResolver the resolver used to resolve placeholders. + * @param placeholderProcessor the processor to process the placeholders. + * @param placeholderSanitizer the sanitizer to sanitize placeholders. + * @param processorRegistry the registry holding different processors. + * @return an instance of AdventureMessageFormatter. + */ + public static AdventureMessageFormatter create( + final MessageCompiler messageCompiler, + final PlaceholderContext placeholderContext, + final PlaceholderResolver placeholderResolver, + final PlaceholderProcessor placeholderProcessor, + final PlaceholderSanitizer placeholderSanitizer, + final ProcessorRegistry processorRegistry) { + return new AdventureMessageFormatter( + messageCompiler, + placeholderContext, + placeholderResolver, + placeholderProcessor, + placeholderSanitizer, + processorRegistry); + } - /** - * Creates a default instance of AdventureMessageFormatter with automatically initialized dependencies. - * - * @return an instance of AdventureMessageFormatter with default configuration. - */ - public static AdventureMessageFormatter create() { - final MessageCompiler messageCompiler = AdventureMessageCompilerFactory.create(); - final ImplicitConversion implicitConversion = ImplicitConversion.create(); - final PlaceholderContext placeholderContext = PlaceholderContext.create(); - final PlaceholderResolver placeholderResolver = PlaceholderResolverFactory.create(); - final PlaceholderSanitizer placeholderSanitizer = PlaceholderSanitizerFactory.create(); - final PlaceholderEvaluator placeholderEvaluator = + /** + * Creates a default instance of AdventureMessageFormatter with automatically initialized + * dependencies. + * + * @return an instance of AdventureMessageFormatter with default configuration. + */ + public static AdventureMessageFormatter create() { + final MessageCompiler messageCompiler = AdventureMessageCompilerFactory.create(); + final ImplicitConversion implicitConversion = ImplicitConversion.create(); + final PlaceholderContext placeholderContext = PlaceholderContext.create(); + final PlaceholderResolver placeholderResolver = PlaceholderResolverFactory.create(); + final PlaceholderSanitizer placeholderSanitizer = PlaceholderSanitizerFactory.create(); + final PlaceholderEvaluator placeholderEvaluator = ReflectivePlaceholderEvaluatorFactory.create(); - final PlaceholderProcessor placeholderProcessor = + final PlaceholderProcessor placeholderProcessor = PlaceholderProcessorFactory.create( placeholderEvaluator, placeholderSanitizer, implicitConversion); - final ProcessorRegistry processorRegistry = ProcessorRegistryFactory.create(); - return create( - messageCompiler, - placeholderContext, - placeholderResolver, - placeholderProcessor, - placeholderSanitizer, - processorRegistry); - } + final ProcessorRegistry processorRegistry = ProcessorRegistryFactory.create(); + return create( + messageCompiler, + placeholderContext, + placeholderResolver, + placeholderProcessor, + placeholderSanitizer, + processorRegistry); + } } diff --git a/honey-common/src/dev/shiza/honey/adventure/placeholder/ParsableValue.java b/honey-common/src/dev/shiza/honey/adventure/placeholder/ParsableValue.java index 6def784..9e7c3eb 100644 --- a/honey-common/src/dev/shiza/honey/adventure/placeholder/ParsableValue.java +++ b/honey-common/src/dev/shiza/honey/adventure/placeholder/ParsableValue.java @@ -9,11 +9,12 @@ public record ParsableValue(String value) { /** - * Factory method to create a new instance of {@code ParsableValue} using the provided string value. - * - * @param value The string value to be parsed. - * @return A new instance of {@code ParsableValue} initialized with the provided string value. - */ + * Factory method to create a new instance of {@code ParsableValue} using the provided string + * value. + * + * @param value The string value to be parsed. + * @return A new instance of {@code ParsableValue} initialized with the provided string value. + */ public static ParsableValue of(final String value) { return new ParsableValue(value); } diff --git a/honey-common/src/dev/shiza/honey/conversion/ImplicitConversion.java b/honey-common/src/dev/shiza/honey/conversion/ImplicitConversion.java index e299f89..76989b9 100644 --- a/honey-common/src/dev/shiza/honey/conversion/ImplicitConversion.java +++ b/honey-common/src/dev/shiza/honey/conversion/ImplicitConversion.java @@ -6,9 +6,10 @@ import java.util.stream.Collectors; /** -* The {@code ImplicitConversion} class is responsible for performing implicit conversions on objects between different types. -* It utilizes a set of {@link ImplicitConversionUnit} to define the conversion rules. -*/ + * The {@code ImplicitConversion} class is responsible for performing implicit conversions on + * objects between different types. It utilizes a set of {@link ImplicitConversionUnit} to define + * the conversion rules. + */ public final class ImplicitConversion { private final Map, Function> conversions; @@ -21,31 +22,32 @@ public final class ImplicitConversion { } /** - * Factory method to create an {@code ImplicitConversion} instance with a set of conversion units. - * - * @param units the set of {@link ImplicitConversionUnit} defining conversion rules. - * @return a new instance of {@code ImplicitConversion}. - */ + * Factory method to create an {@code ImplicitConversion} instance with a set of conversion units. + * + * @param units the set of {@link ImplicitConversionUnit} defining conversion rules. + * @return a new instance of {@code ImplicitConversion}. + */ public static ImplicitConversion create(final Set units) { return new ImplicitConversion(units); } /** - * Factory method to create an {@code ImplicitConversion} instance with an array of conversion units. - * - * @param units the array of {@link ImplicitConversionUnit} defining conversion rules. - * @return a new instance of {@code ImplicitConversion}. - */ + * Factory method to create an {@code ImplicitConversion} instance with an array of conversion + * units. + * + * @param units the array of {@link ImplicitConversionUnit} defining conversion rules. + * @return a new instance of {@code ImplicitConversion}. + */ public static ImplicitConversion create(final ImplicitConversionUnit... units) { return create(Set.of(units)); } /** - * Converts a given value by searching for an appropriate conversion rule. - * - * @param value the value to convert - * @return the converted value or the same value if no conversion was applicable - */ + * Converts a given value by searching for an appropriate conversion rule. + * + * @param value the value to convert + * @return the converted value or the same value if no conversion was applicable + */ public Object convert(final Object value) { if (value == null) { return null; @@ -55,12 +57,12 @@ public Object convert(final Object value) { } /** - * Recursively tries to convert the given value using the conversion rules. - * - * @param value the value to convert - * @param conversionFound a flag to indicate if a conversion has already occurred - * @return the converted value, or the same value if no applicable conversion is found - */ + * Recursively tries to convert the given value using the conversion rules. + * + * @param value the value to convert + * @param conversionFound a flag to indicate if a conversion has already occurred + * @return the converted value, or the same value if no applicable conversion is found + */ private Object convertRecursive(final Object value, final boolean conversionFound) { if (value == null || conversionFound) { return value; diff --git a/honey-common/src/dev/shiza/honey/conversion/ImplicitConversionException.java b/honey-common/src/dev/shiza/honey/conversion/ImplicitConversionException.java index f5ffe1b..88e2a3a 100644 --- a/honey-common/src/dev/shiza/honey/conversion/ImplicitConversionException.java +++ b/honey-common/src/dev/shiza/honey/conversion/ImplicitConversionException.java @@ -1,10 +1,10 @@ package dev.shiza.honey.conversion; /** -* An exception that indicates an error due to implicit type conversion that is not permissible. -* This class extends {@link IllegalStateException}, thus indicating that the application is in an -* inappropriate state for the requested operation. -*/ + * An exception that indicates an error due to implicit type conversion that is not permissible. + * This class extends {@link IllegalStateException}, thus indicating that the application is in an + * inappropriate state for the requested operation. + */ public final class ImplicitConversionException extends IllegalStateException { public ImplicitConversionException(final String message) { diff --git a/honey-common/src/dev/shiza/honey/conversion/ImplicitConversionUnit.java b/honey-common/src/dev/shiza/honey/conversion/ImplicitConversionUnit.java index 97a2e00..c7acad2 100644 --- a/honey-common/src/dev/shiza/honey/conversion/ImplicitConversionUnit.java +++ b/honey-common/src/dev/shiza/honey/conversion/ImplicitConversionUnit.java @@ -3,22 +3,24 @@ import java.util.function.Function; /** -* Represents an implicit conversion unit that holds converter functions between different types. -* This record provides type safety and throws exceptions for invalid uses. -*/ + * Represents an implicit conversion unit that holds converter functions between different types. + * This record provides type safety and throws exceptions for invalid uses. + */ public record ImplicitConversionUnit( Class from, Class into, Function conversion) { /** - * Creates an {@code ImplicitConversionUnit} with type-checked conversion. - * @param The source type from which to convert. - * @param The destination type to which to convert. - * @param from The source class. Must not be null. - * @param into The destination class. Must not be null. - * @param conversion The function for converting between types. Must not be null. - * @return An ImplicitConversionUnit instance holding the conversion data. - * @throws ImplicitConversionException If any of the parameters is null or if from and into are the same. - */ + * Creates an {@code ImplicitConversionUnit} with type-checked conversion. + * + * @param The source type from which to convert. + * @param The destination type to which to convert. + * @param from The source class. Must not be null. + * @param into The destination class. Must not be null. + * @param conversion The function for converting between types. Must not be null. + * @return An ImplicitConversionUnit instance holding the conversion data. + * @throws ImplicitConversionException If any of the parameters is null or if from and into are + * the same. + */ public static ImplicitConversionUnit unchecked( final Class from, final Class into, final Function conversion) { if (from == null || into == null || conversion == null) { diff --git a/honey-common/src/dev/shiza/honey/message/Message.java b/honey-common/src/dev/shiza/honey/message/Message.java index 7fbf623..86d6cb8 100644 --- a/honey-common/src/dev/shiza/honey/message/Message.java +++ b/honey-common/src/dev/shiza/honey/message/Message.java @@ -4,40 +4,40 @@ import java.util.function.UnaryOperator; /** -* Represents an immutable message paired with a context for placeholders. -* The context is used to replace placeholders within the message content. -*/ + * Represents an immutable message paired with a context for placeholders. The context is used to + * replace placeholders within the message content. + */ public record Message(String content, PlaceholderContext context) { private static final Message BLANK = new Message("", PlaceholderContext.create()); /** - * Creates a new {@code Message} instance with specified content. - * A new placeholder context is also initialized for this message. - * - * @param content the content of the message - * @return a new {@code Message} instance with initialized placeholder context - */ + * Creates a new {@code Message} instance with specified content. A new placeholder context is + * also initialized for this message. + * + * @param content the content of the message + * @return a new {@code Message} instance with initialized placeholder context + */ public static Message of(final String content) { return new Message(content, PlaceholderContext.create()); } /** - * Retrieves a blank message with an empty content and a new placeholder context. - * - * @return a blank {@code Message} instance - */ + * Retrieves a blank message with an empty content and a new placeholder context. + * + * @return a blank {@code Message} instance + */ public static Message blank() { return BLANK; } /** - * Applies a {@code UnaryOperator} that modifies the placeholder context, - * and returns a new {@code Message} instance with the modified context. - * - * @param mutator the function that modifies the placeholder context - * @return a new {@code Message} instance with the modified placeholder context - */ + * Applies a {@code UnaryOperator} that modifies the placeholder context, and returns a new {@code + * Message} instance with the modified context. + * + * @param mutator the function that modifies the placeholder context + * @return a new {@code Message} instance with the modified placeholder context + */ public Message placeholders(final UnaryOperator mutator) { return new Message(content, mutator.apply(context)); } diff --git a/honey-common/src/dev/shiza/honey/message/compiler/MessageCompiler.java b/honey-common/src/dev/shiza/honey/message/compiler/MessageCompiler.java index 73d35df..d6ba64e 100644 --- a/honey-common/src/dev/shiza/honey/message/compiler/MessageCompiler.java +++ b/honey-common/src/dev/shiza/honey/message/compiler/MessageCompiler.java @@ -4,19 +4,21 @@ import java.util.List; /** -* Represents a compiler function that takes a sanitized string content and a list of placeholders to produce a compiled message of type T. -* -* @param the type of the compiled message output -*/ + * Represents a compiler function that takes a sanitized string content and a list of placeholders + * to produce a compiled message of type T. + * + * @param the type of the compiled message output + */ @FunctionalInterface public interface MessageCompiler { /** - * Compiles a message based on the provided sanitized content and placeholders. - * - * @param sanitizedContent the sanitized textual content to compile - * @param placeholders a list of {@link SanitizedPlaceholder} objects which are to be substituted in the sanitized content - * @return the compiled message of type T - */ + * Compiles a message based on the provided sanitized content and placeholders. + * + * @param sanitizedContent the sanitized textual content to compile + * @param placeholders a list of {@link SanitizedPlaceholder} objects which are to be substituted + * in the sanitized content + * @return the compiled message of type T + */ T compile(final String sanitizedContent, final List placeholders); } diff --git a/honey-common/src/dev/shiza/honey/message/dispatcher/MessageBaseDispatcher.java b/honey-common/src/dev/shiza/honey/message/dispatcher/MessageBaseDispatcher.java index 64efd76..f3397ff 100644 --- a/honey-common/src/dev/shiza/honey/message/dispatcher/MessageBaseDispatcher.java +++ b/honey-common/src/dev/shiza/honey/message/dispatcher/MessageBaseDispatcher.java @@ -2,8 +2,8 @@ import dev.shiza.honey.message.Message; import dev.shiza.honey.message.dispatcher.MessageRenderer.DelegatingMessageRenderer; -import dev.shiza.honey.message.dispatcher.MessageRenderer.FormattingMessageRenderer; import dev.shiza.honey.message.dispatcher.MessageRenderer.EmptyMessageRenderer; +import dev.shiza.honey.message.dispatcher.MessageRenderer.FormattingMessageRenderer; import dev.shiza.honey.message.formatter.MessageFormatter; import java.util.concurrent.CompletableFuture; import java.util.function.BiConsumer; diff --git a/honey-common/src/dev/shiza/honey/message/dispatcher/MessageDispatcher.java b/honey-common/src/dev/shiza/honey/message/dispatcher/MessageDispatcher.java index c95ccb2..22122e4 100644 --- a/honey-common/src/dev/shiza/honey/message/dispatcher/MessageDispatcher.java +++ b/honey-common/src/dev/shiza/honey/message/dispatcher/MessageDispatcher.java @@ -4,78 +4,75 @@ import java.util.concurrent.CompletableFuture; /** -* The {@code MessageDispatcher} interface defines methods for -* configuring and dispatching messages to a recipient. -* -* @param IN the type of the recipient to whom the message will be sent -* @param OUT the type of the result or content of the message -*/ + * The {@code MessageDispatcher} interface defines methods for configuring and dispatching messages + * to a recipient. + * + * @param IN the type of the recipient to whom the message will be sent + * @param OUT the type of the result or content of the message + */ public interface MessageDispatcher { /** - * Sets the recipient of the message. - * - * @param recipient the recipient of the message - * @return the current instance of {@code MessageDispatcher} for method chaining - */ + * Sets the recipient of the message. + * + * @param recipient the recipient of the message + * @return the current instance of {@code MessageDispatcher} for method chaining + */ MessageDispatcher recipient(final VIEWER recipient); /** - * Sets the message template and formatter for the message. - * - * @param formatter the formatter to format the result - * @param template the template string that will be used in formatting the message - * @return the current instance of {@code MessageDispatcher} for method chaining - */ + * Sets the message template and formatter for the message. + * + * @param formatter the formatter to format the result + * @param template the template string that will be used in formatting the message + * @return the current instance of {@code MessageDispatcher} for method chaining + */ MessageDispatcher template( - final MessageFormatter formatter, final String template); + final MessageFormatter formatter, final String template); /** - * Sets the message template and formatter for the message. - * - * @param formatter the formatter to format the result - * @param template the template string that will be used in formatting the message - * @return the current instance of {@code MessageDispatcher} for method chaining - */ + * Sets the message template and formatter for the message. + * + * @param formatter the formatter to format the result + * @param template the template string that will be used in formatting the message + * @return the current instance of {@code MessageDispatcher} for method chaining + */ MessageDispatcher template(final RESULT message); /** - * Sets the message using a plain result. - * - * @param message the result that will be used as the message - * @return the current instance of {@code MessageDispatcher} for method chaining - */ + * Sets the message using a plain result. + * + * @param message the result that will be used as the message + * @return the current instance of {@code MessageDispatcher} for method chaining + */ MessageDispatcher variable(final String key, final Object value); /** - * Adds a variable to the message context. - * - * @param key the key for the variable - * @param value the value of the variable - * @return the current instance of {@code MessageDispatcher} for method chaining - */ + * Adds a variable to the message context. + * + * @param key the key for the variable + * @param value the value of the variable + * @return the current instance of {@code MessageDispatcher} for method chaining + */ MessageDispatcher promisedVariable(final String key, final Object value); /** - * Adds a promised variable to the message context. - * The value is provided asynchronously. - * - * @param key the key for the variable - * @param value the future object containing the value of the variable - * @return the current instance of {@code MessageDispatcher} for method chaining - */ + * Adds a promised variable to the message context. The value is provided asynchronously. + * + * @param key the key for the variable + * @param value the future object containing the value of the variable + * @return the current instance of {@code MessageDispatcher} for method chaining + */ MessageDispatcher promisedVariable( - final String key, final CompletableFuture value); + final String key, final CompletableFuture value); - /** - * Dispatches the message synchronously. - */ + /** Dispatches the message synchronously. */ void dispatch(); /** - * Dispatches the message asynchronously. - * - * @return a {@link CompletableFuture} that is completed when the dispatch is done - */ + * Dispatches the message asynchronously. + * + * @return a {@link CompletableFuture} that is completed when the dispatch is done + */ CompletableFuture dispatchAsync(); } diff --git a/honey-common/src/dev/shiza/honey/message/dispatcher/MessageDispatchingException.java b/honey-common/src/dev/shiza/honey/message/dispatcher/MessageDispatchingException.java index 590bf82..93514e2 100644 --- a/honey-common/src/dev/shiza/honey/message/dispatcher/MessageDispatchingException.java +++ b/honey-common/src/dev/shiza/honey/message/dispatcher/MessageDispatchingException.java @@ -1,9 +1,9 @@ package dev.shiza.honey.message.dispatcher; /** -* Represents an exception that is thrown during message dispatching -* when an illegal or inappropriate state is detected. -*/ + * Represents an exception that is thrown during message dispatching when an illegal or + * inappropriate state is detected. + */ public final class MessageDispatchingException extends IllegalStateException { public MessageDispatchingException(final String message) { diff --git a/honey-common/src/dev/shiza/honey/message/dispatcher/MessageRenderer.java b/honey-common/src/dev/shiza/honey/message/dispatcher/MessageRenderer.java index f5fa3ea..d91c902 100644 --- a/honey-common/src/dev/shiza/honey/message/dispatcher/MessageRenderer.java +++ b/honey-common/src/dev/shiza/honey/message/dispatcher/MessageRenderer.java @@ -9,49 +9,49 @@ import java.util.concurrent.CompletableFuture; /** -* Defines a sealed interface for rendering messages depending on various implementations that -* can add variables to the message or simply define how the rendering should behave. -* -* @param the type of the result of rendering -*/ + * Defines a sealed interface for rendering messages depending on various implementations that can + * add variables to the message or simply define how the rendering should behave. + * + * @param the type of the result of rendering + */ public sealed interface MessageRenderer permits EmptyMessageRenderer, FormattingMessageRenderer, DelegatingMessageRenderer { /** - * Adds a variable to the message. This method may not be supported by non-formatting renderers. - * - * @param key the key for the variable - * @param value the value to associate with the key - * @return a new instance of a message renderer with the variable added - * @throws MessageDispatchingException if the operation is not supported - */ + * Adds a variable to the message. This method may not be supported by non-formatting renderers. + * + * @param key the key for the variable + * @param value the value to associate with the key + * @return a new instance of a message renderer with the variable added + * @throws MessageDispatchingException if the operation is not supported + */ default MessageRenderer variable(final String key, final Object value) { throw new MessageDispatchingException( "Cannot add variable to a non-formatting message renderer"); } /** - * Adds a promised variable. This method may not be supported by non-formatting renderers. - * - * @param key the key for the variable - * @param value the value to associate with the key - * @return a new instance of a message renderer with the variable added - * @throws MessageDispatchingException if the operation is not supported - */ + * Adds a promised variable. This method may not be supported by non-formatting renderers. + * + * @param key the key for the variable + * @param value the value to associate with the key + * @return a new instance of a message renderer with the variable added + * @throws MessageDispatchingException if the operation is not supported + */ default MessageRenderer promisedVariable(final String key, final Object value) { throw new MessageDispatchingException( "Cannot add promised variable to a non-formatting message renderer"); } /** - * Adds a promised variable to the message for asynchronous resolutions. - * This method may not be supported by non-formatting renderers. - * - * @param key the key for the variable - * @param value the future promise of the value to associate with the key - * @return a new instance of a message renderer with the promised variable added - * @throws MessageDispatchingException if the operation is not supported - */ + * Adds a promised variable to the message for asynchronous resolutions. This method may not be + * supported by non-formatting renderers. + * + * @param key the key for the variable + * @param value the future promise of the value to associate with the key + * @return a new instance of a message renderer with the promised variable added + * @throws MessageDispatchingException if the operation is not supported + */ default MessageRenderer promisedVariable( final String key, final CompletableFuture value) { throw new MessageDispatchingException( @@ -59,25 +59,25 @@ default MessageRenderer promisedVariable( } /** - * Renders the message synchronously. - * - * @return the rendering result of the specified type - */ + * Renders the message synchronously. + * + * @return the rendering result of the specified type + */ RESULT render(); /** - * Renders the message asynchronously. - * - * @return a CompletableFuture of the rendering result - */ + * Renders the message asynchronously. + * + * @return a CompletableFuture of the rendering result + */ CompletableFuture renderAsync(); /** - * A message renderer that does not contain any content to render and will throw an exception - * when render methods are called. - * - * @param the type of the result of rendering - */ + * A message renderer that does not contain any content to render and will throw an exception when + * render methods are called. + * + * @param the type of the result of rendering + */ record EmptyMessageRenderer() implements MessageRenderer { @Override @@ -93,13 +93,13 @@ public CompletableFuture renderAsync() { } /** - * A formatting message renderer that uses a specified message formatter and message to render output. - * Supports dynamic addition of variables and promises. - * - * @param the type of the result of rendering - * @param formatter the formatter to format the message - * @param message the message to be formatted - */ + * A formatting message renderer that uses a specified message formatter and message to render + * output. Supports dynamic addition of variables and promises. + * + * @param the type of the result of rendering + * @param formatter the formatter to format the message + * @param message the message to be formatted + */ record FormattingMessageRenderer(MessageFormatter formatter, Message message) implements MessageRenderer { @@ -133,11 +133,12 @@ public CompletableFuture renderAsync() { } /** - * A message renderer that always returns a pre-defined result, for both synchronous and asynchronous methods. - * - * @param the type of the result of rendering - * @param result the result to return on render attempts - */ + * A message renderer that always returns a pre-defined result, for both synchronous and + * asynchronous methods. + * + * @param the type of the result of rendering + * @param result the result to return on render attempts + */ record DelegatingMessageRenderer(RESULT result) implements MessageRenderer { @Override diff --git a/honey-common/src/dev/shiza/honey/message/dispatcher/TitleMessageDispatcher.java b/honey-common/src/dev/shiza/honey/message/dispatcher/TitleMessageDispatcher.java index 0e50352..039dd89 100644 --- a/honey-common/src/dev/shiza/honey/message/dispatcher/TitleMessageDispatcher.java +++ b/honey-common/src/dev/shiza/honey/message/dispatcher/TitleMessageDispatcher.java @@ -5,58 +5,58 @@ import java.util.function.UnaryOperator; /** -* Interface for a TitleMessageDispatcher which is responsible for sending titles, -* subtitles, and managing their display times to specific recipients. -* -* @param IN The type of the viewer/recipient for whom the messages are intended. -* @param OUT The result type for operations that are performed by the MessageDispatcher. -*/ + * Interface for a TitleMessageDispatcher which is responsible for sending titles, subtitles, and + * managing their display times to specific recipients. + * + * @param IN The type of the viewer/recipient for whom the messages are intended. + * @param OUT The result type for operations that are performed by the MessageDispatcher. + */ public interface TitleMessageDispatcher { /** - * Configures the display times of the title message. - * - * @param fadeIn Duration in ticks for the title to fade in. - * @param stay Duration in ticks for the title to remain visible. - * @param fadeOut Duration in ticks for the title to fade out. - * @return An instance of TitleMessageDispatcher for method chaining. - */ + * Configures the display times of the title message. + * + * @param fadeIn Duration in ticks for the title to fade in. + * @param stay Duration in ticks for the title to remain visible. + * @param fadeOut Duration in ticks for the title to fade out. + * @return An instance of TitleMessageDispatcher for method chaining. + */ TitleMessageDispatcher times(final int fadeIn, final int stay, final int fadeOut); /** - * Sets the title message using a UnaryOperator that operates on a MessageDispatcher. - * - * @param consumer A UnaryOperator that configures the MessageDispatcher with the title. - * @return An instance of TitleMessageDispatcher for method chaining. - */ - TitleMessageDispatcher title(final UnaryOperator> consumer); + * Sets the title message using a UnaryOperator that operates on a MessageDispatcher. + * + * @param consumer A UnaryOperator that configures the MessageDispatcher with the title. + * @return An instance of TitleMessageDispatcher for method chaining. + */ + TitleMessageDispatcher title( + final UnaryOperator> consumer); /** - * Sets the subtitle message using a UnaryOperator that operates on a MessageDispatcher. - * - * @param consumer A UnaryOperator that configures the MessageDispatcher with the subtitle. - * @return An instance of TitleMessageDispatcher for method chaining. - */ - TitleMessageDispatcher subtitle(final UnaryOperator> consumer); + * Sets the subtitle message using a UnaryOperator that operates on a MessageDispatcher. + * + * @param consumer A UnaryOperator that configures the MessageDispatcher with the subtitle. + * @return An instance of TitleMessageDispatcher for method chaining. + */ + TitleMessageDispatcher subtitle( + final UnaryOperator> consumer); /** - * Sets the recipient of the title message. - * - * @param recipient The viewer/recipient who will receive the message. - * @return An instance of TitleMessageDispatcher for method chaining. - */ + * Sets the recipient of the title message. + * + * @param recipient The viewer/recipient who will receive the message. + * @return An instance of TitleMessageDispatcher for method chaining. + */ TitleMessageDispatcher recipient(final VIEWER recipient); - /** - * Dispatches the title and subtitle to the recipient synchronously. - */ + /** Dispatches the title and subtitle to the recipient synchronously. */ void dispatch(); /** - * Dispatches the title and subtitle to the recipient asynchronously. - * - * @return A CompletableFuture that completes with a list of results (normally empty) - * once the message dispatch operation is complete. - */ + * Dispatches the title and subtitle to the recipient asynchronously. + * + * @return A CompletableFuture that completes with a list of results (normally empty) once the + * message dispatch operation is complete. + */ CompletableFuture> dispatchAsync(); } diff --git a/honey-common/src/dev/shiza/honey/message/formatter/MessageBaseFormatter.java b/honey-common/src/dev/shiza/honey/message/formatter/MessageBaseFormatter.java index ab3e88d..d638fc7 100644 --- a/honey-common/src/dev/shiza/honey/message/formatter/MessageBaseFormatter.java +++ b/honey-common/src/dev/shiza/honey/message/formatter/MessageBaseFormatter.java @@ -15,9 +15,10 @@ import org.jetbrains.annotations.ApiStatus.Internal; /** -* Abstract base class for formatting messages that encapsulates common logic. -* @param The type of the output formatted message. -*/ + * Abstract base class for formatting messages that encapsulates common logic. + * + * @param The type of the output formatted message. + */ @Internal public abstract class MessageBaseFormatter implements MessageFormatter { @@ -44,10 +45,11 @@ protected MessageBaseFormatter( } /** - * Processes a message synchronously and returns the formatted output. - * @param message The message to format. - * @return The formatted message. - */ + * Processes a message synchronously and returns the formatted output. + * + * @param message The message to format. + * @return The formatted message. + */ @Override public T format(final Message message) { final Set placeholders = placeholderResolver.resolve(message.content()); @@ -61,10 +63,12 @@ public T format(final Message message) { } /** - * Processes a message asynchronously and returns a CompletableFuture that will yield the formatted output. - * @param message The message to format. - * @return A CompletableFuture that upon completion will provide the formatted message. - */ + * Processes a message asynchronously and returns a CompletableFuture that will yield the + * formatted output. + * + * @param message The message to format. + * @return A CompletableFuture that upon completion will provide the formatted message. + */ @Override public CompletableFuture formatAsync(final Message message) { final Set placeholders = placeholderResolver.resolve(message.content()); @@ -78,11 +82,12 @@ public CompletableFuture formatAsync(final Message message) { } /** - * Compiles the message content with sanitized placeholders into the final formatted message. - * @param message The original message. - * @param placeholders The list of sanitized placeholders. - * @return The compiled message of type T. - */ + * Compiles the message content with sanitized placeholders into the final formatted message. + * + * @param message The original message. + * @param placeholders The list of sanitized placeholders. + * @return The compiled message of type T. + */ private T compile(final Message message, final List placeholders) { final String processedContent = processorRegistry.preprocess(message.content()); final String sanitizedContent = diff --git a/honey-common/src/dev/shiza/honey/message/formatter/MessageFormatter.java b/honey-common/src/dev/shiza/honey/message/formatter/MessageFormatter.java index e3926c9..e9028c3 100644 --- a/honey-common/src/dev/shiza/honey/message/formatter/MessageFormatter.java +++ b/honey-common/src/dev/shiza/honey/message/formatter/MessageFormatter.java @@ -4,26 +4,26 @@ import java.util.concurrent.CompletableFuture; /** -* The MessageFormatter interface provides methods to format messages. It offers both -* synchronous and asynchronous methods for formatting a message. -* -* @param the type of the formatted message output. -*/ + * The MessageFormatter interface provides methods to format messages. It offers both synchronous + * and asynchronous methods for formatting a message. + * + * @param the type of the formatted message output. + */ public interface MessageFormatter { /** - * Formats the given message synchronously. - * - * @param message the message to be formatted. - * @return the formatted message of type T. - */ + * Formats the given message synchronously. + * + * @param message the message to be formatted. + * @return the formatted message of type T. + */ T format(final Message message); /** - * Formats the given message asynchronously. - * - * @param message the message to be formatted. - * @return a CompletableFuture representing the formatted message of type T. - */ + * Formats the given message asynchronously. + * + * @param message the message to be formatted. + * @return a CompletableFuture representing the formatted message of type T. + */ CompletableFuture formatAsync(final Message message); } diff --git a/honey-common/src/dev/shiza/honey/placeholder/visitor/PlaceholderVisitorImpl.java b/honey-common/src/dev/shiza/honey/placeholder/visitor/PlaceholderVisitorImpl.java index 5308962..250aa67 100644 --- a/honey-common/src/dev/shiza/honey/placeholder/visitor/PlaceholderVisitorImpl.java +++ b/honey-common/src/dev/shiza/honey/placeholder/visitor/PlaceholderVisitorImpl.java @@ -1,8 +1,8 @@ package dev.shiza.honey.placeholder.visitor; import dev.shiza.honey.placeholder.evaluator.PlaceholderContext; -import dev.shiza.honey.placeholder.resolver.Placeholder; import dev.shiza.honey.placeholder.evaluator.reflection.ReflectivePlaceholderEvaluationException; +import dev.shiza.honey.placeholder.resolver.Placeholder; import java.util.function.UnaryOperator; public final class PlaceholderVisitorImpl implements PlaceholderVisitor { diff --git a/honey-common/src/dev/shiza/honey/placeholder/visitor/PromisingPlaceholderVisitor.java b/honey-common/src/dev/shiza/honey/placeholder/visitor/PromisingPlaceholderVisitor.java index 874f6e8..cd2006c 100644 --- a/honey-common/src/dev/shiza/honey/placeholder/visitor/PromisingPlaceholderVisitor.java +++ b/honey-common/src/dev/shiza/honey/placeholder/visitor/PromisingPlaceholderVisitor.java @@ -1,8 +1,8 @@ package dev.shiza.honey.placeholder.visitor; import dev.shiza.honey.placeholder.evaluator.PlaceholderContext; -import dev.shiza.honey.placeholder.resolver.Placeholder; import dev.shiza.honey.placeholder.evaluator.reflection.ReflectivePlaceholderEvaluationException; +import dev.shiza.honey.placeholder.resolver.Placeholder; import java.util.concurrent.CompletableFuture; import java.util.function.UnaryOperator; diff --git a/honey-common/src/dev/shiza/honey/processor/Processor.java b/honey-common/src/dev/shiza/honey/processor/Processor.java index 9c3f3f9..e6d7c31 100644 --- a/honey-common/src/dev/shiza/honey/processor/Processor.java +++ b/honey-common/src/dev/shiza/honey/processor/Processor.java @@ -1,23 +1,21 @@ package dev.shiza.honey.processor; /** -* Functional interface for processing content. -*

-* This interface is designed for operations that take a single {@link String} -* argument and return a processed {@link String} result. It is marked as a -* {@link FunctionalInterface} to ensure that it can be used in contexts where -* lambda expressions and method references are expected, such as with streams -* or in custom functional programming constructs. -*

-*/ + * Functional interface for processing content. + * + *

This interface is designed for operations that take a single {@link String} argument and + * return a processed {@link String} result. It is marked as a {@link FunctionalInterface} to ensure + * that it can be used in contexts where lambda expressions and method references are expected, such + * as with streams or in custom functional programming constructs. + */ @FunctionalInterface public interface Processor { /** - * Processes the specified content and returns the processed result. - * - * @param content the content to process - * @return the processed result - */ + * Processes the specified content and returns the processed result. + * + * @param content the content to process + * @return the processed result + */ String process(final String content); -} \ No newline at end of file +} diff --git a/honey-common/src/dev/shiza/honey/processor/ProcessorRegistry.java b/honey-common/src/dev/shiza/honey/processor/ProcessorRegistry.java index 1915c19..ceba453 100644 --- a/honey-common/src/dev/shiza/honey/processor/ProcessorRegistry.java +++ b/honey-common/src/dev/shiza/honey/processor/ProcessorRegistry.java @@ -1,35 +1,33 @@ package dev.shiza.honey.processor; /** -* The {@code ProcessorRegistry} interface provides methods for registering -* a preprocessor and preprocessing content. Implementations of this interface -* are expected to maintain a registry of {@link Processor} instances and apply -* these processors to content. -* -*

This interface is typically used to modify or enhance content before -* it is processed in its final form. -*/ + * The {@code ProcessorRegistry} interface provides methods for registering a preprocessor and + * preprocessing content. Implementations of this interface are expected to maintain a registry of + * {@link Processor} instances and apply these processors to content. + * + *

This interface is typically used to modify or enhance content before it is processed in its + * final form. + */ public interface ProcessorRegistry { /** - * Registers the given processor as a preprocessor. The registered processor - * will be applied in the preprocessing stage, and it can modify or enhance - * the input content. - * - * @param processor the {@link Processor} to register as a preprocessor - * @return the current instance of {@code ProcessorRegistry} to allow method chaining - * @throws IllegalArgumentException if the processor is null - */ + * Registers the given processor as a preprocessor. The registered processor will be applied in + * the preprocessing stage, and it can modify or enhance the input content. + * + * @param processor the {@link Processor} to register as a preprocessor + * @return the current instance of {@code ProcessorRegistry} to allow method chaining + * @throws IllegalArgumentException if the processor is null + */ ProcessorRegistry preprocessor(final Processor processor); /** - * Executes preprocessing on the provided content using all registered - * preprocessors. The method processes the content sequentially through each - * preprocessor and returns the final processed output. - * - * @param content the original content to process - * @return the processed content after applying all registered preprocessors - * @throws IllegalArgumentException if the content is null - */ + * Executes preprocessing on the provided content using all registered preprocessors. The method + * processes the content sequentially through each preprocessor and returns the final processed + * output. + * + * @param content the original content to process + * @return the processed content after applying all registered preprocessors + * @throws IllegalArgumentException if the content is null + */ String preprocess(final String content); } diff --git a/honey-common/src/dev/shiza/honey/processor/ProcessorRegistryFactory.java b/honey-common/src/dev/shiza/honey/processor/ProcessorRegistryFactory.java index ff9c91f..09a94a9 100644 --- a/honey-common/src/dev/shiza/honey/processor/ProcessorRegistryFactory.java +++ b/honey-common/src/dev/shiza/honey/processor/ProcessorRegistryFactory.java @@ -4,27 +4,28 @@ import java.util.List; /** -* Factory for creating instances of {@link ProcessorRegistry}. -* This class provides static factory methods to instantiate {@link ProcessorRegistry} with or without initial processors. -*/ + * Factory for creating instances of {@link ProcessorRegistry}. This class provides static factory + * methods to instantiate {@link ProcessorRegistry} with or without initial processors. + */ public final class ProcessorRegistryFactory { - private ProcessorRegistryFactory() { - } + private ProcessorRegistryFactory() {} /** - * Creates a {@link ProcessorRegistry} with the specified list of preprocessors. - * @param preprocessors the list of processors to include in the registry - * @return an instance of {@link ProcessorRegistry} initialized with the given preprocessors - */ + * Creates a {@link ProcessorRegistry} with the specified list of preprocessors. + * + * @param preprocessors the list of processors to include in the registry + * @return an instance of {@link ProcessorRegistry} initialized with the given preprocessors + */ public static ProcessorRegistry create(final List preprocessors) { return new ProcessorRegistryImpl(preprocessors); } /** - * Creates a {@link ProcessorRegistry} with no initial preprocessors. - * @return an instance of {@link ProcessorRegistry} with no initial processors - */ + * Creates a {@link ProcessorRegistry} with no initial preprocessors. + * + * @return an instance of {@link ProcessorRegistry} with no initial processors + */ public static ProcessorRegistry create() { return create(ImmutableList.of()); } diff --git a/honey-common/src/dev/shiza/honey/processor/ProcessorRegistryImpl.java b/honey-common/src/dev/shiza/honey/processor/ProcessorRegistryImpl.java index fad2084..659e0db 100644 --- a/honey-common/src/dev/shiza/honey/processor/ProcessorRegistryImpl.java +++ b/honey-common/src/dev/shiza/honey/processor/ProcessorRegistryImpl.java @@ -4,9 +4,9 @@ import java.util.List; /** -* An implementation of the {@link ProcessorRegistry} interface which allows for keeping track -* and manipulating a list of preprocessors. -*/ + * An implementation of the {@link ProcessorRegistry} interface which allows for keeping track and + * manipulating a list of preprocessors. + */ final class ProcessorRegistryImpl implements ProcessorRegistry { private final List preprocessors; @@ -16,29 +16,29 @@ final class ProcessorRegistryImpl implements ProcessorRegistry { } /** - * Appends a new preprocessor to the registry and returns a new instance of the registry. - * - * @param processor the preprocessor to be added to the registry - * @return a new instance of {@link ProcessorRegistry} with the added preprocessor - */ + * Appends a new preprocessor to the registry and returns a new instance of the registry. + * + * @param processor the preprocessor to be added to the registry + * @return a new instance of {@link ProcessorRegistry} with the added preprocessor + */ @Override public ProcessorRegistry preprocessor(final Processor processor) { - return new ProcessorRegistryImpl(ImmutableList.builder() - .addAll(preprocessors) - .add(processor) - .build() + return new ProcessorRegistryImpl( + ImmutableList.builder().addAll(preprocessors).add(processor).build()); } /** - * Processes a string content by applying all the preprocessors registered. - * - * @param content the content to be processed - * @return the processed content after all preprocessors have been applied - */ + * Processes a string content by applying all the preprocessors registered. + * + * @param content the content to be processed + * @return the processed content after all preprocessors have been applied + */ @Override public String preprocess(final String content) { return preprocessors.stream() - .reduce(content, (processedContent, processor) -> processor.process(processedContent), + .reduce( + content, + (processedContent, processor) -> processor.process(processedContent), (a, b) -> b); } } diff --git a/honey-common/test/dev/shiza/honey/placeholder/evaluator/reflection/ReflectivePlaceholderEvaluatorTest.java b/honey-common/test/dev/shiza/honey/placeholder/evaluator/reflection/ReflectivePlaceholderEvaluatorTest.java index f10ac36..0db6bea 100644 --- a/honey-common/test/dev/shiza/honey/placeholder/evaluator/reflection/ReflectivePlaceholderEvaluatorTest.java +++ b/honey-common/test/dev/shiza/honey/placeholder/evaluator/reflection/ReflectivePlaceholderEvaluatorTest.java @@ -11,9 +11,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; -import dev.shiza.honey.placeholder.visitor.PromisingPlaceholderVisitor; -import dev.shiza.honey.placeholder.visitor.PlaceholderVisitorImpl; import dev.shiza.honey.placeholder.evaluator.EvaluatedPlaceholder; +import dev.shiza.honey.placeholder.visitor.PlaceholderVisitorImpl; +import dev.shiza.honey.placeholder.visitor.PromisingPlaceholderVisitor; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import org.junit.jupiter.api.Test; diff --git a/honey-common/test/dev/shiza/honey/placeholder/evaluator/reflection/ReflectivePlaceholderEvaluatorTestUtils.java b/honey-common/test/dev/shiza/honey/placeholder/evaluator/reflection/ReflectivePlaceholderEvaluatorTestUtils.java index 28b565c..d37ff40 100644 --- a/honey-common/test/dev/shiza/honey/placeholder/evaluator/reflection/ReflectivePlaceholderEvaluatorTestUtils.java +++ b/honey-common/test/dev/shiza/honey/placeholder/evaluator/reflection/ReflectivePlaceholderEvaluatorTestUtils.java @@ -4,9 +4,9 @@ import dev.shiza.honey.placeholder.evaluator.PlaceholderContext; import dev.shiza.honey.placeholder.evaluator.PlaceholderEvaluator; -import dev.shiza.honey.placeholder.resolver.Placeholder; import dev.shiza.honey.placeholder.evaluator.reflection.ReflectivePlaceholderEvaluatorTest.Account; import dev.shiza.honey.placeholder.evaluator.reflection.ReflectivePlaceholderEvaluatorTest.User; +import dev.shiza.honey.placeholder.resolver.Placeholder; import java.time.Duration; final class ReflectivePlaceholderEvaluatorTestUtils { @@ -18,14 +18,13 @@ final class ReflectivePlaceholderEvaluatorTestUtils { static final User USER = new User(NAME, SURNAME); static final Account ACCOUNT = new Account(1, USER); - - static final PlaceholderEvaluator EVALUATOR = new ReflectivePlaceholderEvaluator(); static final PlaceholderContext SYNC_CONTEXT = PlaceholderContext.create().withValue("account", ACCOUNT).withValue("user", USER); static final PlaceholderContext ASYNC_CONTEXT = PlaceholderContext.create() .withPromisedValue("account", ACCOUNT) .withPromisedValue("user", USER); + static final PlaceholderEvaluator EVALUATOR = new ReflectivePlaceholderEvaluator(); static Placeholder placeholder(final String expression) { return new Placeholder("{{" + expression + "}}", expression);