// Arup Guha
// 10/28/2017
// Example for Junior Knights Illustrating ArrayList methods.

import java.util.*;

public class TestAL {

	public static void main(String[] args) {

		// Add stuff to the end and check list.
		ArrayList<String> lunchitems = new ArrayList<String>();
		lunchitems.add("tacquito");
		lunchitems.add("chipotlechickengriller");
		System.out.println(lunchitems);

		// Show the use of the get method.
		String arupsorder = lunchitems.get(1);
		System.out.println("Arup's order is "+arupsorder);

		// Show the overloaded add.
		lunchitems.add(1, "enchiladas");
		System.out.println(lunchitems);

		// Uncomment this and print to see what clear does.
		//lunchitems.clear();

		// Just adding a bunch of stuff to our list.
		lunchitems.add("burrito");
		lunchitems.add("taco");
		lunchitems.add("chimichanga");
		lunchitems.add("taco");
		lunchitems.add("taco");
		System.out.println(lunchitems);

		// show what happens we we remove an item via index.
		String eatthis = lunchitems.remove(2);
		System.out.println("After eating "+eatthis+" we have "+lunchitems+" left.");

		// Now, we remove an item by the item - it removes the first occurrence of the item, if it exists.
		boolean gotItem = lunchitems.remove("taco");
		if (gotItem)
			System.out.println("I ate a taco we now have "+lunchitems);

		// Testing the case when we try to remove something that isn't there.
		gotItem = lunchitems.remove("cheeseburger");
		if (!gotItem)
			System.out.println("Sorry there is no cheeseburger. "+lunchitems);

		// Set changes an changes an item in our last AND returns the old one, if we want it for something.
		String last = lunchitems.set(2, "nachos");
		System.out.println("replaced "+last+" now we have "+lunchitems);

		// Loop through all items in the array list - standard way.
		for (int i=0; i<lunchitems.size(); i++) {

			// A random screening of items with 6 or more characters.
			if (lunchitems.get(i).length() > 5)
				System.out.println("We will eat "+lunchitems.get(i));
		}

		// Iterator method of going through each item in an ArrayList - this is cleaner unless you need explicit
		// access to the index of an item.
		for (String item : lunchitems) {
			if (item.length() > 5)
				System.out.println("We will now eat "+item);
		}

		// These are very useful but the AP people don't test on them.
		Collections.sort(lunchitems);
		System.out.println(lunchitems);
		Collections.reverse(lunchitems);
		System.out.println(lunchitems);
		for (int i=0; i<5; i++) {
			Collections.shuffle(lunchitems);
			System.out.println(lunchitems);
		}
	}
}