<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package edu.cornell.cs.cs2110;

/**
 * Implements a set of limited size.
 */
public class SmallSet {
	private int _size = 0;
	public static final int MAX = 10;
	private Object _items[] = new Object[MAX];
	
	/**
	 * Returns the number of elements in this set.
	 * @return
	 * 		the number of elements in this set.
	 */
	public int size() {
		return _size;
	}

	/**
	 * Adds an item to this set.
	 * @param o
	 * 		Object to be added.
	 * @throws SmallSetFullException
	 * 		if this set is at maximum capacity.
	 */
	public void add(Object o) throws SmallSetFullException {
		if (!inSet(o)) {
			if (_size &gt;= MAX) {
				throw new SmallSetFullException();
			}
			_items[_size] = o;
			++_size;
		}
	}

	/**
	 * Returns whether the given Object is in this set.
	 * @param o
	 * 		Object to check whether in this set.
	 * @return
	 * 		&lt;code&gt;true&lt;/code&gt; if the given Object is
	 * 		in this set, &lt;code&gt;false&lt;/code&gt; otherwise.
	 */
	private boolean inSet(Object o) {
		for (int i=0; i &lt; MAX; i++) {
			if (_items[i] == o) {
				return true;
			}
		}
		
		return false;
	}
}
</pre></body></html>