package examples;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.HashMap;

import frege.runtime.Runtime;

public final class JHashMap {

	public static void main(String[] args) {
		try {
			if ("count".equals(args[0])) 
				count();
			else if ("uniq".equals(args[0]))
				uniq();
		} 
		catch (IOException e) {}
	}
	
	static int wörter = 0;
	
	public static void uniq() throws IOException {
		HashMap<String, Integer> map = new HashMap<>();
		
		String line = null;
		Pattern words = Pattern.compile("\\w+", 448);	// same mode as in Frege, for fairness
		int result = 0;
		BufferedReader in = Runtime.stdin.get();
		
		while ((line = in.readLine()) != null) {
			Matcher m = words.matcher(line);
			while (m.find()) {
				String key = m.group();
				Integer n = map.get(key);
				if (n == null) map.put(key, 1);
				else map.put(key, n+1);
			}
		}
		map.values().stream().forEach(arg -> wörter+=arg);
		System.err.println(wörter);
		System.out.println(map.size());

	}
	
	public static void count() throws IOException {
		String line = null;
		Pattern words = Pattern.compile("\\w+", 448);	// same mode as in Frege, for fairness
		int result = 0;
		
		while ((line = Runtime.stdin.get().readLine()) != null) {
			Matcher m = words.matcher(line);
			while (m.find()) result++;
		}
		System.out.println(result);
	}
	
}

@@ -410,30 +410,8 @@
 %0A%09%0A%09
-static int w%C3%B6rter = 0;
 %0A%09%0A%09
@@ -613,32 +613,35 @@
  for fairness%0A%09%09
+// 
 int result = 0;%0A
@@ -924,57 +924,64 @@
 %7D%0A%09%09
-map.values().stream().forEach(arg -%3E
+int w%C3%B6rter = 0;%0A%09%09for (int n : map.values())
  w%C3%B6rter
+ 
 +=
-arg)
+ n
 ;%0A%09%09

make it work in java7