<commit_before>package io.doist.recyclerviewext.animations;

import java.util.ArrayList;
import java.util.List;

class Utils {
    public static boolean equals(Object a, Object b) {
        if (a == b) {
            return true;
        } else if (a != null) {
            return a.equals(b);
        } else {
            return false;
        }
    }

    /**
     * Similar to {@link ArrayList#indexOf(Object)}, but starts the search in a specific position going back and forth,
     * hence being optimized for collections that don't change a lot.
     */
    public static int indexOf(List<Object> list, Object object, int startPosition) {
        int size = list.size();
        // Search back and forth until one of the ends is hit.
        for (int i = startPosition, j = 0; i >= 0 && i < size; j++, i += j % 2 == 0 ? j : -j) {
            if (equals(object, list.get(i))) {
                return i;
            }
        }
        if (startPosition < list.size() / 2) {
            // Search forward if the head was hit.
            for (int i = startPosition * 2 + 1; i < size; i++) {
                if (equals(object, list.get(i))) {
                    return i;
                }
            }
        } else if (startPosition > list.size() / 2) {
            // Search backward if the tail was hit.
            for (int i = size - (size - startPosition) * 2 - 1; i >= 0; i--) {
                if (equals(object, list.get(i))) {
                    return i;
                }
            }
        }
        return -1;
    }
}<commit_msg>Account for startPosition > size in indexOf()<commit_after>package io.doist.recyclerviewext.animations;

import java.util.ArrayList;
import java.util.List;

class Utils {
    public static boolean equals(Object a, Object b) {
        if (a == b) {
            return true;
        } else if (a != null) {
            return a.equals(b);
        } else {
            return false;
        }
    }

    /**
     * Similar to {@link ArrayList#indexOf(Object)}, but starts the search in a specific position going back and forth,
     * hence being optimized for collections that don't change a lot.
     */
    public static int indexOf(List<Object> list, Object object, int startPosition) {
        int size = list.size();
        // Search back and forth until one of the ends is hit.
        for (int i = startPosition, j = 0; i >= 0 && i < size; j++, i += j % 2 == 0 ? j : -j) {
            if (equals(object, list.get(i))) {
                return i;
            }
        }
        if (startPosition < size / 2) {
            // Search forward if the head was hit.
            for (int i = startPosition * 2 + 1; i < size; i++) {
                if (equals(object, list.get(i))) {
                    return i;
                }
            }
        } else if (startPosition > size / 2) {
            // Search backward if the tail was hit.
            for (int i = size - (size - Math.max(startPosition, size)) * 2 - 1; i >= 0; i--) {
                if (equals(object, list.get(i))) {
                    return i;
                }
            }
        }
        return -1;
    }
}
{'fraction_non_alphanumeric': 0.11871419478039465, 'fraction_numerical': 0.0076384468491406746, 'mean_word_length': 1.453551912568306, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, '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': '6273570', 'n_tokens_mistral': 926, 'n_tokens_neox': 882, 'n_words': 316}