Good programming practices

Java

Simple SGML parser

October 30th, 2011

There exists many parsing libraries for XML, HTML and SGML. Sometimes it’s enough to use simple solution instead of whole library. I created 4 classes for parsing string into list of markups and plain text. The parser use regular expressions for extracting all elements. More…

Iterating over non null elements only

October 27th, 2011

Since Java 5 in this language exists very useful “foreach” statement. But if collection contains null elements, iterator will also return null. If code doesn’t check against null, this may cause a NullPointerException. So I made a simple class based on Decorator Design Pattern. It just wraps an Iterable or Iterator and return only non null values. More…

Java code conditional compilation

September 8th, 2011

Java language doesn’t have a preprocessor like C. But compiler optimize the code – if it’s sure, that code can’t be reached, it will not be included in the output byte code. An optional code can be placed inside if statement or by tertiary statement, where condition can be evaluated by compiler. More…