// Arup Guha
// 4/28/2018
// Solution to 2016 AP Computer Science FR Question 2C

import java.util.*;

public class SystemLog {

	private List<LogBook> messageList;

	// For testing.
	public SystemLog(String[] messages) {
		messageList = new ArrayList<LogBook>();
		for (String s: messages)
			messageList.add(new LogBook(s));
	}

	// For easy testing.
	public String toString() {
		String res = "";
		for (LogBook book: messageList)
			res = res + book + "\n";
		return res;
	}

	// Method they asked us to write for part C.
	public List<LogBook> removeMessages(String keyword) {

		ArrayList<LogBook> res = new ArrayList<LogBook>();

		// Go backwards so there's no issue when deleting stuff.
		// Just check and add the removed item from our instance variable.
		for (int i=messageList.size()-1; i>=0; i--)
			if (messageList.get(i).containsWord(keyword))
				res.add(0, messageList.remove(i));

		return res;
	}

	public static void main(String[] args) {

		String[] stuff = {"SERVER1:file write","SERVER2:disk read","SERVER2:store data now","SERVER3:which disk data"};
		SystemLog data = new SystemLog(stuff);

		// Delete and look at.
		System.out.println("Deleted ");
		List<LogBook> delData = data.removeMessages("data");
		for (LogBook book: delData)
			System.out.println(book);
		System.out.println("---------------------");

		// Still have
		System.out.println("Still have");
		System.out.println(data);
	}
}