Algorithms with Java Generics