46 lines
1.3 KiB
Java
46 lines
1.3 KiB
Java
package uebung09.collection;
|
|
|
|
public class SetFactory {
|
|
|
|
private SetFactory() { /* don't instantiate */ }
|
|
|
|
/**
|
|
* Returns the empty set.
|
|
*
|
|
* @param <T> the element type of the returned set.
|
|
* @return the empty set.
|
|
*/
|
|
public static <T> Set<T> create() {
|
|
return EmptySet.getInstance();
|
|
}
|
|
|
|
/**
|
|
* Returns the singleton set containing the specified element.
|
|
*
|
|
* @param element an element (must not be null)
|
|
* @param <T> the element type of the returned set.
|
|
* @return the singleton set containing the specified element.
|
|
*/
|
|
public static <T> Set<T> create(T element) {
|
|
return new SingeltonSet<T>(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 <T> the element type of the returned set.
|
|
* @return a set containing the specified elements.
|
|
*/
|
|
public static <T> Set<T> create(T... elems) {
|
|
// BigSet<T> rtn = new BigSet<T>(elems[1], new SingeltonSet<>(elems[1]));
|
|
Set<T> set = EmptySet.getInstance();
|
|
|
|
for(T elem : elems) {
|
|
set = set.add(elem);
|
|
}
|
|
|
|
return set;
|
|
}
|
|
}
|