package com.heroku.myapp.myorchestrator.consumers.snapshot.seiyu;

import com.heroku.myapp.commons.consumers.DiffQueueConsumer;
import com.heroku.myapp.commons.util.content.DocumentUtil;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.bson.Document;
import org.springframework.stereotype.Component;

@Component
public class DiffRecentchangesOfSeiyuConsumer extends DiffQueueConsumer {

    @Override
    public Optional<Document> calculateDiff(Document master, Document snapshot) {
        List<Map<String, Object>> newList = new DocumentUtil().setDocument(snapshot).getData();
        List<Map<String, Object>> oldList = new DocumentUtil().setDocument(master).getData();
        Map<Object, Map<String, Object>> oldMap = new LinkedHashMap<>();
        oldList.stream().forEach((map) -> oldMap.put(oldMap.get("title"), map));
        List<Map<String, Object>> collect = newList.stream().filter((map) -> {
            Object title = map.get("title");
            if (!map.containsKey("revid")) {
                return false;
            } else if (oldMap.containsKey(title)) {
                Map<String, Object> old = oldMap.get(title);
                if (old.containsKey("revid")) {
                    if (old.get("revid").equals(map.get("old_revid"))) {
                        return true;
                    } else {
                        throw new RuntimeException();
                    }
                } else {
                    return true;
                }
            } else {
                return true;
            }
        }).collect(Collectors.toList());
        if (collect.isEmpty()) {
            return Optional.empty();
        } else {
            return new DocumentUtil().setDiff(collect).nullable();
        }
    }
}

@@ -894,20 +894,17 @@
 Map.put(
-oldM
+m
 ap.get(%22
@@ -983,145 +983,154 @@
 am()
-.filter((map) -%3E %7B%0A            Object title = map.get(%22title%22);%0A            if (!map.containsKey(%22revid%22)) %7B%0A                return false
+%0A                .filter((map) -%3E map.containsKey(%22revid%22))%0A                .filter((map) -%3E %7B%0A                    Object title = map.get(%22title%22)
 ;%0A  
@@ -1139,22 +1139,23 @@
         
+ 
-%7D else
+      
  if (old
@@ -1176,24 +1176,32 @@
 y(title)) %7B%0A
+        
             
@@ -1257,32 +1257,40 @@
                 
+      
+  
 if (old.contains
@@ -1301,24 +1301,32 @@
 %22revid%22)) %7B%0A
+        
             
@@ -1402,32 +1402,40 @@
                 
+       
+ 
 return true;%0A   
@@ -1443,32 +1443,40 @@
                 
+        
 %7D else %7B%0A       
@@ -1492,16 +1492,24 @@
         
+       
+ 
 throw ne
@@ -1542,34 +1542,50 @@
                 
-%7D%0A
+        %7D%0A        
                 
@@ -1605,32 +1605,40 @@
                 
+        
 return true;%0A   
@@ -1626,32 +1626,40 @@
    return true;%0A
+        
                 
@@ -1664,32 +1664,40 @@
   %7D%0A            
+        
 %7D else %7B%0A       
@@ -1681,32 +1681,40 @@
        %7D else %7B%0A
+        
                 
@@ -1730,34 +1730,50 @@
 ue;%0A            
-%7D%0A
+        %7D%0A        
         %7D).colle

modify DiffRecentchangesOfSeiyuConsumer logic