-
-
Notifications
You must be signed in to change notification settings - Fork 204
/
RandomCollection.java
36 lines (28 loc) · 1.2 KB
/
RandomCollection.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.fastasyncworldedit.core.util.collection;
import com.fastasyncworldedit.core.math.random.SimpleRandom;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* A RandomCollection holds multiple values that can be accessed by using
* {@link RandomCollection#next(SimpleRandom, int, int, int)}. The returned value is
* determined by a given {@link SimpleRandom} implementation.
*
* @param <T> the type of values the collection holds.
*/
public sealed interface RandomCollection<T> permits FastRandomCollection, SimpleRandomCollection {
/**
* Return a new RandomCollection. The implementation may differ depending on the
* given arguments but there is no need to differ.
*
* @param weights the weighted map.
* @param <T> the type the collection holds.
* @return a RandomCollection using the given weights and the RNG.
*/
static <T> RandomCollection<T> of(List<Weighted<T>> weights) {
return FastRandomCollection.create(weights)
.orElseGet(() -> new SimpleRandomCollection<>(weights));
}
T next(SimpleRandom random, int x, int y, int z);
record Weighted<T>(T value, double weight) {
}
}