<commit_before>package soofw.trk;

import android.util.Log; // FIXME
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

class TaskList {
	String lastFilter = "";
	File file = null;
	ArrayList<Task> mainList = new ArrayList<Task>();
	ArrayList<Task> filterList = new ArrayList<Task>();
	ArrayList<String> tagList = new ArrayList<String>();
	ArrayList<String> complexTagList = new ArrayList<String>();
	ArrayList<String> tagFilters = new ArrayList<String>();

	TaskList(File file) {
		this.file = file;
	}

	void read() {
		try {
			String line = null;
			BufferedReader reader = new BufferedReader(new FileReader(this.file));

			while(true) {
				line = reader.readLine();
				if(line == null) break;

				this.mainList.add(new Task(line));
			}
			Collections.sort(this.mainList);
			this.filterList.addAll(this.mainList);
			this.generateTagList();

			reader.close();
		} catch(FileNotFoundException e) {
			Log.e("TRK", e.getMessage());
			this.tutorial();
		} catch(IOException e) {
			// FIXME
			Log.e("TRK", e.getMessage());
		}
	}
	void write() {
		try {
			BufferedWriter writer = new BufferedWriter(new FileWriter(this.file));

			for(int i = 0; i < this.mainList.size(); i++) {
				writer.write(this.mainList.get(i).source + "\n");
			}

			writer.flush();
			writer.close();
		} catch(IOException e) {
			// FIXME
			Log.e("TRK", e.getMessage());
		}
	}
	void tutorial() {
		this.add("Tag by due date 12/31");
		this.add("Tag by a project +garden");
		this.add("Tag by a location @home");
		this.add("Tag by anything #life");
		this.add("Tag by everything +shopping @store #life");
		this.add("Tag by priority !1");
		this.add("Or tag by low priority !0");
		this.add("Use subtags +work/tpsreports @office/garbage");
		this.add("Type to search or add");
		this.add("Long press to edit");
		this.add("Long press to filter +by @the #tags");
		this.add("Slide out from the left to filter");
		this.filterList.addAll(this.mainList);
	}

	void add(String source) {
		this.mainList.add(new Task(source));
		this.update();
	}
	void add(Task source) {
		this.mainList.add(source);
		this.update();
	}
	void set(int id, String source) {
		this.mainList.set(id, new Task(source));
		this.update();
	}
	void set(int id, Task source) {
		this.mainList.set(id, source);
		this.update();
	}
	void remove(Task task) {
		this.mainList.remove(task);
		this.update();
	}
	Task get(int id) {
		return this.mainList.get(id);
	}
	int indexOf(Task task) {
		return this.mainList.indexOf(task);
	}

	void update() {
		Collections.sort(this.mainList);
		this.generateTagList();
		// FIXME bug/26
		for(int i = 0; i < this.tagFilters.size(); i++) {
			if(!this.tagList.contains(this.tagFilters.get(i))) {
				this.tagFilters.remove(i);
				i--;
			}
		}
	}

	void generateTagList() {
		this.tagList.clear();
		this.complexTagList.clear();

		for(int i = 0; i < this.mainList.size(); i++) {
			String[] tags = this.mainList.get(i).getTags();
			for(int j = 0; j < tags.length; j++) {
				char type = tags[j].charAt(0);
				switch(type) {
					case '+':
					case '@':
					case '#':
						String[] subtags = tags[j].substring(1).split("/");
						if(!this.complexTagList.contains(tags[j])) {
							this.complexTagList.add(tags[j]);
						}
						for(int k = 0; k < subtags.length; k++) {
							if(this.tagList.contains(type + subtags[k])) continue;<commit_msg>Retain filter list when removing the last item with a tag<commit_after>package soofw.trk;

import android.util.Log; // FIXME
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

class TaskList {
	String lastFilter = "";
	File file = null;
	ArrayList<Task> mainList = new ArrayList<Task>();
	ArrayList<Task> filterList = new ArrayList<Task>();
	ArrayList<String> tagList = new ArrayList<String>();
	ArrayList<String> complexTagList = new ArrayList<String>();
	ArrayList<String> tagFilters = new ArrayList<String>();

	TaskList(File file) {
		this.file = file;
	}

	void read() {
		try {
			String line = null;
			BufferedReader reader = new BufferedReader(new FileReader(this.file));

			while(true) {
				line = reader.readLine();
				if(line == null) break;

				this.mainList.add(new Task(line));
			}
			Collections.sort(this.mainList);
			this.filterList.addAll(this.mainList);
			this.generateTagList();

			reader.close();
		} catch(FileNotFoundException e) {
			Log.e("TRK", e.getMessage());
			this.tutorial();
		} catch(IOException e) {
			// FIXME
			Log.e("TRK", e.getMessage());
		}
	}
	void write() {
		try {
			BufferedWriter writer = new BufferedWriter(new FileWriter(this.file));

			for(int i = 0; i < this.mainList.size(); i++) {
				writer.write(this.mainList.get(i).source + "\n");
			}

			writer.flush();
			writer.close();
		} catch(IOException e) {
			// FIXME
			Log.e("TRK", e.getMessage());
		}
	}
	void tutorial() {
		this.add("Tag by due date 12/31");
		this.add("Tag by a project +garden");
		this.add("Tag by a location @home");
		this.add("Tag by anything #life");
		this.add("Tag by everything +shopping @store #life");
		this.add("Tag by priority !1");
		this.add("Or tag by low priority !0");
		this.add("Use subtags +work/tpsreports @office/garbage");
		this.add("Type to search or add");
		this.add("Long press to edit");
		this.add("Long press to filter +by @the #tags");
		this.add("Slide out from the left to filter");
		this.filterList.addAll(this.mainList);
	}

	void add(String source) {
		this.mainList.add(new Task(source));
		this.update();
	}
	void add(Task source) {
		this.mainList.add(source);
		this.update();
	}
	void set(int id, String source) {
		this.mainList.set(id, new Task(source));
		this.update();
	}
	void set(int id, Task source) {
		this.mainList.set(id, source);
		this.update();
	}
	void remove(Task task) {
		this.mainList.remove(task);
		this.update();
	}
	Task get(int id) {
		return this.mainList.get(id);
	}
	int indexOf(Task task) {
		return this.mainList.indexOf(task);
	}

	void update() {
		Collections.sort(this.mainList);
		this.generateTagList();
	}

	void generateTagList() {
		this.tagList.clear();
		this.complexTagList.clear();

		for(int i = 0; i < this.mainList.size(); i++) {
			String[] tags = this.mainList.get(i).getTags();
			for(int j = 0; j < tags.length; j++) {
				char type = tags[j].charAt(0);
				switch(type) {
					case '+':
					case '@':
					case '#':
						String[] subtags = tags[j].substring(1).split("/");
						if(!this.complexTagList.contains(tags[j])) {
							this.complexTagList.add(tags[j]);
						}
						for(int k = 0; k < subtags.length; k++) {
							if(this.tagList.contains(type + subtags[k])) continue;
{'fraction_non_alphanumeric': 0.16627472679485406, 'fraction_numerical': 0.003734956425508369, 'mean_word_length': 3.713168187744459, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 23, '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': '7192333', 'n_tokens_mistral': 2825, 'n_tokens_neox': 2502, 'n_words': 560}