uebung09
This commit is contained in:
@@ -11,8 +11,7 @@ public class SetFactory {
|
||||
* @return the empty set.
|
||||
*/
|
||||
static <T> Set<T> create() {
|
||||
// TODO implement
|
||||
return null;
|
||||
return new EmptySet<T>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,8 +22,7 @@ public class SetFactory {
|
||||
* @return the singleton set containing the specified element.
|
||||
*/
|
||||
static <T> Set<T> create(T element) {
|
||||
// TODO implement
|
||||
return null;
|
||||
return new SingeltonSet<T>(element);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,7 +33,14 @@ public class SetFactory {
|
||||
* @return a set containing the specified elements.
|
||||
*/
|
||||
static <T> Set<T> create(T... elems) {
|
||||
// TODO implement
|
||||
return null;
|
||||
if (elems.length == 0) return create();
|
||||
if (elems.length == 1) return create(elems[0]);
|
||||
Set<T> result = create();
|
||||
|
||||
for (T t : elems) {
|
||||
result = result.add(t);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user