mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-22 12:59:50 +00:00
chore: clean up
This commit is contained in:
1 parent
ea1eab8685
commit
d6ead4a4e9
22 files changed
+341
-141
No files matched your search
@@ -2,6 +2,7 @@ package me.towdium.jecalculation.data.structure;
|
||||
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.polyfill.NBTHelper;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
import me.towdium.jecalculation.utils.wrappers.Trio;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
@@ -60,19 +61,8 @@ public class Recipes {
|
||||
return records.size();
|
||||
}
|
||||
|
||||
public Stream<Map.Entry<String, List<Recipe>>> stream() {
|
||||
return records.entrySet().stream();
|
||||
}
|
||||
|
||||
public Stream<Trio<Recipe, String, Integer>> flatStream() {
|
||||
return records.entrySet().stream().flatMap(i ->
|
||||
IntStream.range(0, i.getValue().size()).mapToObj(j ->
|
||||
new Trio<>(i.getValue().get(j), i.getKey(), j)));
|
||||
}
|
||||
|
||||
public Stream<Trio<Recipe, String, Integer>> flatStream(String group) {
|
||||
List<Recipe> l = records.get(group);
|
||||
return IntStream.range(0, l.size()).mapToObj(j -> new Trio<>(l.get(j), group, j));
|
||||
public Stream<Pair<String, List<Recipe>>> stream() {
|
||||
return records.entrySet().stream().map(i -> new Pair<>(i.getKey(), i.getValue()));
|
||||
}
|
||||
|
||||
public void remove(String group, int index) {
|
||||
@@ -85,17 +75,14 @@ public class Recipes {
|
||||
return getGroup(group).get(index);
|
||||
}
|
||||
|
||||
public List<Trio<Recipe, String, Integer>> getRecipes() {
|
||||
return flatStream().collect(Collectors.toCollection(ArrayList::new));
|
||||
public List<Recipe> getRecipes() {
|
||||
return records.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Trio<Recipe, String, Integer>> getRecipes(String group) {
|
||||
return flatStream(group).collect(Collectors.toCollection(ArrayList::new));
|
||||
public List<Recipe> getRecipes(String group) {
|
||||
return records.get(group);
|
||||
}
|
||||
|
||||
public Optional<Recipe> getRecipe(ILabel label) {
|
||||
return flatStream().map(i -> i.one).filter(i -> i.matches(label)).findFirst();
|
||||
}
|
||||
public void forEach(BiConsumer<String, List<Recipe>> consumer) {
|
||||
records.forEach(consumer);
|
||||
}
|
||||
@@ -116,10 +103,34 @@ public class Recipes {
|
||||
|
||||
|
||||
public List<String> getGroups() {
|
||||
return records.keySet().stream().sorted().collect(Collectors.toList());
|
||||
return new ArrayList<>(records.keySet());
|
||||
}
|
||||
|
||||
public NBTTagCompound serialize() {
|
||||
return serialize(records.keySet());
|
||||
}
|
||||
|
||||
public RecipeIterator recipeIterator() {
|
||||
return new RecipeIterator();
|
||||
}
|
||||
|
||||
public class RecipeIterator implements Iterator<Recipe> {
|
||||
Iterator<Map.Entry<String, List<Recipe>>> i = records.entrySet().iterator();
|
||||
Iterator<Recipe> j;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
while (j == null || !j.hasNext()) {
|
||||
if (i.hasNext()) j = i.next().getValue().iterator();
|
||||
else return false;
|
||||
}
|
||||
return j.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe next() {
|
||||
while (j == null || !j.hasNext()) if (i.hasNext()) j = i.next().getValue().iterator();
|
||||
return j.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user