mirror of
https://github.com/processing/processing4.git
synced 2026-03-16 01:17:39 +01:00
throw an exception when calling random() on empty XxxList (from 221006)
This commit is contained in:
@@ -681,6 +681,9 @@ public class DoubleList implements Iterable<Double> {
|
||||
* Return a random value from the list.
|
||||
*/
|
||||
public double random() {
|
||||
if (count == 0) {
|
||||
throw new ArrayIndexOutOfBoundsException("No entries in this DoubleList");
|
||||
}
|
||||
return data[(int) (Math.random() * count)];
|
||||
}
|
||||
|
||||
@@ -690,6 +693,9 @@ public class DoubleList implements Iterable<Double> {
|
||||
* randomSeed() from the specified sketch object.
|
||||
*/
|
||||
public double random(PApplet sketch) {
|
||||
if (count == 0) {
|
||||
throw new ArrayIndexOutOfBoundsException("No entries in this DoubleList");
|
||||
}
|
||||
return data[(int) sketch.random(count)];
|
||||
}
|
||||
|
||||
|
||||
@@ -703,6 +703,9 @@ public class FloatList implements Iterable<Float> {
|
||||
* Return a random value from the list.
|
||||
*/
|
||||
public float random() {
|
||||
if (count == 0) {
|
||||
throw new ArrayIndexOutOfBoundsException("No entries in this FloatList");
|
||||
}
|
||||
return data[(int) (Math.random() * count)];
|
||||
}
|
||||
|
||||
@@ -712,6 +715,9 @@ public class FloatList implements Iterable<Float> {
|
||||
* randomSeed() from the specified sketch object.
|
||||
*/
|
||||
public float random(PApplet sketch) {
|
||||
if (count == 0) {
|
||||
throw new ArrayIndexOutOfBoundsException("No entries in this FloatList");
|
||||
}
|
||||
return data[(int) sketch.random(count)];
|
||||
}
|
||||
|
||||
|
||||
@@ -678,6 +678,9 @@ public class IntList implements Iterable<Integer> {
|
||||
* Return a random value from the list.
|
||||
*/
|
||||
public int random() {
|
||||
if (count == 0) {
|
||||
throw new ArrayIndexOutOfBoundsException("No entries in this IntList");
|
||||
}
|
||||
return data[(int) (Math.random() * count)];
|
||||
}
|
||||
|
||||
@@ -687,6 +690,9 @@ public class IntList implements Iterable<Integer> {
|
||||
* randomSeed() from the specified sketch object.
|
||||
*/
|
||||
public int random(PApplet sketch) {
|
||||
if (count == 0) {
|
||||
throw new ArrayIndexOutOfBoundsException("No entries in this IntList");
|
||||
}
|
||||
return data[(int) sketch.random(count)];
|
||||
}
|
||||
|
||||
|
||||
@@ -581,6 +581,9 @@ public class StringList implements Iterable<String> {
|
||||
* Return a random value from the list.
|
||||
*/
|
||||
public String random() {
|
||||
if (count == 0) {
|
||||
throw new ArrayIndexOutOfBoundsException("No entries in this StringList");
|
||||
}
|
||||
return data[(int) (Math.random() * count)];
|
||||
}
|
||||
|
||||
@@ -590,6 +593,9 @@ public class StringList implements Iterable<String> {
|
||||
* randomSeed() from the specified sketch object.
|
||||
*/
|
||||
public String random(PApplet sketch) {
|
||||
if (count == 0) {
|
||||
throw new ArrayIndexOutOfBoundsException("No entries in this StringList");
|
||||
}
|
||||
return data[(int) sketch.random(count)];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user