Skip to content

Commit

Permalink
Added documentation to chance generators
Browse files Browse the repository at this point in the history
  • Loading branch information
xDec0de committed Dec 1, 2023
1 parent bff2968 commit 9e59c90
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,37 @@ public interface ChanceGenerator<T> {
@Nonnull
public ChanceGenerator<T> add(T element, float chance);

/**
* Generates a {@link List} with {@link #add(Object, float) added}
* elements by chance. Keep in mind that this list may be empty if
* no element has a 100% chance of being generated.
* <p>
* Elements will only be added once to the list if their chance to
* be generated was successful.
*
* @return A {@link List} with {@link #add(Object, float) added}
* elements by chance. May be empty if no element was generated by chance.
*
* @since MCUtils 1.0.0
*/
@Nonnull
public List<T> generate();

/**
* Works in a similar way to {@link #generate()} but limits the
* generated elements to a <b>max</b> amount. Implementations should
* discard more common elements (Higher chance ones) if the resulting
* list exceeds the <b>max</b> size. An auxiliary method is provided
* for this purpose ({@link #limitElements(HashMap, int)}).
*
* @param max the maximum size of the generated {@link List}.
*
* @return A {@link List} with {@link #add(Object, float) added}
* elements by chance limited to a certain <b>max</b> size.
* May be empty if no element was generated by chance.
*
* @since MCUtils 1.0.0
*/
@Nonnull
public List<T> generate(int max);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ public List<T> generate() {
return result;
}

/**
* Works in a similar way to {@link #generate()} but limits the
* generated elements to a <b>max</b> amount. Keep in mind that the
* rarest elements take priority, so for example if we have two elements,
* "Common" (100% chance) and "Rare" (25% chance) and the <b>max</b> amount
* to generate is 1, if the 25% chance of getting the "Rare" element was
* successful, the list will only contain "Rare" as it has a higher priority
* to be generated than "Common".
*
* @param max the maximum size of the generated {@link List}.
*
* @return A {@link List} with {@link #add(Object, float) added}
* elements by chance limited to a certain <b>max</b> size.
* May be empty if no element was generated by chance.
*
* @since MCUtils 1.0.0
*/
@Nonnull
@Override
public List<T> generate(int max) {
Expand Down

0 comments on commit 9e59c90

Please sign in to comment.