Prevent null pointer exception if GeneratorWeighted is empty

This commit is contained in:
Cheeserolls 2015-08-06 11:49:18 +01:00
parent 675e7411da
commit a7e520c7f3
1 changed files with 5 additions and 2 deletions

View File

@ -84,7 +84,10 @@ public class GeneratorWeighted extends BOPGeneratorBase
public IGenerator getRandomGenerator(Random random)
{
if (this.weights.isEmpty()) {return null;}
if (this.weights.isEmpty())
{
throw new RuntimeException("GeneratorWeighted has no child generators");
}
int totalWeight = 0;
for (int weight : this.weights.values()) {totalWeight += weight;}
int j = random.nextInt(totalWeight);
@ -93,7 +96,7 @@ public class GeneratorWeighted extends BOPGeneratorBase
j -= entry.getValue();
if (j < 0) {return entry.getKey();}
}
return null;
throw new RuntimeException("Shouldn't ever get here");
}
// never used - the scatter method is overriden