import java.util.*;
import java.util.Map.*;

public class Babel
{
    public Babel (boolean debug)
    {
        _debug = debug;
    }

    public int translate (Vector<Food> foods)
    {
        HashMap<String, Vector<String>> mapped = new HashMap<String, Vector<String>>();
        
        for (int i = 0; i < foods.size(); i++)
        {
            Food toCheck = foods.elementAt(i);
            
            toCheck.getIngredients().forEach(ingredient -> count.put(ingredient, count.getOrDefault(ingredient, 0) + 1));

            for (String allergen : toCheck.getAllergens())
            {
                mapped.computeIfAbsent(allergen, key -> new Vector<String>(toCheck.getIngredients()));
                mapped.get(allergen).retainAll(toCheck.getIngredients());
            }
        }

        if (_debug)
            System.out.println("Mapped "+mapped.size());

        int totalOccurrences = count.entrySet().stream().filter(
                                ingredient -> mapped.entrySet().stream()
                                .noneMatch(entry -> entry.getValue().contains(ingredient.getKey())))
                                .mapToInt(Entry::getValue)
                                .sum();
        
        return totalOccurrences;
    }
    
    private boolean _debug;
}
@@ -385,143 +385,8 @@
 (i);
-%0A            %0A            toCheck.getIngredients().forEach(ingredient -%3E count.put(ingredient, count.getOrDefault(ingredient, 0) + 1));
 %0A%0A  
@@ -748,64 +748,244 @@
     
-int totalOccurrences = count.entrySet().stream().filter(
+while (mapped.entrySet().stream().anyMatch(entry -%3E entry.getValue().size() != 1))%0A        %7B%0A            for (Entry%3CString, Vector%3CString%3E%3E specific : mapped.entrySet())%0A            %7B%0A                if (specific.getValue().size() == 1)
 %0A   
@@ -987,32 +987,36 @@
 )%0A              
+  %7B%0A
                 
@@ -1017,16 +1017,25 @@
         
+  String 
 ingredie
@@ -1041,135 +1041,420 @@
 ent 
--%3E mapped.entrySet().stream()%0A                                .noneMatch(entry -%3E entry.getValue().contains(ingredient.getKey()
+= specific.getValue().firstElement();%0A            %0A                    System.out.println(%22Looking at %22+ingredient+%22 from %22+specific);%0A%0A                    for (Entry%3CString, Vector%3CString%3E%3E other : mapped.entrySet())%0A                    %7B%0A                        System.out.println(%22Now looking at %22+other.getKey()+%22 and %22+specific.getKey());%0A%0A                        if (!other.getKey().equals(specific.getKey(
 )))%0A
@@ -1461,32 +1461,42 @@
                 
+        %7B%0A
                 
@@ -1499,34 +1499,129 @@
     
-.mapToInt(Entry::getValue)
+            System.out.println(%22Removing %22+ingredient);%0A%0A                            other.getValue().remove(ingredient);
 %0A   
@@ -1626,32 +1626,41 @@
                 
+       %7D%0A
                .
@@ -1662,15 +1662,56 @@
     
-.sum();
+     %7D%0A                %7D%0A            %7D%0A        %7D
 %0A   
@@ -1735,24 +1735,9 @@
 urn 
-totalOccurrences
+0
 ;%0A  

Update Babel.java