package edu.qaware.cc.spark;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.AbstractMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;

import static java.util.stream.Collectors.counting;
import static java.util.stream.Collectors.groupingBy;

/**
 * A word count example implemented with plain Java 8 features
 *
 * @author f.lautenschlager
 */
public class JavaWordCount {

    private static final Logger LOGGER = LoggerFactory.getLogger(JavaWordCount.class);

    /**
     * TODO: Implement the extraction of words from a given line
     */
    private static final Function<String, Stream<String>> WORDS_EXTRACTOR =
            s -> {
                // TODO: Implement
                return null;
            };
    /**
     * TODO: Implement the mapping of words
     */
    private static final Function<String, AbstractMap.SimpleEntry<String, Long>> WORDS_MAPPER =
            word -> {
                // TODO: Implement
                return null;
            };

    /**
     * TODO: Implement the reduce step of the mapped words
     */
    private static final Function<AbstractMap.SimpleEntry<String, Long>, String> WORDS_REDUCER =
            t -> {
                // TODO: Implement
                return null;
            };

    /**
     * Runs the word count example with plain java 8 features.
     *
     * @param args ignored
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {

        String filePath = SparkWordCount.class.getResource("/largeText.txt").getPath();

        long start = System.currentTimeMillis();

        //Collect it to a map Executes the whole computation!
        Map<String, Long> result = Files.lines(Paths.get(filePath))
                .flatMap(WORDS_EXTRACTOR)
                .map(WORDS_MAPPER)
                .collect(groupingBy(WORDS_REDUCER, counting()));

        long end = System.currentTimeMillis();

        LOGGER.info("================================================================");
        LOGGER.info("Counted {} words in {} ms", result.keySet().size(), end - start);
        LOGGER.info("================================================================");
    }


}
@@ -105,24 +105,81 @@
 OException;%0A
+import java.net.URI;%0Aimport java.net.URISyntaxException;%0A
 import java.
@@ -1586,16 +1586,50 @@
 ception%0A
+     * @throws URISyntaxException%0A
      */%0A
@@ -1693,43 +1693,54 @@
 tion
- %7B%0A%0A        String filePath = Spark
+, URISyntaxException %7B%0A%0A        URI uri = Java
 Word
@@ -1785,15 +1785,13 @@
 t%22).
-getPath
+toURI
 ();%0A
@@ -1964,16 +1964,11 @@
 get(
-filePath
+uri
 ))%0A 

Use URI instead of path for input file