sebastiandaschner news


monday, january 08, 2018

A Hacky New Year to all of you and welcome to Newsletter #18 in 2018 :-)

After visiting the beautiful and exciting island of Java I could spend some relaxed days over Christmas with my family. These days are usually the quietest in the year without conferences and business-related traveling — perfect for some hacking just for fun :-)

I’m also very excited for the first jSpirit, held at the end of this week in snowy Bavaria. For me unconferences are among the most inspiring experiences, with a lot of interesting people coming together and philosophizing about technology, work-life balances, and other random topics. And yes, it helps to hold these events at exciting locations, such as islands or distilleries :-) If you feel like you want to start your year with an additional inspiration boost and you’re quick, you can still join us!

For now, the conference season and plannings for 2018 slowly emerge. I’m happy to announce that I will speak on the following events:

  • Index — San Francisco, February

  • DevNexus — Atlanta, February

  • JBreak; — Novosibirsk, March

  • JavaLand — Brühl, March

  • Voxxed Days Bucharest — Bucharest, March

I can’t wait to start the conference season again :-) Expect content about Java EE, containers, Kubernetes, Effective enterprise testing, productive software development and CQRS!

For this year, I also want to try to combine my conference-related travels with client engagements. If you’re interested in workshops or “problem-solving sprints”, or you know some company or team that might be, you can check my offerings on my website.

 

What’s new

 

EnumSet for enum collections

In the last newsletter issue we discovered EnumMaps for mappings with enum keys. Well, you might have observed that there is also a specialized Set that is optimized for enums: EnumSet.

We once again define a CoffeeType enum:

public enum CoffeeType {
    ESPRESSO, POUR_OVER, FRENCH_PRESS, LATTE, FLAT_WHITE
}

Now we can create sets of this enum type, by using the EnumSet implementation:

Set<CoffeeType> favoriteCoffeeTypes = EnumSet.of(ESPRESSO, POUR_OVER, LATTE);

assertThat(favoriteCoffeeTypes).containsOnly(ESPRESSO, POUR_OVER, LATTE);

The favoriteCoffeeTypes still acts like any Set, that is, adding duplicates won’t change its contents:

favoriteCoffeeTypes.add(POUR_OVER);

assertThat(favoriteCoffeeTypes).containsOnly(ESPRESSO, POUR_OVER, LATTE);

Interesting side note: If you look into the JDK, you’ll see that EnumSet is implemented by both RegularEnumSet and JumboEnumSet; the number of enum elements determines the implementation being used. If you’re interested in how the EnumSet implementation manage to be highly efficient, I challenge you to have a look into these classes. Hint: Bitwise operations :-)

 

Custom domain resolution with curl

The curl command line tool is widely used to access HTTP(S) resources. Quite often you might use it to test SSL-secured services that aren’t available via a DNS lookup (yet). You can access the services directly via their IP address and Host HTTP header — what usually results in an SSL certificate error:

curl --insecure https://8.8.8.8/ -H 'Host: www.sebastian-daschner.com'

Another way is to let curl make a custom lookup by specifying the desired target including the host name via the --resolve flag:

curl https://www.sebastian-daschner.com --resolve www.sebastian-daschner.com:443:8.8.8.8

Now curl will access the service using SSL directly via the given IP address. If your used SSL certificate is valid for the domain, your SSL check won’t fail and you won’t need the --insecure or -k flags anymore.

 

Thanks a lot for reading and see you next time!

 

Did you like the content? You can subscribe to the newsletter for free: