RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.util.chance.WeightedChance< T > Class Template Reference

An item with a common chance. More...

Inheritance diagram for com.runehive.util.chance.WeightedChance< T >:
Collaboration diagram for com.runehive.util.chance.WeightedChance< T >:

Public Member Functions

int compareTo (WeightedObject< T > o)
get ()
 Gets the representation of the weighted chance.
double getWeight ()
 Gets the object's weight.
String toString ()
 WeightedChance (double weight, T representation)

Private Attributes

final T representation
 The representation.
double weight
 The weight type.

Detailed Description

An item with a common chance.

Author
Michael | Chex

Definition at line 10 of file WeightedChance.java.

Constructor & Destructor Documentation

◆ WeightedChance()

com.runehive.util.chance.WeightedChance< T >.WeightedChance ( double weight,
T representation )

Definition at line 18 of file WeightedChance.java.

18 {
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 }

References representation, and weight.

Member Function Documentation

◆ compareTo()

Definition at line 37 of file WeightedChance.java.

37 {
38 return (int) (getWeight() - o.getWeight());
39 }

References getWeight(), and com.runehive.util.chance.WeightedObject< T >.getWeight().

Here is the call graph for this function:

◆ get()

Gets the representation of the weighted chance.

Implements com.runehive.util.chance.WeightedObject< T >.

Definition at line 32 of file WeightedChance.java.

32 {
33 return representation;
34 }

References representation.

◆ getWeight()

double com.runehive.util.chance.WeightedChance< T >.getWeight ( )

Gets the object's weight.

Implements com.runehive.util.chance.WeightedObject< T >.

Definition at line 27 of file WeightedChance.java.

27 {
28 return weight;
29 }

References weight.

Referenced by compareTo(), and toString().

Here is the caller graph for this function:

◆ toString()

String com.runehive.util.chance.WeightedChance< T >.toString ( )

Implements com.runehive.util.chance.WeightedObject< T >.

Definition at line 42 of file WeightedChance.java.

42 {
43 return "[Object: " + get() + ", " + "Weight: " + getWeight() + "]";
44 }

References getWeight().

Here is the call graph for this function:

Member Data Documentation

◆ representation

final T com.runehive.util.chance.WeightedChance< T >.representation
private

The representation.

Definition at line 13 of file WeightedChance.java.

Referenced by get(), and WeightedChance().

◆ weight

double com.runehive.util.chance.WeightedChance< T >.weight
private

The weight type.

Definition at line 16 of file WeightedChance.java.

Referenced by getWeight(), and WeightedChance().


The documentation for this class was generated from the following file: