Skip to content

Instantly share code, notes, and snippets.

@TGITS
Created May 17, 2023 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TGITS/bb74244b283621adbf3b1c7ec97941b0 to your computer and use it in GitHub Desktop.
Save TGITS/bb74244b283621adbf3b1c7ec97941b0 to your computer and use it in GitHub Desktop.
Script JShell pour générer une stream d'ISBNs factices
//DEPS net.datafaker:datafaker:1.9.0
/**
* Pour executer avec JBang : jbang SimpleStreamUsage.jsh
* <p>
* Pour exécuter sous JShell :
* jshell --class-path .;.\lib\datafaker-1.9.0.jar
* /open SimpleStreamUsage.jsh
*/
import net.datafaker.Faker;
import java.util.stream.Stream;
// Instanciation d'un objet Faker pour pouvoir générer des valeurs aléatoires
Faker faker = new Faker();
// <String>stream() : Type de la séquence
// suppliers(() -> faker.code().isbn10(true)) : Création des éléments de la séquence
// len(5, 10) : Limites hautes et basses sur la taille de la séquence
// generate() : génération de la séquence
Stream<String> isbns = faker.<String>stream().suppliers(() -> faker.code().isbn10(true)).len(5, 10).generate();
System.out.println("Printing some ISBNs (between 5 and 10):");
isbns.forEach(System.out::println);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment