This section provides code extracts, from individual methods to classes and full packages. The intention is to provide examples of some specific code I have written which I think is note-worthy in some way, and to comment on the relative merits of the approach I took.
I do have to caveat that I currently favor using unchecked exceptions; what this means is that my exceptions subclass RuntimeException, and none of my methods have throws clauses. I apologize if that rankles you, but know that I do constantly wrestle with this decision on a theoretical level. However, with over 3,000 java classes behind me and several significant systems in production, I find unchecked exceptions actually work in practice on large projects. But in all honesty, I have not tried checked exceptions on any large scale.
Code follows in the order posted; the right side index lists the code by basic category and in alphabetical order.
License & Disclaimer
All code published in this section is licensed for any use without restriction provided that the source file retains my copyright notice as credit. All code is provided as is, without warranty of any kind; the author accepts no liability for any loss of any kind which results from the use of this code.
Math Evaluator (Java) back to top
This math expression evaluator was born out of a need to have a small-footprint and efficient solution which could evaluate arbitrary expressions reasonably efficiently without requiring pre-compilation. I needed something which would do basic math with variables, expressions like: “Top+2”, “Bottom-2” and “(Right+1-Left)/2”.
Table Oriented Layout Manager (Java) back to top
A long time ago, in a land far, far away… (from New Zealand) I was writing a GUI in Java. After about 7 levels of nesting I began to think that I was missing something critical - that there had to be an easier way. Don’t get me wrong, I love Java’s concept of resizeable flowing layouts (I cannot count the number of times I have had to deal with a Windows O/S dialog on my 1920x1200 screen utilizing about 10% of my available real estate with a little teeny tiny listbox in the middle showing 9 of the 2700 files I am sifting through). But there just has to be a better way!
Linked-list / Binary-tree Combination (Java) back to top
This class set is a combined linked-list and binary-tree map implementation. It was originally designed around about 2000 or 2001. Since then it has gone through several refactorings to arrive in the final form, each time with the desire to obtain added function while adhering to the DRY principle.
Most-Recently-Used Cache (Java) back to top
This class is a very simple MRU cache based on my LinkedTree implementation. It serves as a working example of the use of the linked tree. However, do note that it does not leverage one of the most powerful attributes of the tree, which is the ability to position to and navigate from specific nodes by exact and closest-match keys.
Callback Method Support for Java 2+ (Java) back to top
One of the things I really miss when programming in Java is function callbacks. One situation where the need for these kept presenting itself was in recursively processing hierarchies where you want to perform some specific action for each item. Like walking a directory tree, or processing a data structure. The minimalist inside me hated to have to define an interface and then an implementation for each specific case.
A Compact Pull Parser for JSON (Java) back to top
This is another situation where I needed something leaner than what I could find on the Internet, and I found myself lying awake one early morning wondering, “how hard could it be?”. Written from about 3 am to 10 am, this parser is efficient, lean and functional.
16 bit CRC (C) back to top
This is an C module from ages ago for calculating a 16 bit CRC. As far as I can recall it is compatible with the ancient X-Modem file transfer protocol… but I wouldn’t want to bet my life, my wife and my wallet on it. I used it for years as a checksum for a modem communications protocol and it worked really well in that context.
32 bit CRC (C) back to top
This is an C module from ages ago for calculating a 32 bit CRC. As far as I can recall it is compatible with the ancient Z-Modem file transfer protocol… but I wouldn’t want to bet my life, my wife and my wallet on it. I used it for years as a checksum for a modem communications protocol and it worked really well in that context.
A Cyclic Object Sharing Pool (Java) back to top
I created this class in response to a question on StackOverflow.com. The question was regarding the most efficient way to use Java
DataFormat objects when you have many short-lived threads and no per-logical-thread context which survives
the life of a Java thread.