Comments (2)
Support for non-static inner classes reflection can be a little bit tricky to implement at the level of reflection (because of how the library is done - i need a reference to the outer class but i don't have that since everything is created lazy...).
I will think of a solution for that, but until then I recommend you to use the filler() method that instead of using reflection is using a Supplier<T>
.
The code using filler should be like this:
List<Patient> patientList = mockNeat.filler(() -> {
Patient p = new Patient();
p.setdOB(
m.filler(() -> p.new DOB())
.setter(Patient.DOB::setEstimated, m.bools())
.setter(Patient.DOB::setPremature, m.bools())
.val()
);
return p;
})
.setter(Patient::setFirstName, m.names().first())
.setter(Patient::setLastName, m.names().last())
.list(() -> new ArrayList<>(), 10)
.val();
System.out.println(patientList);
Or if you want to de-couple the DOB
creation from the Patient
class:
Function<Patient, Patient> dobPopulator =
(patient) -> {
Patient.DOB dob = m.filler(() -> patient.new DOB())
.setter(Patient.DOB::setPremature, mockNeat.bools())
.setter(Patient.DOB::setEstimated, mockNeat.bools())
.val();
patient.setdOB(dob);
return patient;
};
List<Patient> patientList = mockNeat.filler(() -> new Patient())
.setter(Patient::setFirstName, m.names().first())
.setter(Patient::setLastName, m.names().last())
.map(dobPopulator)
.list(() -> new ArrayList<>(), 10)
.val();
System.out.println(patientList);
from mockneat.
For now, I will try to take out sub classes into the own classes, and their packages. I don't want to deal with getters and setters. Sub-classes, we were good for me because I could place class definitions for small types under a main object class definition. For now, I will try to organize into separate data packages and use mockneat for generating data. By the way, big thanks for your suggestions.
from mockneat.
Related Issues (20)
- Try Using Rultor, Makes Life Easier
- Automated Management
- Question: Is there have anyway support combine mock data
- markovs() function throw exception HOT 1
- question: How to add unique objects to a list HOT 3
- tutorial for shuffling a subset of properties, given an instance of object HOT 1
- Apache Common Text Vulnerabilities (version must be ≥ 1.9)
- localDates() does not work when using a formatter that contains time HOT 4
- subsequent run data consistency HOT 2
- If you can use it easily in spring or spring boot, it would be fine. HOT 1
- No instructions to use this project from Maven? HOT 10
- Industries is misspelled HOT 3
- using list(MockUnitInt) doesn't generate a new random value each time. HOT 6
- Website search broken HOT 1
- Incorrect documentation around secure random seeding
- bulk data vs sequential
- Markovs doesn't honor RandomType HOT 5
- Antivirus complains of Java Trojan for mockneat-0.3.8.jar HOT 7
- probabilities use double loss of accuracy HOT 3
- Question: Would be viable to use reflection to call mockneat data generators ? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mockneat.