I wanted a simple pattern for preventing a class from being instantiated in an invalid state, or from mutating into one.
Why? Because it vastly reduces the amount and complexity of reasoning required for use at client call-sites.
Think of it as “integrity by design”, a compliment to the “integrity by default” effort undertaken by the Java architects, detailed here.
This article discusses the design and implementation of a record pattern, very similar to the one I designed and implemented for Scala’s case class several years ago, which provides the “integrity by design” guarantees by ensuring that only valid record instances can be observed.
This pattern is also trivially cross-applicable to Java classes.
BTW, the solution I provided in my library already does exactly what you are describing in terms of not needing to instrument each enum class.
The high value of your response, to me, is discovering I can replace my custom "Memoizer" mechanism with a platform-provided (and therefore superior to my custom code) solution with java.lang.ClassValue.
I wanted ease of use and comfort methods when using Java’s legacy Enum. Like resolving a value by its case-insensitive name or ordinal. Or easily, flexibly, and quickly, pretty-printing (a subset of) the Enum’s values, again by name and/or ordinal.
As old as Java’s Enum is, I think it’s absolutely fantastic. I just wanted to increase its fantastic-ness!
After searching for a SQL Server TSQL implementation of Geohash types and conversion functions, I finally just went and wrote a whole open-source library myself.
I designed it for maximum accuracy, performance, and strong conversion consistency guarantees. It enables an average IT data warehouse analyst or report writer to efficiently use, process, and leverage simple GIS spatial proximity models and queries. Given the steep learning curve of finding and adopting a full GIS style solution for data-science/big-data/data-analytics, this library can enable a temporary or good-enough solution until new requirements require investing in a more fleshed out GIS solution like Mapbox, ESRI, etc.
The library provides two Geohash implementation types; Integer (BIGINT) and String (VARCHAR). It also provides two coordinate types; Longitude+Latitude and DMS. And then it provides the conversions to and from these various types. It also provides conversions to/from the SQL Server spatial geography Point type.
Please see the extensive README.md for detailed information.
Wouldn't it be kind of like "DNS for locations" where any string phrase could be associated with the OLC/Plus Code (many human descriptive names to one location identifier)? Better, what if you could then universally translate between that and the many other kinds of location encodings, both human descriptive and computer identifier?
That's what we do at QA Locate with our LNS (Location Naming Service) and our ULT (Universal Location Translator). See our technical two pagers located here: https://www.qalocate.com/resources/
Why? Because it vastly reduces the amount and complexity of reasoning required for use at client call-sites.
Think of it as “integrity by design”, a compliment to the “integrity by default” effort undertaken by the Java architects, detailed here.
This article discusses the design and implementation of a record pattern, very similar to the one I designed and implemented for Scala’s case class several years ago, which provides the “integrity by design” guarantees by ensuring that only valid record instances can be observed.
This pattern is also trivially cross-applicable to Java classes.