// Path: app/src/main/java/comcmput301f16t01/github/carrier/Listener.java
// public interface Listener {
//     void update();
// }


import android.util.Log;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.ExecutionException;
import comcmput301f16t01.github.carrier.Listener;
package comcmput301f16t01.github.carrier.Requests;




/**
 * Adds listener functionality to the base ArrayList class.
 * TODO remove building up listeners (if there are any?)
 * @see Listener
 * @see Request
 */
public class RequestList extends ArrayList<Request> {
    private ArrayList<Listener> listeners = new ArrayList<>();
    /** Possible limit on the length of the array (-1 is default "unset" value). */
    private int maxArraySize = -1;

    public void setMaxArraySize(int maxArraySize) {
        this.maxArraySize = maxArraySize;
    }

    @Override
    public boolean add(Request e) {
        Boolean returnValue = super.add(e);
        notifyListeners();
        return returnValue;
    }

    public void addListener(Listener newListener ) {
        listeners.add( newListener );
    }

    public void removeListener( Listener listener ) {
        listeners.remove( listener );
    }

    public void notifyListeners() {
        for (Listener listener : listeners ) {
            listener.update();
        }
    }

    /** Replaces itself with a new instance and notifies listeners of the update. */
    public void replaceList( RequestList newList ) {
        this.clear();
        this.addAll( newList );
        notifyListeners();
    }

    /**
     * Removes request based on the request Id and notifies listeners of the update.
     * @param request The request to remove from the list
     */
    public boolean remove(Request request) {
        Iterator<Request> iterator = this.iterator();
        while(iterator.hasNext()) {
            if(iterator.next().getId().equals(request.getId())) {
// Path: app/src/main/java/comcmput301f16t01/github/carrier/Listener.java
// public interface Listener {
//     void update();
// }


// Path: app/src/main/java/comcmput301f16t01/github/carrier/Requests/RequestList.java
import android.util.Log;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.ExecutionException;
import comcmput301f16t01.github.carrier.Listener;

package comcmput301f16t01.github.carrier.Requests;




/**
 * Adds listener functionality to the base ArrayList class.
 * TODO remove building up listeners (if there are any?)
 * @see Listener
 * @see Request
 */
public class RequestList extends ArrayList<Request> {
    private ArrayList<Listener> listeners = new ArrayList<>();
    /** Possible limit on the length of the array (-1 is default "unset" value). */
    private int maxArraySize = -1;

    public void setMaxArraySize(int maxArraySize) {
        this.maxArraySize = maxArraySize;
    }

    @Override
    public boolean add(Request e) {
        Boolean returnValue = super.add(e);
        notifyListeners();
        return returnValue;
    }

    public void addListener(Listener newListener ) {
        listeners.add( newListener );
    }

    public void removeListener( Listener listener ) {
        listeners.remove( listener );
    }

    public void notifyListeners() {
        for (Listener listener : listeners ) {
            listener.update();
        }
    }

    /** Replaces itself with a new instance and notifies listeners of the update. */
    public void replaceList( RequestList newList ) {
        this.clear();
        this.addAll( newList );
        notifyListeners();
    }

    /**
     * Removes request based on the request Id and notifies listeners of the update.
     * @param request The request to remove from the list
     */
    public boolean remove(Request request) {
        Iterator<Request> iterator = this.iterator();
        while(iterator.hasNext()) {
            if(iterator.next().getId().equals(request.getId())) {
                iterator.remove();