<commit_before>package de.oetting.kata.chop;

import java.util.List;

public class Chop {

	public <S extends Comparable<S>> int find(List<S> list, S element) {
		if (list.isEmpty())
			return -1;
		int middle = list.size() / 2;
		int comparison = list.get(middle).compareTo(element);
		if (comparison == 0)
			return middle;
		if (comparison < 0)
			return findInBiggerHalf(list, element, middle + 1, middle + 1, list.size() - 1);
		return findInLowerHalf(list, element, middle, 0, middle - 1);
	}
	private <S extends Comparable<S>> int findInBiggerHalf(List<S> list, S element, int pivot, int min, int max) {
		if (max < pivot) {
			return -1;
		}
		int newPivot = (max + pivot) / 2;
		int comparison = list.get(newPivot).compareTo(element);
		if (comparison == 0)
			return newPivot;
		if (comparison < 0)
			return findInBiggerHalf(list, element, newPivot + 1, newPivot + 1, max);
		return findInLowerHalf(list, element, newPivot - 1, min, newPivot - 1);
	}
	
	private <S extends Comparable<S>> int findInLowerHalf(List<S> list, S element, int pivot, int min, int max) {
		if (pivot < min)
			return -1;
		int newPivot = pivot / 2;
		int comparison = list.get(newPivot).compareTo(element);
		if (comparison == 0)
			return newPivot;
		if (comparison < 0)
			return findInBiggerHalf(list, element, newPivot + 1, newPivot + 1, max );
		return findInLowerHalf(list, element, newPivot - 1, min, newPivot - 1);
	}
}<commit_msg>refactoring to always use the same method to find<commit_after>package de.oetting.kata.chop;

import java.util.List;

public class Chop {

	public <S extends Comparable<S>> int find(List<S> list, S element) {
		if (list.isEmpty())
			return -1;
		int middle = list.size() / 2;
		int comparison = list.get(middle).compareTo(element);
		if (comparison == 0)
			return middle;
		if (comparison < 0)
			return find(list, element, middle + 1, middle + 1, list.size() - 1);
		return find(list, element, middle, 0, middle - 1);
	}

	private <S extends Comparable<S>> int find(List<S> list, S element, int pivot, int min, int max) {
		int newPivot = (max + min) / 2;
		if (newPivot < min)
			return -1;
		if (newPivot > max)
			return -1;
		int comparison = list.get(newPivot).compareTo(element);
		if (comparison == 0)
			return newPivot;
		if (comparison < 0)
			return find(list, element, newPivot + 1, newPivot + 1, max);
		return find(list, element, newPivot - 1, min, newPivot - 1);
	}
}
{'fraction_non_alphanumeric': 0.13562836997096642, 'fraction_numerical': 0.01783492326835338, 'mean_word_length': 3.683495145631068, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1884908', 'n_tokens_mistral': 984, 'n_tokens_neox': 850, 'n_words': 270}