-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathGenerator.java
69 lines (53 loc) · 2.17 KB
/
Generator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package data;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toList;
/**
* @author Simon Popugaev
*/
public class Generator {
private static final int EMPLOYEES_COUNT = 12;
public static String generateString() {
final String letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
final int maxLength = 10;
final int length = ThreadLocalRandom.current().nextInt(maxLength) + 1;
return IntStream.range(0, length)
.mapToObj(letters::charAt)
.map(Object::toString)
.collect(Collectors.joining());
}
public static Person generatePerson() {
return new Person(generateString(), generateString(), 18 + ThreadLocalRandom.current().nextInt(50));
}
public static JobHistoryEntry generateJobHistoryEntry() {
final int maxDuration = 10;
final int duration = ThreadLocalRandom.current().nextInt(maxDuration) + 1;
return new JobHistoryEntry(duration, generatePosition(), generateEmployer());
}
public static String generateEmployer() {
final String[] employers = {"epam", "google", "yandex", "abc"};
return employers[ThreadLocalRandom.current().nextInt(employers.length)];
}
public static String generatePosition() {
final String[] positions = {"dev", "QA", "BA"};
return positions[ThreadLocalRandom.current().nextInt(positions.length)];
}
public static List<JobHistoryEntry> generateJobHistory() {
int maxLength = 10;
final int length = ThreadLocalRandom.current().nextInt(maxLength) + 1;
return Stream.generate(Generator::generateJobHistoryEntry)
.limit(length)
.collect(toList());
}
public static Employee generateEmployee() {
return new Employee(generatePerson(), generateJobHistory());
}
public static List<Employee> generateEmployeeList() {
return Stream.generate(Generator::generateEmployee)
.limit(EMPLOYEES_COUNT)
.collect(toList());
}
}