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(map.get("title"), map));
        List<Map<String, Object>> collect = newList.stream()
                .filter((map) -> map.containsKey("revid"))
                .filter((map) -> {
                    Object title = map.get("title");
                    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();
        }
    }
}

@@ -780,22 +780,22 @@
     Map%3C
-Object
+String
 , Map%3CSt
@@ -894,16 +894,25 @@
 Map.put(
+(String) 
 map.get(
@@ -1107,22 +1107,22 @@
     
-Object
+String
  title =
  map
@@ -1117,16 +1117,25 @@
  title =
+ (String)
  map.get
@@ -1355,56 +1355,570 @@
     
-if (old.get(%22revid%22).equals(map.get(%22old_revid%22)
+String old_new_revid = (String) old.get(%22revid%22);%0A                            String new_old_revid = (String) map.get(%22old_revid%22);%0A                            if (old_new_revid.equals(new_old_revid)) %7B%0A                                return true;%0A                            %7D else %7B%0A                                String old_old_revid = (String) old.get(%22old_revid%22);%0A                                String new_new_revid = (String) map.get(%22revid%22);%0A                                if (old_old_revid.equals(new_old_revid) && old_new_revid.equals(new_new_revid
 )) %7B
@@ -1946,37 +1946,46 @@
             
+    
 return 
-true;%0A
+false;%0A    
             
@@ -2041,16 +2041,20 @@
         
+   
+ 
 throw ne
@@ -2071,24 +2071,58 @@
 xception();%0A
+                                %7D%0A
             

modify DiffRecentchangesOfSeiyuConsumer logic