Last active
May 4, 2023 11:36
-
-
Save TGITS/f912d284c0b50197729424d87be371f9 to your computer and use it in GitHub Desktop.
Un exemple d'utilisation du fournisseur de données options pour créer un sous-ensemble aléatoirement peuplé
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//DEPS net.datafaker:datafaker:1.9.0 | |
/** | |
* Pour exécuter avec JBang : jbang DataFakerOptionsProviderSubset.jsh | |
* Pour exécuter sous JShell : | |
* jshell --class-path .;.\lib\datafaker-1.9.0.jar | |
* /open DataFakerOptionsProviderSubset.jsh | |
*/ | |
import net.datafaker.Faker; | |
import net.datafaker.providers.base.Options; | |
import java.util.Set; | |
import java.util.stream.Collectors; | |
import java.util.stream.IntStream; | |
enum DaysOfWeek { | |
MONDAY, | |
TUESDAY, | |
WEDNESDAY, | |
FRIDAY, | |
SATURDAY, | |
SUNDAY | |
}; | |
// Instanciation d'un objet Faker pour pouvoir générer des valeurs aléatoires | |
Faker faker = new Faker(); | |
Options options = faker.options(); | |
for(int i = 0 ; i < 4 ; i++) { | |
System.out.println(); | |
Set<DaysOfWeek> fourDaysOfWeek = options.subset(4,daysOfWeekAsArray); | |
System.out.println("A set of four random days among seven : " + fourDaysOfWeek.stream().map(DaysOfWeek::toString).collect(Collectors.joining(", "))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment