Skip to content

Latest commit

 

History

194 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MgntUtils

Maven Central License Javadoc GitHub release Tests GitHub stars
Scarf: Commercial Users Scarf: Downloads

MgntUtils is an open-source Java library that provides:

  • A collection of utility methods for common tasks that are either missing from or overly verbose in the standard Java API
  • Self-Populating Factory Micro-Framework: The most architecturally significant part of this library — a micro-framework whose implementation classes automatically register themselves with their factory upon instantiation, eliminating manual registry maintenance and enabling a powerful N × M extensibility pattern described in the documentation below.

The Javadoc API is available here: MgntUtils Javadoc API

Key Features and Utilities

  • Stacktrace Filtering

    One of the most popular features of MgntUtils is advanced stacktrace filtering. The primary API is TextUtils.getStacktrace(), which accepts either a Throwable or a raw String. It removes framework noise (such as application server and library internals), making logs significantly more readable and reducing their size.

    Filtering is configured via a predefined list of relevant package prefixes, allowing you to focus only on application-level code.

    Key capabilities:

    • Filter stacktraces from a Throwable — referred to as "hot filtering"
    • Filter stacktraces from raw String input, such as logs or remote-service output — referred to as "cold filtering"
    • Configurable filtering via relevant package prefixes
    • Collapse irrelevant frames

    Why String-based filtering (cold filtering) matters: Unlike typical solutions that operate only on exceptions, MgntUtils can process raw stacktrace strings. This enables usage beyond in-process error handling:

    • Log processing pipelines
    • Remote stacktrace cleanup
    • Serialized / stored error handling
    • Post-processing of external system outputs

    Infrastructure-level integration: This feature can be integrated transparently into Spring Boot applications without changing existing code.
    See: Zero-Code-Change Stacktrace Filtering for Spring Boot: An Infrastructure-Level Integration.


  • Human-Readable Time Intervals
    The methods TextUtils.parseStringToTimeInterval() and TextUtils.parseStringToDuration() convert strings like "5d", "4h", or "30m" directly into long milliseconds or java.time.Duration values, making time-based configuration far more maintainable than raw numeric values.

  • Unicode Conversion
    The StringUnicodeEncoderDecoder class converts strings to Unicode escape sequences (e.g., Hello → \u0048\u0065\u006c\u006c\u006f) and back. This is useful for debugging encoding issues, handling special characters and emojis, and working with non-Latin scripts such as Hebrew, Arabic, Slavic languages, Chinese, and others.

  • Silent Numeric Parsing
    Utility methods for parsing strings into numeric types (e.g., Integer, Long, Double) without throwing NumberFormatException. Instead, they return a default value or null when parsing fails, avoiding boilerplate try-catch blocks.

  • Version Comparison
    The library provides a Version type and VersionRange support, enabling easy comparison of software versions and checking whether a version falls within a given range. It also supports checking the intersection of version ranges.

  • JSON Parsing
    Simple JSON serialization and deserialization utilities for basic use cases.

  • Web and File Utilities

    • Simple HTTP Client: A lightweight, easy-to-configure HTTP client suitable for repeated calls to the same URLs, such as in microservices communication. Configuration is reusable across multiple calls.
    • HTTP Throttling: WebUtils includes a method for chunked reading of HTTP request content that can auto-throttle to match the client’s consumption speed.
    • File I/O: Basic utilities for reading from and writing to files.

Self-Populating Factory Micro-Framework

All other utilities in this library solve individual, well-defined problems. What follows is different in kind: it is a fundamental architectural pattern and by far the most significant part of this library. It is packaged as a lightweight micro-framework — two classes — that provides the infrastructure for a self-registering factory pattern. The library ships this infrastructure along with a complete, runnable example. The broader architectural pattern it enables — resolving an N × M extensibility problem across multiple data types and processing stages without modifying existing code — is not part of the library itself, but is documented in detail in Infrastructure for Extensible Multi-Stage Workflows Across Multiple Data Types and demonstrated in a separate companion project. This article should be considered required reading alongside this section.

