blob: 80b563fe0aae1c1610a036bdbb4bba873947f1f4 (
plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
package bjc.dicelang.neodice.diepool;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
import bjc.dicelang.neodice.*;
public class TransformDiePool<SideType> implements DiePool<SideType> {
private final DiePool<SideType> contained;
private UnaryOperator<Stream<SideType>> transform;
public TransformDiePool(DiePool<SideType> contained,
UnaryOperator<Stream<SideType>> transform) {
super();
this.contained = contained;
this.transform = transform;
}
@Override
public Stream<SideType> roll(Random rng) {
return transform.apply(contained.roll(rng));
}
@Override
public List<Die<SideType>> contained() {
return contained.contained();
}
@Override
public int hashCode() {
return Objects.hash(contained, transform);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
TransformDiePool<?> other = (TransformDiePool<?>) obj;
return Objects.equals(contained, other.contained)
&& Objects.equals(transform, other.transform);
}
@Override
public String toString() {
return contained.toString() + "(transformed)";
}
}
|