<commit_before>package com.dexode.adapter;

import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by <NAME> aka Gelldur on 14.04.16.
 */
public class RecyclerAdapterCommandManager {

	public RecyclerAdapterCommandManager(final AdapterWrapper adapterWrapper) {
		_adapter = adapterWrapper;
	}

	public RecyclerAdapterCommandManager(final RecyclerView.Adapter adapter) {
		_adapter = new AdapterWrapper() {
			@Override
			public void notifyItemInserted(final int position) {
				adapter.notifyItemInserted(position);
			}

			@Override
			public void notifyItemChanged(final int position) {
				adapter.notifyItemChanged(position);
			}

			@Override
			public void notifyItemRangeInserted(final int position, final int count) {
				adapter.notifyItemRangeInserted(position, count);
			}

			@Override
			public void notifyItemRemoved(final int position) {
				adapter.notifyItemRemoved(position);
			}

			@Override
			public void notifyItemRangeRemoved(final int position, final int count) {
				adapter.notifyItemRangeRemoved(position, count);
			}

			@Override
			public void notifyDataSetChanged() {
				adapter.notifyDataSetChanged();
			}

			@Override
			public void notifyItemMoved(final int fromPosition, final int toPosition) {
				adapter.notifyItemMoved(fromPosition, toPosition);
			}
		};
	}

	public void pushBackOne(final int id) {
		checkStartChanges();
		_changes.add(id);
	}

	public void pushBackAll(final ArrayList<Integer> ids) {
		checkStartChanges();
		_changes.addAll(ids);
	}

	public void insert(int position, final int id) {
		checkStartChanges();
		_changes.add(position, id);
	}

	public void remove(int position) {
		checkStartChanges();
		_changes.remove(position);
	}

	public void reset() {
		checkStartChanges();
		_changes.clear();
		_updates.clear();
	}

	public void update(final int position, final int id) {
		_updates.add(id);
	}

	public void commit() {
		commit(false);
	}

	public void commit(boolean skipProcessing) {
		skipProcessing = _stable.isEmpty() || skipProcessing;
		if (skipProcessing) {
			_stable = _changes;
			_updates.clear();
			_adapter.notifyDataSetChanged();
			return;
		}

		if (_changes != null) {
			process();
			_stable = _changes;
		}

		_changes = null;
		for (Integer updateId : _updates) {
			final int position = _stable.indexOf(updateId);
			if (position > 0) {
				_adapter.notifyItemChanged(position);
			}
		}
		_updates.clear();
	}

	private void process() {
		ArrayList<Range> inserted = new ArrayList<>(32);
		ArrayList<Range> removed = new ArrayList<>(32);
		ArrayList<Integer> processed = new ArrayList<>(_stable);

		int offset = 0;
		//Search for removed<commit_msg>Fix RecyclerAdapter command manager<commit_after>package com.dexode.adapter;

import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by <NAME> aka Gelldur on 14.04.16.
 */
public class RecyclerAdapterCommandManager {

	public RecyclerAdapterCommandManager(final AdapterWrapper adapterWrapper) {
		_adapter = adapterWrapper;
	}

	public RecyclerAdapterCommandManager(final RecyclerView.Adapter adapter) {
		_adapter = new AdapterWrapper() {
			@Override
			public void notifyItemInserted(final int position) {
				adapter.notifyItemInserted(position);
			}

			@Override
			public void notifyItemChanged(final int position) {
				adapter.notifyItemChanged(position);
			}

			@Override
			public void notifyItemRangeInserted(final int position, final int count) {
				adapter.notifyItemRangeInserted(position, count);
			}

			@Override
			public void notifyItemRemoved(final int position) {
				adapter.notifyItemRemoved(position);
			}

			@Override
			public void notifyItemRangeRemoved(final int position, final int count) {
				adapter.notifyItemRangeRemoved(position, count);
			}

			@Override
			public void notifyDataSetChanged() {
				adapter.notifyDataSetChanged();
			}

			@Override
			public void notifyItemMoved(final int fromPosition, final int toPosition) {
				adapter.notifyItemMoved(fromPosition, toPosition);
			}
		};
	}

	public void pushBackOne(final int id) {
		checkStartChanges();
		_changes.add(id);
	}

	public void pushBackAll(final ArrayList<Integer> ids) {
		checkStartChanges();
		_changes.addAll(ids);
	}

	public void insert(int position, final int id) {
		checkStartChanges();
		_changes.add(position, id);
	}

	public void remove(int position) {
		checkStartChanges();
		_changes.remove(position);
	}

	public void reset() {
		checkStartChanges();
		_changes.clear();
		_updates.clear();
	}

	public void update(final int position, final int id) {
		_updates.add(id);
	}

	public void commit() {
		commit(false);
	}

	public void commit(boolean skipProcessing) {
		skipProcessing = _stable.isEmpty() || skipProcessing;
		if (skipProcessing) {
			_stable = _changes;
			_changes = null;
			_updates.clear();
			_adapter.notifyDataSetChanged();
			return;
		}

		if (_changes != null) {
			process();
			_stable = _changes;
		}

		_changes = null;
		for (Integer updateId : _updates) {
			final int position = _stable.indexOf(updateId);
			if (position > 0) {
				_adapter.notifyItemChanged(position);
			}
		}
		_updates.clear();
	}

	private void process() {
		ArrayList<Range> inserted = new ArrayList<>(32);
		ArrayList<Range> removed = new ArrayList<>(32);
		ArrayList<Integer> processed = new ArrayList<>(_stable);

		int offset = 0;
		//Search for removed
{'fraction_non_alphanumeric': 0.10543478260869565, 'fraction_numerical': 0.004710144927536232, 'mean_word_length': 4.179174484052533, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, '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': '2139525', 'n_tokens_mistral': 1944, 'n_tokens_neox': 1656, 'n_words': 398}