All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.javarig.generator.InstantGenerator Maven / Gradle / Ivy

Go to download

This project aims to provide a random instances generator for any class in java, it iterates through setters of an empty object and sets the fields values (using Java reflection api) randomly

The newest version!
package io.javarig.generator;

import io.javarig.RandomInstanceGenerator;

import java.lang.reflect.Type;
import java.time.Instant;
import java.time.LocalDate;

import static java.time.ZoneOffset.UTC;

public class InstantGenerator extends TypeGenerator {

    private final Instant MIN_INSTANT = Instant.ofEpochMilli(0);
    private final Instant MAX_INSTANT = LocalDate.of(2100, 12, 31).atStartOfDay(UTC).toInstant();

    public InstantGenerator(Type type, RandomInstanceGenerator randomInstanceGenerator) {
        super(type, randomInstanceGenerator);
    }

    @Override
    public Instant generate() {
        return Instant.ofEpochMilli(getRandom().nextLong(MIN_INSTANT.toEpochMilli(), MAX_INSTANT.toEpochMilli()));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy