RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
WeightedChance.java
1
package
com.osroyale.util.chance;
2
3
import
java.util.Objects;
4
10
public
class
WeightedChance<T>
implements
WeightedObject
<T> {
11
13
private
final
T representation;
14
16
private
double
weight;
17
18
public
WeightedChance(
double
weight, T representation) {
19
if
(weight <= 0) {
20
throw
new
IllegalArgumentException(
"The weight of an item must be larger than zero!"
);
21
}
22
this.representation = Objects.requireNonNull(representation);
23
this.weight = weight;
24
}
25
26
@Override
27
public
double
getWeight
() {
28
return
weight;
29
}
30
31
@Override
32
public
T
get
() {
33
return
representation;
34
}
35
36
@Override
37
public
int
compareTo(
WeightedObject<T>
o) {
38
return
(
int
) (
getWeight
() - o.
getWeight
());
39
}
40
41
@Override
42
public
String toString() {
43
return
"[Object: "
+
get
() +
", "
+
"Weight: "
+
getWeight
() +
"]"
;
44
}
45
}
com.osroyale.util.chance.WeightedChance.getWeight
double getWeight()
Definition
WeightedChance.java:27
com.osroyale.util.chance.WeightedObject
Definition
WeightedObject.java:8
com.osroyale.util.chance.WeightedObject.getWeight
double getWeight()