Search in sources :

Example 1 with RandomService

use of com.github.javafaker.service.RandomService in project com-liferay-apio-architect by liferay.

the class PersonModel method compute.

/**
 * Computes the fake data for this model class.
 */
public static void compute() {
    if (!_personModels.isEmpty()) {
        return;
    }
    for (long index = 0; index < 10; index++) {
        Faker faker = new Faker();
        Address address = faker.address();
        Internet internet = faker.internet();
        DateAndTime dateAndTime = faker.date();
        Calendar calendar = Calendar.getInstance();
        calendar.add(YEAR, -21);
        Date birthDate = dateAndTime.past(10000, DAYS, calendar.getTime());
        Name name = faker.name();
        RandomService randomService = faker.random();
        IntStream intStream = IntStream.range(0, randomService.nextInt(5));
        List<String> jobTitles = intStream.mapToObj(__ -> name.title()).collect(Collectors.toList());
        PersonModel personModel = new PersonModel(address.fullAddress(), internet.avatar(), birthDate, internet.safeEmailAddress(), name.firstName(), jobTitles, name.lastName(), _count.get());
        _personModels.put(_count.getAndIncrement(), personModel);
    }
}
Also used : YEAR(java.util.Calendar.YEAR) IntStream(java.util.stream.IntStream) RandomService(com.github.javafaker.service.RandomService) Date(java.util.Date) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Address(com.github.javafaker.Address) Collectors(java.util.stream.Collectors) DateAndTime(com.github.javafaker.DateAndTime) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Calendar(java.util.Calendar) Stream(java.util.stream.Stream) Name(com.github.javafaker.Name) Faker(com.github.javafaker.Faker) DAYS(java.util.concurrent.TimeUnit.DAYS) Map(java.util.Map) Optional(java.util.Optional) Internet(com.github.javafaker.Internet) Address(com.github.javafaker.Address) Calendar(java.util.Calendar) DateAndTime(com.github.javafaker.DateAndTime) Date(java.util.Date) Name(com.github.javafaker.Name) Faker(com.github.javafaker.Faker) RandomService(com.github.javafaker.service.RandomService) Internet(com.github.javafaker.Internet) IntStream(java.util.stream.IntStream)

Example 2 with RandomService

use of com.github.javafaker.service.RandomService in project java-faker by DiUS.

the class Internet method privateIpV4Address.

/**
 * @return a valid private IPV4 address in dot notation
 */
public String privateIpV4Address() {
    final Integer[] PRIVATE_FIRST_OCTET = { 10, 127, 169, 192, 172 };
    final Integer[] PRIVATE_SECOND_OCTET_172 = { 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 };
    final RandomService r = faker.random();
    int first = random(PRIVATE_FIRST_OCTET), second = r.nextInt(256), third = r.nextInt(256), fourth = r.nextInt(256);
    switch(first) {
        case 172:
            second = random(PRIVATE_SECOND_OCTET_172);
            break;
        case 192:
            second = 168;
            break;
        case 169:
            second = 254;
            break;
    }
    return String.format("%d.%d.%d.%d", first, second, third, fourth);
}
Also used : RandomService(com.github.javafaker.service.RandomService)

Example 3 with RandomService

use of com.github.javafaker.service.RandomService in project com-liferay-apio-architect by liferay.

the class BlogPostingModel method compute.

/**
 * Computes the fake data for this model class.
 */
public static void compute() {
    if (!_blogPostings.isEmpty()) {
        return;
    }
    for (long index = 0; index < 42; index++) {
        Faker faker = new Faker();
        Book book = faker.book();
        Lorem lorem = faker.lorem();
        RandomService randomService = faker.random();
        int creatorId = randomService.nextInt(PersonModel.getCount());
        DateAndTime dateAndTime = faker.date();
        Date date = dateAndTime.past(400, DAYS);
        BlogPostingModel blogPostingModel = new BlogPostingModel(_count.get(), lorem.paragraph(), date, creatorId, date, lorem.sentence(), book.title());
        _blogPostings.put(_count.getAndIncrement(), blogPostingModel);
    }
}
Also used : Lorem(com.github.javafaker.Lorem) Faker(com.github.javafaker.Faker) Book(com.github.javafaker.Book) RandomService(com.github.javafaker.service.RandomService) DateAndTime(com.github.javafaker.DateAndTime) Date(java.util.Date)

Example 4 with RandomService

use of com.github.javafaker.service.RandomService in project java-faker by DiUS.

the class Internet method publicIpV4Address.

/**
 * @return a valid public IPV4 address in dot notation
 */
public String publicIpV4Address() {
    final RandomService r = faker.random();
    final int[] PRIVATE_FIRST_OCTET = { 10, 127, 169, 192, 172 };
    int first = r.nextInt(256), second = r.nextInt(256), third = r.nextInt(256), fourth = r.nextInt(256);
    while (Arrays.binarySearch(PRIVATE_FIRST_OCTET, first) > 0) {
        first = r.nextInt(256);
    }
    return String.format("%d.%d.%d.%d", first, second, third, fourth);
}
Also used : RandomService(com.github.javafaker.service.RandomService)

Aggregations

RandomService (com.github.javafaker.service.RandomService)4 DateAndTime (com.github.javafaker.DateAndTime)2 Faker (com.github.javafaker.Faker)2 Date (java.util.Date)2 Address (com.github.javafaker.Address)1 Book (com.github.javafaker.Book)1 Internet (com.github.javafaker.Internet)1 Lorem (com.github.javafaker.Lorem)1 Name (com.github.javafaker.Name)1 Calendar (java.util.Calendar)1 YEAR (java.util.Calendar.YEAR)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 DAYS (java.util.concurrent.TimeUnit.DAYS)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1