I needed a TriFunction

Since Java 8 you can do such nice functional things, I love it. But, for some reason it has Functions and BiFunctions, but no TriFunctions! So, it was time to add the TriFunction interface. And yes, I’m very immature :-P import java.util.Objects; import java.util.function.Function; @FunctionalInterface public interface TriFunction<S, U, C, K> { /** * Applies this function to the given arguments * @param s the first argument * @param u the second arguments * @param c the third argument * @return K */ K apply(S s, U u, C c); /** * Returns a composed function that first applies this function to its input * and then applies the {@code after} function to the result. * * If evaluation of either function throws an exception, it is relayed to * the caller of the composed function. * @param <T> * @param after * @return */ default <T> TriFunction<S, U, C, T> andThen(Function<? super K, ? extends T> after) { Objects.requireNonNull(after); return (S s, U u, C c) -> after.apply(apply(s, u, c)); } } ...

December 21, 2016 · 2 min · 224 words · Sir

Fixing ORD fields in Oracle

If you use Hibernate and ordered list, you’re probably familiar with having to add a column to retain the order. If you don’t want nulls in your list, you sometimes need to reorder this (say, for instance, if you manually remove an item from a list via the database). Of course, you can do an update to “set ord = ord - 1 where ord = ” and continue doing so until you have the items nicely sequenced again. But if you have Oracle*, you can use the row_number() feature ...

March 11, 2015 · 2 min · 227 words · Sir

Doing Enums with Jackson

Recently I’ve been working on a Jersey 2 application (a JAX-RS REST) using JSON. For the JSON serialization and deserialization I’ve chosen to use the Jackson framework. One of the reasons for this is that prior we’ve been using Freemarker templates, but if you use those, you can easily create invalid JSON which will eventually screw up your clients. Using Jackson & Jersey allow me to skip the entire Object graph to template to output chain and simply use POJOs and use annotations to model the JSON request and responses. ...

March 21, 2014 · 3 min · 567 words · Sir

Writing your own maven plugin

As some of you may know, I’m currently working on the WCMS project at the Australian Broadcasting Corporation. This is a large, multi-year project to replace the old web content management system with a brand new (Java) CoreMedia system which will allow the ABC to grow it’s online presence even further. As with most java based systems, we use maven to support building the project. And we use many of the plugins that are out there to do specific tasks, for instance the maven-config-processor-plugin to create the various configurations for each of the target platforms, but also the maven-shade-plugin to change some .class files in specific jars. ...

October 4, 2010 · 6 min · 1131 words · Sir