That's basically my first touch with Java generic types and I can't figure out what is wrong with the following piece of code.
I have a helper class Helper with a static function inRange usng generic type that should return the list of objects from an input list that are in certain range around object at index index (I haven't tested it yet, it's not an issue here if it works correctly or not):
public class Helper {
public static List inRange(List list, int index, int range) {
List res = new ArrayList();
int N = list.size();
assert(index < N);
if (N == 0)
return res;
int i, j;
/* right range */
i = (index + 1) % N;
j = 0;
while (i != index && j < range) {
res.add(list.get(i));
i = (i &