<commit_before>package st.gaw.db.adapter;

import java.util.List;

import st.gaw.db.InMemoryDbArrayList;
import st.gaw.db.InMemoryDbHelper;
import st.gaw.db.InMemoryDbList;
import st.gaw.db.InMemoryDbListener;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class InMemoryFilteredListAdapter<E> extends BaseAdapter implements InMemoryDbListener<E> {

	public interface DbFilter<E> {
		List<E> getFilteredData(InMemoryDbList<E,?> source);
	}

	private final InMemoryDbArrayList<E> mArray;
	private final LayoutInflater mInflater;
	private final int layoutId;
	private final DbFilter<E> filter;
	private final UIHandler uiHandler;
	private List<E> mData;

	public InMemoryFilteredListAdapter(Context context, UIHandler uiHandler, InMemoryDbArrayList<E> array, int layoutResourceId, DbFilter<E> filter) {
		this.mArray = array;
		this.mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.layoutId = layoutResourceId;
		this.filter = filter;
		this.uiHandler = uiHandler;
		mData = filter.getFilteredData(mArray);
		mArray.addListener(this);
	}

	@Override
	public int getCount() {
		return mData.size();
	}

	@Override
	public E getItem(int position) {
		return mData.get(position);
	}

	@Override
	public boolean hasStableIds() {
		return true;
	}

	@Override
	public long getItemId(int position) {
		return mData.get(position).hashCode();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView==null)
			convertView = mInflater.inflate(layoutId, parent, false);

		TextView vt = (TextView) convertView.findViewById(android.R.id.text1);
		vt.setText(mData.get(position).toString());

		return convertView;
	}

	@Override
	public void onMemoryDbChanged(InMemoryDbHelper<E> db) {
		final List<E> newData = filter.getFilteredData(mArray);
		Runnable runner = new Runnable() {
			@Override
			public void run() {
				mData = newData;
				notifyDataSetChanged();
			}
		};

		if (uiHandler!=null)
			uiHandler.runOnUiThread(runner);
		else
			runner.run();
	}
}
<commit_msg>avoid a crash after the number of elements is reduced<commit_after>package st.gaw.db.adapter;

import java.util.List;

import st.gaw.db.InMemoryDbArrayList;
import st.gaw.db.InMemoryDbHelper;
import st.gaw.db.InMemoryDbList;
import st.gaw.db.InMemoryDbListener;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class InMemoryFilteredListAdapter<E> extends BaseAdapter implements InMemoryDbListener<E> {

	public interface DbFilter<E> {
		List<E> getFilteredData(InMemoryDbList<E,?> source);
	}

	private final InMemoryDbArrayList<E> mArray;
	private final LayoutInflater mInflater;
	private final int layoutId;
	private final DbFilter<E> filter;
	private final UIHandler uiHandler;
	private List<E> mData;

	public InMemoryFilteredListAdapter(Context context, UIHandler uiHandler, InMemoryDbArrayList<E> array, int layoutResourceId, DbFilter<E> filter) {
		this.mArray = array;
		this.mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.layoutId = layoutResourceId;
		this.filter = filter;
		this.uiHandler = uiHandler;
		mData = filter.getFilteredData(mArray);
		mArray.addListener(this);
	}

	@Override
	public int getCount() {
		return mData.size();
	}

	@Override
	public E getItem(int position) {
		return mData.get(position);
	}

	@Override
	public boolean hasStableIds() {
		return true;
	}

	@Override
	public long getItemId(int position) {
		if (position<mData.size())
			return mData.get(position).hashCode();
		return -1;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView==null)
			convertView = mInflater.inflate(layoutId, parent, false);

		TextView vt = (TextView) convertView.findViewById(android.R.id.text1);
		vt.setText(mData.get(position).toString());

		return convertView;
	}

	@Override
	public void onMemoryDbChanged(InMemoryDbHelper<E> db) {
		final List<E> newData = filter.getFilteredData(mArray);
		Runnable runner = new Runnable() {
			@Override
			public void run() {
				mData = newData;
				notifyDataSetChanged();
			}
		};

		if (uiHandler!=null)
			uiHandler.runOnUiThread(runner);
		else
			runner.run();
	}
}

{'fraction_non_alphanumeric': 0.10173113913229323, 'fraction_numerical': 0.0006411626415900834, 'mean_word_length': 4.1827242524916945, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 27, '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': '4739311', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1475, 'n_words': 327}