import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * A named class to hold non-negative numbers.
 * 
 * @author Mark Young (A00000000)
 */
public class ClassWithList {
    
    private String name;
    private List<Integer> myNumbers;
    
    /**
     * Create an empty list.
     * 
     * @param reqName the name for this list
     */
    public ClassWithList(String reqName) {
        name = reqName;
        myNumbers = new ArrayList<>();
    }
    
    /**
     * Get the name of this list.
     * 
     * @return the name of this list
     */
    public String getName() {
        return name;
    }
    
    /**
     * Change the name of this list.
     * 
     * @param newName the new name for this list
     */
    public void setName(String newName) {
        name = newName;
    }
    
    /**
     * Add another number to this list. NOTE: the number must not be negative.
     * 
     * @param newNum the number to add
     * @throws IllegalArgumentException if the number is negative
     */
    public void add(int newNum) {
        if (newNum < 0) {
            throw new IllegalArgumentException("Negative numbers not allowed");
        }
        myNumbers.add(newNum);
    }
    
    public boolean remove(int oldNum) {
        // need to create an Integer object to use remove-by-value
        return myNumbers.remove(Integer.valueOf(oldNum));
    }
    
    /**
     * A VERY BAD IDEA!!! Allows the client to mess with the List!
     * 
     * @return the ACTUAL LIST this object contains
     */
    public List<Integer> getNumbersForCheater() {
        return myNumbers;
    }
    
    /**
     * A MUCH BETTER IDEA! Does not allow the client to change the list!
     * 
     * @return a view of the list this object contains
     */
    public List<Integer> getNumbersSafely() {
        return Collections.unmodifiableList(myNumbers);
    }
    
    @Override
    public String toString() {
        return name + ": " + myNumbers;
    }
}
