Skip to content

Commit

Permalink
simplified iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
Wong, Dylan committed Feb 4, 2024
1 parent 714fad2 commit 89f3b5a
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions src/main/java/gregtech/api/recipes/machines/RecipeMapFurnace.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;

@ApiStatus.Internal
public class RecipeMapFurnace extends RecipeMap<SimpleRecipeBuilder> {
Expand Down Expand Up @@ -53,31 +53,10 @@ public Recipe findRecipe(long voltage, List<ItemStack> inputs, List<FluidStack>
return null;
}

// probably can just extend Iterator<Recipe> directly.
static class FurnaceRecipeIterator implements Iterator<Recipe> {

Stack<Recipe> recipe = new Stack<>();

FurnaceRecipeIterator(Recipe recipe) {
this.recipe.add(recipe);
}

@Override
public boolean hasNext() {
return !recipe.isEmpty();
}

@Override
public Recipe next() {
if (recipe.isEmpty()) return null;
return recipe.pop();
}
}

@Override
@NotNull
public Iterator<Recipe> getRecipeIterator(long voltage, List<ItemStack> inputs, List<FluidStack> fluidInputs,
boolean exactVoltage) {
return new FurnaceRecipeIterator(this.findRecipe(voltage, inputs, fluidInputs, exactVoltage));
return Collections.singleton(this.findRecipe(voltage, inputs, fluidInputs, exactVoltage)).iterator();
}
}

0 comments on commit 89f3b5a

Please sign in to comment.