<commit_before>package com.otus.alexeenko.l3;

import java.util.*;

/**
 * Created by Vsevolod on 18/04/2017.
 */

public class MyArrayList<T> implements List<T>, RandomAccess, Cloneable, java.io.Serializable {

    private static final long serialVersionUID = -3056234432889222545L;

    private static final int DEFAULT_SIZE = 16;

    private int size;

    private int capacity;

    private Object array[];

    public MyArrayList() {
        this.array = new Object[DEFAULT_SIZE];
        capacity = DEFAULT_SIZE;
    }

    public MyArrayList(int capacity) {
        this.array = new Object[capacity];
        this.capacity = capacity;
    }

    @Override
    public int size() {
        return size;
    }

    @Override
    public boolean isEmpty() {
        return size == 0;
    }

    @Override
    public boolean contains(Object o) {
        return indexOf(o) > -1;
    }

    @Override
    public Iterator<T> iterator() {
        return listIterator();
    }

    @Override
    public Object[] toArray() {
        Object[] returnArray = new Object[size];
        System.arraycopy(array, 0, returnArray, 0, size);
        return returnArray;
    }

    @Override
    @SuppressWarnings("unchecked")
    public <T1> T1[] toArray(T1[] a) {
        if (a.length < size)
            // Make a new array of a's runtime type, but my contents:
            return (T1[]) Arrays.copyOf(array, size, a.getClass());
        System.arraycopy(array, 0, a, 0, size);
        if (a.length > size)
            a[size] = null;
        return a;
    }

    @Override
    public boolean add(T t) {
        checkCapacity(1);
        array[size++] = t;
        return true;
    }

    @Override
    public boolean remove(Object o) {
        int index;

        if ((index = indexOf(o)) > -1) {
            internalRemove(index);
            return true;
        }
        return false;
    }

    @Override
    public boolean containsAll(Collection<?> c) {
        return false;
    }

    @Override
    public boolean addAll(Collection<? extends T> c) {
        Object[] a = c.toArray();
        int numNew = a.length;
        checkCapacity(size + numNew);  // Increments modCount
        System.arraycopy(a, 0, array, size, numNew);
        size += numNew;
        return numNew != 0;
    }

    @Override
    public boolean addAll(int index, Collection<? extends T> c) {
        rangeCheck(index);

        Object[] a = c.toArray();
        int numNew = a.length;
        checkCapacity(size + numNew);  // Increments modCount

        int different = size - index;
        if (different > 0)
            System.arraycopy(array, index, array, index + numNew,
                    different);

        System.arraycopy(a, 0, array, index, numNew);
        size += numNew;
        return numNew != 0;
    }

    @Override
    public boolean removeAll(Collection<?> c) {
        return false;
    }

    @Override
    public boolean retainAll(Collection<?> c) {
        return false;
    }

    @Override
    public void clear() {
        capacity = capacity + size;
        size = 0;

        array = new Object[DEFAULT_SIZE];
    }

    @Override
    public T get(int index) {
        rangeCheck(index);
        return getElement(index);
    }

    @Override
    public T set(int index, T element) {
        rangeCheck(index);

        T oldValue = getElement(index);
        array[index] = element;
        return oldValue;
    }<commit_msg>L3 Release 3<commit_after>package com.otus.alexeenko.l3;

import java.util.*;

/**
 * Created by Vsevolod on 18/04/2017.
 */

public class MyArrayList<T> implements List<T>, RandomAccess, Cloneable, java.io.Serializable {

    private static final long serialVersionUID = -3056234432889222545L;

    private static final int DEFAULT_SIZE = 16;

    private int size;

    private int capacity;

    private Object array[];

    public MyArrayList() {
        this.array = new Object[DEFAULT_SIZE];
        capacity = DEFAULT_SIZE;
    }

    public MyArrayList(int capacity) {
        this.array = new Object[capacity];
        this.capacity = capacity;
    }

    @Override
    public int size() {
        return size;
    }

    @Override
    public boolean isEmpty() {
        return size == 0;
    }

    @Override
    public boolean contains(Object o) {
        return indexOf(o) > -1;
    }

    @Override
    public Iterator<T> iterator() {
        return listIterator();
    }

    @Override
    public Object[] toArray() {
        Object[] returnArray = new Object[size];
        System.arraycopy(array, 0, returnArray, 0, size);
        return returnArray;
    }

    @Override
    @SuppressWarnings("unchecked")
    public <T1> T1[] toArray(T1[] a) {
        if (a.length < size)
            // Make a new array of a's runtime type, but my contents:
            return (T1[]) Arrays.copyOf(array, size, a.getClass());
        System.arraycopy(array, 0, a, 0, size);
        if (a.length > size)
            a[size] = null;
        return a;
    }

    @Override
    public boolean add(T t) {
        checkCapacity(1);
        array[size++] = t;
        return true;
    }

    @Override
    public boolean remove(Object o) {
        int index;

        if ((index = indexOf(o)) > -1) {
            internalRemove(index);
            return true;
        }
        return false;
    }

    @Override
    public boolean containsAll(Collection<?> c) {
        return false;
    }

    @Override
    public boolean addAll(Collection<? extends T> c) {
        Object[] a = c.toArray();
        int numNew = a.length;
        checkCapacity(size + numNew);  // Change capacity
        System.arraycopy(a, 0, array, size, numNew);
        size += numNew;
        return numNew != 0;
    }

    @Override
    public boolean addAll(int index, Collection<? extends T> c) {
        rangeCheck(index);

        Object[] a = c.toArray();
        int numNew = a.length;
        checkCapacity(size + numNew);  // Change capacity

        int different = size - index;
        if (different > 0)
            System.arraycopy(array, index, array, index + numNew,
                    different);

        System.arraycopy(a, 0, array, index, numNew);
        size += numNew;
        return numNew != 0;
    }

    @Override
    public boolean removeAll(Collection<?> c) {
        return false;
    }

    @Override
    public boolean retainAll(Collection<?> c) {
        return false;
    }

    @Override
    public void clear() {
        capacity = DEFAULT_SIZE;
        size = 0;

        array = new Object[DEFAULT_SIZE];
    }

    @Override
    public T get(int index) {
        rangeCheck(index);
        return getElement(index);
    }

    @Override
    public T set(int index, T element) {
        rangeCheck(index);

        T oldValue = getElement(index);
        array[index] = element;
        return oldValue;
    }
{'fraction_non_alphanumeric': 0.10953908984830805, 'fraction_numerical': 0.014294049008168028, 'mean_word_length': 1.9696838458207016, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, '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': '4149693', 'n_tokens_mistral': 2097, 'n_tokens_neox': 1984, 'n_words': 571}