-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathNameGen.java
54 lines (47 loc) · 1.89 KB
/
NameGen.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
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright Decodable, Inc.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package co.decodable.demos.webhooks;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
public class App {
public static void main(String[] args) {
List<Committer> committers = Arrays.asList(
new Committer("Catalina Lehner", "[email protected]", 0.3),
new Committer("Omer Kreiger", "[email protected]", 0.10),
new Committer("Thuy Schamberger", "[email protected]", 0.20),
new Committer("Gerry Marquardt", "[email protected]", 0.05),
new Committer("Edward Kuhlman", "[email protected]", 0.03),
new Committer("Kent Weissnat", "[email protected]", 0.07),
new Committer("Denver Rosenbaum", "[email protected]", 0.09),
new Committer("Ruben Runolfsson", "[email protected]", 0.02),
new Committer("Jone Collier", "[email protected]", 0.08),
new Committer("Alexander Davis", "[email protected]", 0.06)
);
double sum = 0;
Map<Committer, Double> accumulatedWeight = new LinkedHashMap<>();
for (Committer committer : committers) {
sum += committer.weight;
accumulatedWeight.put(committer, sum);
}
Random random = new Random();
double value = random.nextDouble();
for (Entry<Committer, Double> committer : accumulatedWeight.entrySet()) {
if(value < committer.getValue()) {
System.out.println(committer.getKey().name() + " <" + committer.getKey().email + ">");
break;
}
}
}
private record Committer(String name, String email, double weight) {
}
}