import java.util.Iterator;

/**
 * A set of integers in a fixed range.
 */
public interface IntSet extends Iterable<Integer>
{
    /**
     * Returns the minimum of the range of this set.
     */
    int getRangeMin();

    /**
     * Returns the maximum of the range of this set.  The maximum is included as a valid
     * possible element.
     */
    int getRangeMax();

    /**
     * Adds the given integer to this set.  No effect if the integer is outside the range
     * of this set.
     */
    void add(int n);

    /**
     * Removes the given integer from this set.  No effect if the integer is not an element.
     */
    void remove(int n);

    /**
     * Determines if the given integer is in this set.
     */
    boolean contains(int n);

    /**
     * Returns the number of elements in this set.  This implementation calls contains
     * for each value in the range of this set and so is inefficient; implementing classes
     * should supply a more efficient implementation.
     */
    default int size()
    {
	int count = 0;
	for (int i = getRangeMin(); i <= getRangeMax(); i++)
	    {
		if (contains(i))
		    {
			count++;
		    }
	    }
	return count++;
    }

}
