package com.thinkaurelius.titan.diskstorage.writeaggregation;

import com.thinkaurelius.titan.diskstorage.Entry;

import java.nio.ByteBuffer;
import java.util.List;

/**
 * (c) Matthias Broecheler (me@matthiasb.com)
 */

public class Mutation {

    private List<Entry> additions;

    private List<ByteBuffer> deletions;

    public Mutation(List<Entry> additions, List<ByteBuffer> deletions) {
        this.additions=additions;
        this.deletions=deletions;
    }

    public boolean hasAdditions() {
        return additions!=null && !additions.isEmpty();
    }

    public boolean hasDeletions() {
        return deletions!=null && !deletions.isEmpty();
    }

    public List<Entry> getAdditions() {
        return additions;
    }

    public List<ByteBuffer> getDeletions() {
        return deletions;
    }
    
    public void merge(Mutation m) {
        if (additions==null) additions = m.additions;
        else additions.addAll(m.additions);
        
        if (deletions==null) deletions = m.deletions;
        else deletions.addAll(m.deletions);
    }

}

@@ -857,24 +857,117 @@
 ) %7B%0A    
+%09%0A
     
+%09
 if (
+null == m) %7B%0A    %09%09return;%0A    %09%7D%0A    %09%0A    %09if (null != m.additions) %7B%0A    %09%09if (null == 
 addition
@@ -967,22 +967,16 @@
 dditions
-==null
 ) additi
@@ -994,28 +994,26 @@
 itions;%0A    
-    
+%09%09
 else additio
@@ -1040,20 +1040,24 @@
 s);%0A    
+%09%7D%0A
     
+%09
 %0A       
@@ -1061,16 +1061,60 @@
     if (
+null != m.deletions) %7B%0A        %09if (null == 
 deletion
@@ -1118,14 +1118,8 @@
 ions
-==null
 ) de
@@ -1149,16 +1149,17 @@
         
+%09
 else del
@@ -1182,21 +1182,31 @@
 deletions);%0A
+        %7D%0A
     %7D%0A%0A%7D%0A

Add null checks in Mutation#merge for #40 (cherry picked from commit 533a0a47956f744d6ef6c95977607316f3970ab9)