package dev.kkorolyov.simpleopts;

import java.util.Comparator;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

/**
 * A set of {@code Option} objects.
 */
public class Options implements Iterable<Option> {
	private static final Comparator<Option> optionComparator = new Comparator<Option>() {
		@Override
		public int compare(Option o1, Option o2) {
			return o1.longName().compareTo(o2.longName());
		}
	};
	
	private Set<Option> options = new TreeSet<>(optionComparator);
	
	/**
	 * Constructs an empty {@code Options}.
	 */
	public Options() {
		this(null);
	}
	/**
	 * Constructs a new {@code Options} for the specified set of options.
	 * @param options supported options in this options set
	 */
	public Options(Option[] options) {
		addAll(options);
	}
	
	/**
	 * Checks if this {@code Options} contains the specified option.
	 * @param toCheck option to check
	 * @return {@code true} if this {@code Options} contains the specified option
	 */
	public boolean contains(Option toCheck) {
		return options.contains(toCheck);
	}
	/**
	 * Adds a new option to this options set.
	 * @param toAdd option to add
	 * @return {@code true} if this options set did not already contain the specified option
	 */
	public boolean add(Option toAdd) {
		return options.add(toAdd);
	}
	/**
	 * Adds an array of options to this options set.
	 * @param toAdd array to add
	 * @return number of options added
	 */
	public int addAll(Option[] toAdd) {
		int addedCounter = 0;
		
		for (Option option : toAdd) {
			if (options.add(option))
				addedCounter++;
		}
		return addedCounter;
	}
	/**
	 * Removes an option from this options set.
	 * @param toRemove option to remove
	 * @return {@code true} if this options set contained the specified option
	 */
	public boolean remove(Option toRemove) {
		return options.remove(toRemove);
	}
	
	/**
	 * Returns an iterator over all the options in this options set.
	 */
	@Override
	public Iterator<Option> iterator() {
		return options.iterator();
	}
}

@@ -804,39 +804,320 @@
 cks if this 
-%7B@code Options%7D
+options set contains an option of the specified name.%0A%09 * @param name short or long name of option%0A%09 * @return %7B@code true%7D if this options set contains an option of the specified name%0A%09 */%0A%09public boolean contains(String name) %7B%0A%09%09return get(name) != null;%0A%09%7D%0A%09/**%0A%09 * Checks if this options set
  contains th
@@ -1204,31 +1204,27 @@
 if this 
-%7B@code O
+o
 ptions
-%7D
+ set
  contain
@@ -1329,24 +1329,425 @@
 oCheck);%0A%09%7D%0A
+%09%0A%09/**%0A%09 * Returns an option from this options set matching the specified name.%0A%09 * @param name short or long name of option%0A%09 * @return matching %7B@code Option%7D, or %7B@code null%7D if no such option%0A%09 */%0A%09public Option get(String name) %7B%0A%09%09Option toReturn = null;%0A%09%09%0A%09%09for (Option option : options) %7B%0A%09%09%09if (option.matches(name)) %7B%0A%09%09%09%09toReturn = option;%0A%09%09%09%09%0A%09%09%09%09break;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return toReturn;%0A%09%7D%0A%09%0A
 %09/**%0A%09 * Add

Add contains, get by name