mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
Move empty init exception into BagRandomizer
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
package forge.item.generation;
|
package forge.item.generation;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import forge.card.CardEdition;
|
import forge.card.CardEdition;
|
||||||
import forge.item.BoosterPack;
|
import forge.item.BoosterPack;
|
||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
@@ -11,10 +10,7 @@ import java.util.List;
|
|||||||
public class ChaosBoosterSupplier implements IUnOpenedProduct {
|
public class ChaosBoosterSupplier implements IUnOpenedProduct {
|
||||||
private BagRandomizer<CardEdition> randomizer;
|
private BagRandomizer<CardEdition> randomizer;
|
||||||
|
|
||||||
public ChaosBoosterSupplier(Iterable<CardEdition> sets) throws Exception {
|
public ChaosBoosterSupplier(Iterable<CardEdition> sets) throws IllegalArgumentException {
|
||||||
if (Iterables.size(sets) <= 0) {
|
|
||||||
throw new Exception("At least one set needed to generate chaos draft!");
|
|
||||||
}
|
|
||||||
randomizer = new BagRandomizer<>(sets);
|
randomizer = new BagRandomizer<>(sets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,16 +17,22 @@ public class BagRandomizer<T > implements Iterable<T>{
|
|||||||
private T[] bag;
|
private T[] bag;
|
||||||
private int currentPosition = 0;
|
private int currentPosition = 0;
|
||||||
|
|
||||||
public BagRandomizer(T[] items) {
|
public BagRandomizer(T[] items) throws IllegalArgumentException {
|
||||||
|
if (items.length == 0) {
|
||||||
|
throw new IllegalArgumentException("Must include at least one item!");
|
||||||
|
}
|
||||||
bag = items;
|
bag = items;
|
||||||
shuffleBag();
|
shuffleBag();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BagRandomizer(Iterable<T> items) {
|
public BagRandomizer(Iterable<T> items) throws IllegalArgumentException {
|
||||||
ArrayList<T> list = new ArrayList<>();
|
ArrayList<T> list = new ArrayList<>();
|
||||||
for (T item : items) {
|
for (T item : items) {
|
||||||
list.add(item);
|
list.add(item);
|
||||||
}
|
}
|
||||||
|
if (list.size() == 0) {
|
||||||
|
throw new IllegalArgumentException("Must include at least one item!");
|
||||||
|
}
|
||||||
bag = (T[]) list.toArray();
|
bag = (T[]) list.toArray();
|
||||||
shuffleBag();
|
shuffleBag();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -207,9 +207,9 @@ public class BoosterDraft implements IBoosterDraft {
|
|||||||
themeFilter);
|
themeFilter);
|
||||||
// Add chaos "boosters" as special suppliers
|
// Add chaos "boosters" as special suppliers
|
||||||
final Supplier<List<PaperCard>> ChaosDraftSupplier;
|
final Supplier<List<PaperCard>> ChaosDraftSupplier;
|
||||||
try{
|
try {
|
||||||
ChaosDraftSupplier = new ChaosBoosterSupplier(chaosDraftEditions);
|
ChaosDraftSupplier = new ChaosBoosterSupplier(chaosDraftEditions);
|
||||||
} catch(Exception e) {
|
} catch(IllegalArgumentException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user