Today JavaPolis really started. The first and second day are filled with university sessions and tools in action sessions. University sessions are 3 hours with a small break, so there's time for two. At the end of the day there is time for two tools in action sessions, which take about half an hour each. The first session started at 9.30, which gave us the ability to get a good night of sleep.
The first university session I choose to go to was Java generics and collections in action. The speaker was Maurice Naftalin. The second talk was Google API's, presented by Dick Wall of Google. You probably know him from the JavaPosse. Dick is a great speaker and I really enjoyed this session. After six hours of talk about (Google) collections, generics and Google data API's, it was time for two talks about continuous integration. The first one by Mark Chaimungkalanont was about Bamboo, created by Atlassian, the second one by Mike Aizatski about Teamcity created by JetBrains. What I really liked about Teamcity was the solution to prevent broken builds. Normally a CI server checks code out, then starts to build. With Teamcity you present your code to Teamcity, then it builds, and only if the build succeeds it gets committed to the SCM. Quite an interesting approach. The thing that really interested me about Bamboo was the metrics comparison between similar projects. After all, metrics say the most if you can compare it to something similar.
I will talk a bit more about Dick Wall's talk. I won't get into much technical detail, because I don't have much time during this week, but I know for sure I will play around with the Google Collections Library. The bad thing about generic collections is the way you have to declare them, for example:
Map<Integer,String> myList = new HashMap<Integer,String>();
You are copying code on one line, but it is necessary because at runtime Java cannot get the types of the declared variable. The collection library provides us with Convenience Creators, an easier way to declare generic collections:
Map<Integer,String> myList = Maps.newHashMap();
This actually works and it much easier to write. All collection class implementations have a convenience creator. Another nice feature the collections library provides are Immutable Collections, I won't go in detail here, you can guess what it does :).
How many times did you wanted to have a map with lists in it?
Something like:
Map<String,List<Integer>> map = new Hashmap<String, List<Integer>>();
public void add(String key, Integer value) {
List<Integer> list = map.get(key);
if (list == null) {
list = new ArrayList<Integer>();
list.put(key, list);
}
map.add(value);
}
This is quite cumbersome, that's why Google made the Multimap.
Multimap<String, Integer> multimap = Multimaps.newArrayListMultimap();
public void add(String key, Integer value) {
multimap.put(key, value);
}
That's a lot better. There is also an Multiset. Another interesting new collection class is the ReferenceMap. Basically this replaces the WeakHashMap, and introduces all combinations of weak, soft and hard references. This makes this class good for in memory caching strategies. Then there is the BiMap, where not only the keys are unique, the values are too, so you can reverse the map.
Google also added Predicates, Functions and Constraints to the collections library. These classes are based on functional programming concepts. For example you can put a constraint on what values a list can accept, or a predicate to get a sublist from a list based on some condition. You can read more of this at the Google Collections Library website.
Recent Comments