The framework implementation is located in package com.mgnt.lifecycle.management. It provides infrastructure for factories whose components automatically register themselves during initialization — similar in spirit to an Inversion of Control container, but without the framework overhead and with no external dependencies. Implementation classes are factory-aware: this eliminates manual factory-population logic and centralized registration maps entirely — as long as a concrete implementation is instantiated, it becomes available through the factory.

The package-level Javadoc contains a detailed explanation of the design and a complete, runnable example included with the library source.

See the Javadoc for details:
Self-Populating Factory package documentation

Extended Library Documentation

This README and the library Javadoc provide a solid overview of what MgntUtils is and how to start using it. In addition, there is a series of articles about the library and its features that go deeper into each major utility and the Self-Populating Factory pattern. These articles should be treated as integral parts of the library’s documentation and are especially useful for understanding architectural uses and advanced setups.

You can find all of these articles in the Featured section of my LinkedIn profile:
https://www.linkedin.com/in/michael-gantman-9661521/details/featured/

Series-Overview Articles

Feature-Specific Deep Dives

Architectural Design Pattern

  • Infrastructure for Extensible Multi-Stage Workflows Across Multiple Data Types
    This is the most in-depth article in the series and the one most closely tied to the core architectural contribution of this library. It can be viewed as a two-part piece:

    • Part 1 covers the Self-Populating Factory pattern in greater detail and walks through the runnable example included in the library.
    • Part 2 shows how this pattern can be used to build extensible, multi-stage workflows for multiple data types, allowing you to “extend the flow length-wise and width-wise” (i.e., resolve an N × M matrix-like problem) without modifying existing code — just by adding new data types and stages.

    This article underscores the fact that beyond its collection of utilities, this library provides a foundation for a powerful architectural design pattern that can be reused across many projects.

Commercial Adoption

Below are three articles that focus on commercial adoption of the stacktrace filtering feature.

The first two articles relate to and extend the two stacktrace filtering articles mentioned above. The first one documents a live production integration, while the second shows how to evaluate expected benefits before making production changes. The third one documents the real-world use of the stacktrace filtering feature by a third-party project unaffiliated with the library’s author.

  • Cutting AI Token Costs With MgntUtils Stacktrace Filtering
    This is a live production-integration case study. The stacktrace filtering feature was integrated into a live commercial product serving real-world customers. The article presents measured benefits and describes the integration process, including the time and effort involved as well as some non-obvious issues.

  • Verify AI Token Cost Cuts with MgntUtils Stacktrace Filtering on Your Own Data — Before You Touch Production
    This article is based on the stacktrace filtering feature’s support for "cold filtering": the ability to filter a stacktrace String rather than one extracted from a Throwable. It explains how a prospective customer can filter stacktraces taken from their own logs and see the expected results before making any changes to product code. This makes it possible to evaluate the filtering results and estimate its benefits before production integration.

  • MgntUtils Stacktrace Filtering in Real-World Use: The Soffa Project
    This article explores the real-world use of the stacktrace filtering feature by a third-party user - the Soffa project, associated with LaStartupStation, a Morocco-based company. The project used the stacktrace filtering feature for several years (2021–2025), upgrading to newer versions of this library along the way.

Installing MgntUtils

MgntUtils is available on Maven Central:

<dependency>
    <groupId>com.github.michaelgantman</groupId>
    <artifactId>MgntUtils</artifactId>
    <version>1.7.1.0</version>
</dependency>

If you also want Javadoc and sources for your IDE:

<dependency>
    <groupId>com.github.michaelgantman</groupId>
    <artifactId>MgntUtils</artifactId>
    <version>1.7.1.0</version>
    <classifier>javadoc</classifier>
</dependency>
<dependency>
    <groupId>com.github.michaelgantman</groupId>
    <artifactId>MgntUtils</artifactId>
    <version>1.7.1.0</version>
    <classifier>sources</classifier>
</dependency>

If you have any feedback, feel free to drop me a note at michael_gantman@yahoo.com