This commit is contained in:
2025-06-12 11:59:41 +02:00
parent f42c1b23ab
commit 57aae3eda6
9 changed files with 354 additions and 12 deletions

View File

@@ -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;
}
}