int groundLimitIndex = (int) Math.ceil(otherStudents.size() * (limits[i - 1] / 100.0));
int groundLimitIndex = Math.min(otherStudents.size() - 1, (int) Math.ceil(otherStudents.size() * (limits[i - 1] / 100.0)));
    private HashMap<Character, List<Registration>> splitStudentsByClassification(Integer[] limits,            List<Registration> students, String field, Transformer fieldGetter, Closure fieldSetter) {        HashMap<Character, List<Registration>> studentsClassifications = new HashMap<Character, List<Registration>>(                limits.length);        Collections.sort(students, new BeanComparator(field));                List<Registration> weakStudents = new ArrayList<Registration>();        for (Registration registration : students) {            if(((Double) fieldGetter.transform(registration)) == 0.0){                weakStudents.add(registration);                fieldSetter.execute(new GenericPair<Registration, Character>(registration, 'F'));            }        }        studentsClassifications.put('F', weakStudents);        List<Registration> otherStudents = new ArrayList<Registration>(students);         otherStudents.removeAll(weakStudents);        char classification = 'A';        ListIterator<Registration> studentsIter = otherStudents.listIterator(otherStudents.size());        for (int i = limits.length - 1; i > 0; i--) {            int groundLimitIndex = (int) Math.ceil(otherStudents.size() * (limits[i - 1] / 100.0));            Double groundLimitValue = (Double) fieldGetter.transform(otherStudents.get(groundLimitIndex));                        Double  maxValue = (Double) fieldGetter.transform(otherStudents.get(otherStudents.size() - 1));            if(maxValue.equals(groundLimitValue)){                groundLimitValue -= 0.0000000001;            }                        int limitIndex = studentsIter.previousIndex() + 1;            for (Registration registration = studentsIter.previous(); (Double) fieldGetter.transform(registration) > groundLimitValue; registration = studentsIter                    .previous()) {                fieldSetter.execute(new GenericPair<Registration, Character>(registration, classification));            }            studentsIter.next();            groundLimitIndex = studentsIter.nextIndex();            studentsClassifications.put(classification, otherStudents.subList(groundLimitIndex, limitIndex));            classification++;        }                List<Registration> lastStudents = otherStudents.subList((int) Math.ceil(otherStudents.size()                * (limits[0] / 100.0)), studentsIter.nextIndex());        for (Registration lastStudent : lastStudents) {            fieldSetter.execute(new GenericPair<Registration, Character>(lastStudent, 'E'));        }        List<Registration> allLastStudents = new ArrayList<Registration>(lastStudents);        allLastStudents.addAll(studentsClassifications.get('E'));        studentsClassifications.put('E', allLastStudents);         return studentsClassifications;    }