How xiaokuntt/business-util works
Project Type and Purpose
• This is a Java/Maven-based open-source utility library (“business-util”) designed to simplify complex business-rule and configuration matching by providing a priority-based matching engine.
• There is no “frontend” or “backend” in the typical web-app sense. Instead, the key focus is on a reusable API and an internal matching engine.
a. API Layer
• PriorityAssembler<TSource, TConfig, TKey>
• PriorityFetcher<TSource, TConfig, TKey>
b. Matching Engine (Core Logic)
• PriorityMatchFunction – encapsulates a single matching rule
• PriorityMatchProcessor → orchestrates the sequential execution of functions
• PriorityMatchProcessorTree → optional tree-based processor for large rule sets
• PriorityHandler (and its two built-in implementations driven by PriorityMode)
c. Data Models / Value Objects
• PriorityMatchResult – holds matched configurations and metadata
• PriorityMatchType, PriorityMode – enums defining match types and handler modes
Relationships & Data Flow
• Client (your application) → calls PriorityAssembler.from(...) → obtains an assembler.
• Assembler
→ initConfig(configList) loads TConfig objects into an internal store
→ addPriorityMatchFunction(...) registers one or more PriorityMatchFunction instances
→ initPriorityHandler(PriorityMode) selects a PriorityHandler strategy
→ create() produces a PriorityFetcher instance
• PriorityFetcher
→ when match(source) is invoked, it instantiates either
• a flat list of PriorityMatchProcessor, or
• a PriorityMatchProcessorTree (if .tree() is called)
→ processes the input source through the chain/tree of PriorityMatchFunction nodes
→ applies the configured PriorityHandler (e.g., NUMBER_OF_MATCHES or ABSOLUTE_VALUE)
→ returns a PriorityMatchResult containing the best-match configuration(s)
• PriorityMatchResult flows back to the client
Architectural Patterns & Principles
• Builder/Fluent API: PriorityAssembler as a chained initializer for configuration, functions, and handler.
• Strategy Pattern: PriorityHandler is pluggable (two built-in strategies plus room for custom handlers).
• Chain of Responsibility / Tree Structure: sequential processors or a tree of processors for performance at scale.
• Separation of Concerns:
• Assembler – setup/configuration
• Fetcher/Processor – execution logic
• Handler – prioritization strategy
• Model – enums and result object
Technologies & Frameworks
• Java 8+ (lambdas for match functions)
• Maven for build and dependency management
• JUnit for tests (src/test)