public class ConvenienceMethods extends Object
Constructor and Description |
---|
ConvenienceMethods(RandomService random) |
Modifier and Type | Method and Description |
---|---|
boolean |
chance(int howMany,
int in)
Has a
howMany in in chance to return true . |
<T> T |
chance(int howMany,
int in,
Supplier<T> supplier)
Has a
howMany in in chance to supply a value. |
String |
find(String value)
Finds all methods containing a search string in their name.
|
<T> List<T> |
listOf(int count,
Supplier<T> supplier)
Provides a list of objects supplied by a method
|
<T extends Enum<?>> |
nextEnum(Class<T> clazz)
Returns a random enum value
|
<T> T |
oneOf(List<T> list)
Returns a random element from a list
|
<T> T |
oneOf(Set<T> set)
Returns a random element from a set
|
<T> T |
oneOf(Supplier<T>... suppliers)
Returns a value from a random supplier.
|
<T> T |
oneOf(T... array)
Returns a random element from an array
|
<T> Set<T> |
setOf(int count,
Supplier<T> supplier)
Provides a set of objects supplied by a method
|
public ConvenienceMethods(RandomService random)
public <T> List<T> listOf(int count, Supplier<T> supplier)
T
- the type of objects to generatecount
- the number of objects to generatesupplier
- the method to generate an objectpublic <T> Set<T> setOf(int count, Supplier<T> supplier)
T
- the type of objects to generatecount
- the number of objects to generatesupplier
- the method to generate an object@SafeVarargs public final <T> T oneOf(T... array)
T
- the type of object to returnarray
- the array to pick frompublic <T> T oneOf(List<T> list)
T
- the type of object to returnlist
- the list to pick frompublic <T> T oneOf(Set<T> set)
T
- the type of object to returnset
- the list to pick from@SafeVarargs public final <T> T oneOf(Supplier<T>... suppliers)
T
- the type of value to returnsuppliers
- value suppliers to pick frompublic <T> T chance(int howMany, int in, Supplier<T> supplier)
howMany
in in
chance to supply a value. Otherwise, returns null.
E.g. chance(1, 2, () -> "hello")
has a 1-in-2 chance to supply "hello", that is it will be supplied
50% of the time when the method is invoked.
T
or nullpublic boolean chance(int howMany, int in)
howMany
in in
chance to return true
. Otherwise, returns false
.
E.g. chance(1, 2)
has a 1-in-2 chance to return true
, that is it will return true
50% of the time when the method is invoked.
boolean
public String find(String value)
value
- a string to search forCopyright © 2022. All rights reserved.