package collection; public class SetFactory { private SetFactory() { /* don't instantiate */ } /** * Returns the empty set. * * @param the element type of the returned set. * @return the empty set. */ static Set create() { return new EmptySet(); } /** * Returns the singleton set containing the specified element. * * @param element an element (must not be null) * @param the element type of the returned set. * @return the singleton set containing the specified element. */ static Set create(T element) { return new SingeltonSet(element); } /** * Returns a set containing the specified elements. The specified elements may contain equal elements. * * @param elems elements of the returned set (may contain equal elements) * @param the element type of the returned set. * @return a set containing the specified elements. */ static Set create(T... elems) { if (elems.length == 0) return create(); if (elems.length == 1) return create(elems[0]); Set result = create(); for (T t : elems) { result = result.add(t); } return result; } }