-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for preprocessing and postprocessing of template
- Loading branch information
Showing
8 changed files
with
63 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,7 @@ | ||
package dev.shiza.honey.processor; | ||
|
||
/** | ||
* Functional interface for processing content. | ||
* | ||
* <p>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 | ||
*/ | ||
String process(final String content); | ||
} |
6 changes: 6 additions & 0 deletions
6
honey-common/src/dev/shiza/honey/processor/ProcessorPhase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package dev.shiza.honey.processor; | ||
|
||
public enum ProcessorPhase { | ||
PREPROCESS, | ||
POSTPROCESS | ||
} |
29 changes: 2 additions & 27 deletions
29
honey-common/src/dev/shiza/honey/processor/ProcessorRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,8 @@ | ||
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. | ||
* | ||
* <p>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 | ||
*/ | ||
ProcessorRegistry preprocessor(final Processor processor); | ||
ProcessorRegistry processor(final ProcessorPhase phase, 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 | ||
*/ | ||
String preprocess(final String content); | ||
String process(final ProcessorPhase phase, final String content); | ||
} |
22 changes: 4 additions & 18 deletions
22
honey-common/src/dev/shiza/honey/processor/ProcessorRegistryFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,18 @@ | ||
package dev.shiza.honey.processor; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* 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() {} | ||
|
||
/** | ||
* 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<Processor> preprocessors) { | ||
public static ProcessorRegistry create(final Map<ProcessorPhase, List<Processor>> preprocessors) { | ||
return new ProcessorRegistryImpl(preprocessors); | ||
} | ||
|
||
/** | ||
* 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()); | ||
return create(ImmutableMap.of()); | ||
} | ||
} |
42 changes: 18 additions & 24 deletions
42
honey-common/src/dev/shiza/honey/processor/ProcessorRegistryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters