package org.academiadecodigo.enuminatti.wordhistogram;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * MIT License
 * (c) 2017 Ricardo Constantino
 */

public class Main {
    public static void main(String[] args) {
        String testPhrase = "pedro para para para para para carro banana";

        System.out.println("composition");
        WordHistogram histogram = new WordHistogram();
        histogram.putAll(testPhrase.split(" "));
        System.out.println("Used | Word");
        System.out.println("--------------");
        for (String word : histogram) {
            System.out.printf("%4d | %s\n", histogram.countUses(word), word);
        }



        System.out.println("\nusing Map's merge()");

        Map<String, Integer> mergedMap = new LinkedHashMap<>();

        for (String word : testPhrase.split(" "))
            mergedMap.merge(word, 1, Integer::sum);



        System.out.println("Used | Word");
        System.out.println("--------------");
        for (String word : mergedMap.keySet()) {
            System.out.printf("%4d | %s\n", mergedMap.get(word), word);
        }

        System.out.println("\ninheritance");
        HistogramMap histogramMap = new HistogramMap();
        histogramMap.addAll(testPhrase.split(" "));

        System.out.println("Used | Word");
        System.out.println("--------------");
        for (String word : histogramMap) {
            System.out.printf("%4d | %s\n", histogramMap.get(word), word);
        }
        System.out.println();
        System.out.println(histogramMap);

        // pedro 1
        // para 2
        // carro 1
        // banana 1
    }
}
