Created
February 1, 2016 07:27
-
-
Save kabutz/e1e07c6decc770efee02 to your computer and use it in GitHub Desktop.
LuckyDraw used to decide who gets a place at JCrete® 2016
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.nio.file.*; | |
import java.util.*; | |
import java.util.concurrent.*; | |
import java.util.stream.*; | |
public class LuckyDraw { | |
public static void main(String... args) throws IOException { | |
List<Entry> list = Files.lines(Paths.get("luckydraw.csv")) | |
.map(Entry::new) | |
.collect(Collectors.toList()); | |
Collections.shuffle(list, ThreadLocalRandom.current()); | |
System.out.println("id,LuckyDraw2016Order"); | |
for (int i = 0; i < list.size(); i++) { | |
Entry entry = list.get(i); | |
System.out.println(entry.id + "," + (i + 1)); | |
} | |
} | |
private static class Entry { | |
private final int id; | |
private final String name; | |
private final String email; | |
public Entry(String line) { | |
String[] items = line.split(","); | |
if (items.length != 3) | |
throw new AssertionError( | |
"Invalid line: " + Arrays.toString(items)); | |
System.out.println(Arrays.toString(items)); | |
id = Integer.parseInt(items[0]); | |
name = items[1]; | |
email = items[2]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment