/**
 * The <code>AppModel</code> class can create an ArrayList named
 * listeners, which contains Listener subject. This class can
 * set up listeners, add a Listener to listeners, remove a listener
 * from listeners, notify listeners for updates, set up missValue.
 * 
 * @author CMPUT301W15T06
 * @version 03/07/2015
 * @see java.util.ArrayList
 * @see java.util.HashSet
 * @see java.util.Set
 */

package ca.ualberta.CMPUT301W15T06;

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

public class AppModel{
	
	/**
	 * Set two private ArrayList variable named listeners
	 * and modelListeners to contain Listener subject
	 * 
	 * @see java.util.ArrayList;
	 */
	private transient ArrayList<Listener> listeners;
	private transient ArrayList<Listener> modelListeners;
	/**
	 * Set a boolean variable missValue to justify the 
	 * <code>AppModel</code>
	 */
	private boolean missValue;
	
	/**
	 * This method creates an ArrayList listeners and an
	 * ArrayList modelListers for listeners that 
	 * records all Listener
	 */
	public AppModel(){
		listeners=new ArrayList<Listener>();
		modelListeners=new ArrayList<Listener>();
	}
	
	/**
	 * This method allows user to add a Listener to the 
	 * ArrayList listeners
	 * 
	 * @param l  a Listener type
	 */
	public void addListener(Listener l){
		if (!getListeners().contains(l)){
			getListeners().add(l);
		}
	}
	
	/**
	 * This method allows user to remove a Listener from
	 * the ArrayList listeners
	 * 
	 * @param l  a Listener type
	 */
	public void removeListener(Listener l){
		getListeners().remove(l);
	}
	
	/**
	 * This method checks if there's any listeners, 
	 * if not, set up a new one and return it for further use
	 * 
	 * @return listeners  an ArrayList type
	 */
	private ArrayList<Listener> getListeners(){
		if (listeners==null){
			listeners=new ArrayList<Listener>();
		}
		return listeners;
	}
	

	/**
	 * This method is design for notifying all Listener 
	 * in listeners ArrayList and modelListeners ArrayList 
	 * if there's any update, and the ClaimListManager 
	 * will save the change 
	 */
	public void notifyListeners() {
		for (Listener  listener : getListeners()) {
			listener.update();
		}
		for (Listener  listener : getModelListeners()) {
			listener.update();
		}
		ClaimListManager.getInstance().save();
	}

	/**
	 * This method allows user to add a Listener to the 
	 * modelListeners if the model does not contains 
	 * a Listener l
	 * 
	 * @param l  a Listener type
	 */
	public void addModelListener(Listener l){
		if (!getModelListeners().contains(l)){
			getModelListeners().add(l);
		}
	}
	
	/**
	 * This method is designed to remove a Listener from
	 * the modelListeners ArrayList
	 * 
	 * @param l  a Listener type
	 */
	public void removeModelListener(Listener l){
		getModelListeners().remove(l);
	}
	
	/**
	 * This method will create a new ArrayList modelListeners 
	 * if there's none and return the new modelListeners
	 * 
	 * @return modelListners  an ArrayList type
	 */
	private ArrayList<Listener> getModelListeners(){
		if (modelListeners==null){
			modelListeners=new ArrayList<Listener>();
		}
		return modelListeners;
	}
	
	/**
	 * Set missValue to b, and notify all Listener in
	 * listeners ArrayList and modelListeners ArrayList 
	 * about this update.
	 *  
	 * @param b  a boolean type b
	 */
	public void setMissValue(boolean b) {
		missValue=b;
		notifyListeners();
	}

	/**
	 * return the missValue. This method will be used
	 * when user needs to use the value of missValue 
	 * to justify the <code>AppModel</code>.
	 * 
	 * @return missValue  a boolean type
	 */
	public boolean getMissValue() {
		return missValue;
	}
}

@@ -907,32 +907,54 @@
 alue;%0A%09%0A%09/**%0A%09 *
+ General construction.
  This method cre
@@ -963,32 +963,37 @@
 es an ArrayList 
+%0A%09 * 
 listeners and an
@@ -992,20 +992,16 @@
 s and an
-%0A%09 *
  ArrayLi
@@ -1034,17 +1034,17 @@
 ers 
-that %0A%09 *
+%0A%09 * that
  rec
@@ -1060,16 +1060,17 @@
 Listener
+.
 %0A%09 */%0A%09p
@@ -1474,35 +1474,36 @@
 %09 * the 
-ArrayList listeners
+listeners ArrayList.
 %0A%09 * %0A%09 
@@ -1661,16 +1661,26 @@
 isteners
+ ArrayList
 , %0A%09 * i

Update AppModel.java