Giter Site home page Giter Site logo

datamaker's Introduction

DataMaker

Java data generator

A simple dummy generator using Java Faker that can generate data with recursive lists or trees of objects, for example, people with friends, of family, etc. It can manage different random levels of depth in collections and also different random sizes of collections. The only thing you need to do is mark the collections with an annotation : SelfCollection.

Example:

        table.setItems((new DataMaker()
                .setLocaleName("es_ES")
                .setDepthOfSelfCollections(0)
                .setSizeOfCollections(100)
                .makeObservableList(Person.class)
                ));
public class Person {

    public Person() {
        super();
    }


    public static Faker faker() {
        return DataMaker.faker();
    }

    @Override
    public String toString() {
        return "Person [children=" + this.children + ", id=" + this.id + ", firstName=" + this.firstName + ", lastName="
                + this.lastName + ", gender=" + this.gender + ", single=" + this.single + ", birthDate="
                + this.birthDate + ", age=" + this.age + ", getChildren()=" + getChildren() + "]";
    }

    ObservableList<Person> children = FXCollections.observableArrayList();

    @SelfCollection(minSize = 1, maxSize = 1, minDepth = 1, maxDepth = 1)
    public ObservableList<Person> getChildren() {
        return this.children;
    }

    static int sequentialNumber = 0;
    private final IntegerProperty id = new SimpleIntegerProperty(sequentialNumber++);

    private StringProperty firstName = new SimpleStringProperty(faker().name().firstName());

    private final StringProperty lastName = new SimpleStringProperty(faker().name().lastName());

    private final StringProperty gender = new SimpleStringProperty(faker().bool().bool() ? "HOMBRE" : "MUJER");

    private final BooleanProperty single = new SimpleBooleanProperty(faker().bool().bool());

    private final ObjectProperty<LocalDate> birthDate = new SimpleObjectProperty<>(
            (faker().date().birthday().toInstant().atZone(ZoneId.systemDefault())).toLocalDate());

    private final IntegerProperty age = new SimpleIntegerProperty(
            LocalDate.now().getYear() - this.birthDate.get().getYear());

    public final IntegerProperty idProperty() {
        return this.id;
    }

    public final int getId() {
        return this.idProperty().get();
    }

    public final void setId(final int id) {
        this.idProperty().set(id);
    }

    public StringProperty firstNameProperty() {
        return this.firstName;
    }

    public String getFirstName() {
        return this.firstNameProperty().get();
    }

    public void setFirstName(final String firstName) {
        this.firstNameProperty().set(firstName);
    }

    public final StringProperty lastNameProperty() {
        return this.lastName;
    }

    public final String getLastName() {
        return this.lastNameProperty().get();
    }

    public final void setLastName(final String lastName) {
        this.lastNameProperty().set(lastName);
    }

    public final StringProperty genderProperty() {
        return this.gender;
    }

    public final String getGender() {
        return this.genderProperty().get();
    }

    public final void setGender(final String gender) {
        this.genderProperty().set(gender);
    }

    public final BooleanProperty singleProperty() {
        return this.single;
    }

    public final boolean isSingle() {
        return this.singleProperty().get();
    }

    public final void setSingle(final boolean single) {
        this.singleProperty().set(single);
    }

    public final ObjectProperty<LocalDate> birthDateProperty() {
        return this.birthDate;
    }

    public final LocalDate getBirthDate() {
        return this.birthDateProperty().get();
    }

    public final void setBirthDate(final LocalDate birthDate) {
        this.birthDateProperty().set(birthDate);
    }

    public final IntegerProperty ageProperty() {
        return this.age;
    }

    public final int getAge() {
        return this.ageProperty().get();
    }

    public final void setAge(final int age) {
        this.ageProperty().set(age);
    }

    public enum Gender {

        FEMALE("MUJER", "Female"), MALE("HOMBRE", "Male");

        private final String code;
        private final String text;

        private Gender(final String code, final String text) {
            this.code = code;
            this.text = text;
        }

        public String getCode() {
            return this.code;
        }

        public String getText() {
            return this.text;
        }

        public static Gender getByCode(final String genderCode) {
            for (final Gender g : Gender.values()) {
                if (g.code.equals(genderCode)) {
                    return g;
                }
            }
            return null;
        }

        @Override
        public String toString() {
            return this.text;
        }

    }

}                

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.