Null Aware Built-In Handling 

As soon as the handling of optional values is built into FreshMarker, another interesting feature appears, which could be added with tiny changes. It was implemented in three steps, with the next step only becoming apparent once the previous step had been implemented. The whole thing started with the fact that empty optionals should be processed slightly differently than null values.

FreshMarker with Optionals

Agile software development is characterized, among other things, by the fact that features are developed on demand. This is one of the reasons why some features are not available in FreshMarker or are only added very late. Examples of late additions are the Include- and Import-Directives and the support of the StringBuilder and StringBuffer data types. For the former, the use case was not planned at the start of development and for the latter, support was simply forgotten. Another forgotten data type is the Optional class, which is now finally to be supported.

Optionales einsammeln

Die Verwendung der Optional Klasse für API Rückgabewerte, macht viele Dinge bei der Verwendung einer API sehr viel einfacher. Beispiele dafür gab es ja schon in dem Beitrag Befreit die APIs von Nullen. Manches mal sorgt der Optional als Rückgabewert für Verdruss. Im folgenden Beispiel sollen alle Väter der Personen aus der Liste eingesammelt werden. … Read more

Optionals für Methodenketten

It is a mistake to look too far ahead. Only one link of the chain of destiny can be handled at a time. Winston Churchill Obwohl das Law Of Demeter den folgenden Aufruf zu Recht verteufelt, hat man es, in der holprigen Projektwelt, immer wieder mal mit solchen Verkettungen zu tun. In diesem Beispiel kennt … Read more

Optional Matchers for Hamcrest

Manchmal benötigt man ein kleines Feature, das so schnell aus den Fingern fließt, dass die Zeit nicht lohnt, nach existierenden Lösungen zu suchen. Wie enttäuscht war ich da, als ich beim Schreiben dieses Beitrags etwas ähnliches auf GitHub fand.

Befreit die APIs von Nullen

In vielen Schnittstellen werden noch immer null Werte zurück geliefert. Das führt zu aufwendigen Code in der eigenen Anwendung, da alle Rückgabewerte auf null geprüft werden müssen. Dieses Beispiel prüft, ob der Name des Vaters gesetzt ist und nicht leer ist. Dabei müssen die Rückgabewerte zwei mal geprüft werden, da sonst ggf. eine NullPointerException geworfen wird. … Read more