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)) {
                if (oldMap.containsKey("revid")) {
                    Map<String, Object> old = oldMap.get(title);
                    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();
        }
    }
}

@@ -1193,107 +1193,100 @@
     
-if (oldMap.containsKey(%22revid%22)) %7B%0A                    Map%3CString, Object%3E old = oldMap.get(title);
+Map%3CString, Object%3E old = oldMap.get(title);%0A                if (old.containsKey(%22revid%22)) %7B
 %0A   

modify DiffRecentchangesOfSeiyuConsumer logic