package de.cas.mse.address.map.data;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.IntStream;

import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
public class DataLoader {

	public enum DataSize {
		SMALL, LARGE;
	}

	private AddressCatalogue addressCatalogue;

	@Inject
	public DataLoader(AddressCatalogue addressCatalogue) {
		this.addressCatalogue = addressCatalogue;
	}

	public void loadAddessesFromCsv(DataSize size) {
		try {
			List<String> lines = Files.readAllLines(Paths.get("data/addresses-small.data"));
			int factor;
			if (size == DataSize.SMALL) {
				factor = 1;
			} else {
				factor = 5;
			}

			for (String line : lines) {
				String[] parts = line.split(";");
				Address a = new Address();
				a.setName(parts[0]);
				a.setStreet(parts[1]);
				a.setZip(parts[2]);
				a.setTown(parts[3]);
				IntStream.of(factor).forEach(e -> addressCatalogue.getAddresses().add(a));
			}
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
}

@@ -714,16 +714,62 @@
 ;%0A%09%09%09%7D%0A%0A
+%09%09%09IntStream.range(0, factor).forEach(e -%3E %7B%0A%09
 %09%09%09for (
@@ -787,24 +787,25 @@
  : lines) %7B%0A
+%09
 %09%09%09%09String%5B%5D
@@ -830,16 +830,17 @@
 t(%22;%22);%0A
+%09
 %09%09%09%09Addr
@@ -862,24 +862,25 @@
 ress();%0A%09%09%09%09
+%09
 a.setName(pa
@@ -884,24 +884,25 @@
 (parts%5B0%5D);%0A
+%09
 %09%09%09%09a.setStr
@@ -912,24 +912,25 @@
 (parts%5B1%5D);%0A
+%09
 %09%09%09%09a.setZip
@@ -941,24 +941,25 @@
 ts%5B2%5D);%0A%09%09%09%09
+%09
 a.setTown(pa
@@ -975,42 +975,9 @@
 %09%09%09%09
-IntStream.of(factor).forEach(e -%3E 
+%09
 addr
@@ -1014,15 +1014,22 @@
 d(a)
-)
 ;%0A%09%09%09
-%7D
+%09%7D%0A%09%09%09%7D);
 %0A%09%09%7D

fix loader to really deliver really a large amount of data if requested