@@ -0,0 +1,2509 @@
+/* %0A* @Author: Zeyuan Shang%0A* @Date:   2016-01-22 22:59:02%0A* @Last Modified by:   Zeyuan Shang%0A* @Last Modified time: 2016-01-22 22:59:11%0A*/%0A//Author Shafaet, shafaet@hackerrank.com%0Aimport java.util.*;%0Aimport org.json.simple.JSONObject;%0Aimport org.json.simple.JSONArray;  %0Aimport org.json.simple.JSONObject;  %0A%0Aclass MapReduce%0A%7B%0A   private LinkedHashMap intermediate;%0A   private JSONObject finalResult = new JSONObject();%0A   private int resultCount;%0A   MapReduce()%0A   %7B%0A      resultCount=0;%0A      finalResult = new JSONObject();%0A      intermediate=new LinkedHashMap();%0A   %7D%0A   %0A   JSONObject execute(JSONObject inputdata)%0A   %7B%0A      for(int i=0;i%3Cinputdata.size();i++)%0A      %7B%0A         JSONObject record=(JSONObject)inputdata.get(i);%0A         mapper(record);%0A      %7D%0A      %0A      Iterator it = intermediate.entrySet().iterator();%0A      while (it.hasNext()) %7B%0A         Map.Entry pair = (Map.Entry)it.next();%0A         reducer((int)pair.getKey(), (ArrayList)pair.getValue());%0A         it.remove();%0A      %7D%0A      return finalResult;%0A   %7D%0A   private void emit(LinkedHashMap obj)%0A   %7B%0A      finalResult.put(resultCount++,obj);%0A   %7D%0A   private %3CT%3E void reducer(T key, ArrayList value)%0A   %7B%0A      LinkedHashMap obj=new LinkedHashMap();%0A     obj.put(%22key%22,key);%0A     obj.put(%22value%22,key);%0A     emit(obj);%0A   %7D%0A   private void mapper(JSONObject record)%0A   %7B%0A      int value=(int)record.get(%22value%22);%0A      if (value %3E 10 && value %25 2 == 1) %7B%0A        emitIntermediate(value,1);%0A      %7D%0A   %7D%0A   private  %3CT1,T2%3E  void emitIntermediate(T1 key, T2 value)%0A   %7B%0A      if(!intermediate.containsKey(key))%0A         intermediate.put(key,new ArrayList());%0A%0A      ArrayList temp=(ArrayList)intermediate.get(key);%0A      temp.add(value);%0A      intermediate.put(key,temp);%0A   %7D%0A%7D%0Apublic class Main%0A%7B%0A   %0A   public static void main(String %5B%5Dargh)%0A   %7B%0A      JSONObject inputdata= new JSONObject();%0A      Scanner sc=new Scanner(System.in);%0A      int t=sc.nextInt();%0A      int linecount=0;%0A      for(int i=0;i%3Ct;i++)%0A      %7B%0A       int value=sc.nextInt(); %0A         Map obj=new JSONObject();%0A         obj.put(%22key%22,linecount);%0A         obj.put(%22value%22,value);%0A         %0A         inputdata.put(linecount++,obj);%0A      %7D%0A      MapReduce mapred= new MapReduce();%0A      JSONObject result=mapred.execute(inputdata); %0A   %0A      for(int i=0;i%3Cresult.size();i++)%0A      %7B%0A         LinkedHashMap record=(LinkedHashMap)result.get(i);%0A       int value=(int)record.get(%22value%22);%0A        %0A         System.out.println (value);%0A%0A      %7D%0A   %0A   %7D%0A   %0A%7D%0A%0A

add relational-mapreduce-patterns-1-selections