Somehow I imagine this would be great to solve with recursion - something like this:
/**
* check if the lemmas are listed in alphabetic order. If not, remove fake lemmas.
* @param lemmings
* @param finished
* @return correct lemma-list
*/private List<String> checkingLemmas(List<String> lemmings, ArrayList<String> finished){
if(isSorted(lemmings))
return lemmings;
if(lemmings.size() == 2){
//what to do here?
// I don't have anything to compare to anymore so I don't know which of the two to remove.
//went too far...
}
if(lemmings.size() == 3){
ArrayList<String> x = new ArrayList<String>();
x.add(lemmings.get(0));
x.add(lemmings.get(lemmings.size()-1));
}
List<String> list1 = lemmings.subList(0, (lemmings.size()/2));
List<String> list2 = lemmings.subList((lemmings.size()/2), (lemmings.size()-1));
if(isSorted(list1)){
finished.addAll(list1);
Collections.sort(finished);
}
else if(!isSorted(list1)){
finished.addAll(checkingLemmas(list1, finished));
}
if(isSorted(list2)){
finished.addAll(list2);
Collections.sort(finished);
}
else if(!isSorted(list2)){
finished.addAll(checkingLemmas(list2, finished));
}
return finished;
}