Solution using Guava goodies.