Home » Archives for Gerard Davison

Author Archives: Gerard Davison

In JDK 9 (and well 8) and above everything can be a stream

In JDK 8 we finally got to use streams and everything was good apart from the times when the API you used couldn’t produce a stream. Then you ended up writing a wrapper class method that allowed you to convert an iterator into a Stream, because you missed streams. public static <T> Stream<T> asStream(Iterator<T> it) { return StreamSupport.stream(Spliterators.spliteratorUnknownSize(it, Spliterator.IMMUTABLE | ...

Read More »

Converting string configuration properties to other types, with a bit of Optional

Somedays you come across some code and think that’s pretty, why didn’t I think of that? So my long time colleague Mark Warner has a nice twist on the standard name/value store pattern using method references to deal with converting from a String. int size = store.getProperty("cache.limit", 500, Integer::parseInt); boolean enabled = store.getProperty("cache.enabled", true, Boolean::getBoolean); I took his example and ...

Read More »

Lambda of Lambda, if/else from an Optional

So I got frustrated with two limitations of the Optional interface in JDK 8. The first problem is that there is no obvious way to perform an else operation in a block as there is only a isPresent method unless you are using an old school if statement. The second problem is of course the old chestnut that even if ...

Read More »

Per client cookie handling with Jersey

A lot of REST services will use cookies as part of the authentication / authorisation scheme. This is a problem because by default the old Jersey client will use the singleton CookieHandler.getDefault which is most cases will be null and if not null will not likely work in a multithreaded server environment. (This is because in the background the default ...

Read More »

Declarative Linking in Jersey 2.9 and up

java-interview-questions-answers

A couple of weeks ago A couple of months ago I was looking how I was going to engineers new REST API for an Oracle Cloud project. Once of the things I had planned to do was to use the declarative link injection created in Jersey 1.x by Marc Hadley. Sadly this hadn’t been forwarded ported yet, so a quick ...

Read More »