-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
actually working version of creating components
- Loading branch information
Showing
4 changed files
with
44 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
src/main/java/com/gtnewhorizons/mutecore/api/registry/ComponentContainer.java
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
src/main/java/com/gtnewhorizons/mutecore/api/registry/ComponentsCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.gtnewhorizons.mutecore.api.registry; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
public class ComponentsCreator { | ||
|
||
private boolean built; | ||
private List<Supplier<Object>> componentBuilders = new ArrayList<>(); | ||
|
||
public ComponentsCreator() {} | ||
|
||
public ComponentsCreator component(Supplier<Object> componentBuilder) { | ||
if (built) throw new IllegalStateException("Cannot add components after the builder has been finished"); | ||
componentBuilders.add(componentBuilder); | ||
return this; | ||
} | ||
|
||
public ComponentsCreator build() { | ||
built = true; | ||
return this; | ||
} | ||
|
||
public List<Object> createComponents() { | ||
if (!built) throw new IllegalStateException("Cannot create components when the builder is unfinished"); | ||
List<Object> components = new ArrayList<>(); | ||
for (int i = 0; i < componentBuilders.size(); i++) { | ||
components.add(componentBuilders.get(i).get()); | ||
} | ||
return components; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters