package com.dlvr.continuum.core.db.slice;

import com.dlvr.continuum.atom.Atom;
import com.dlvr.continuum.db.slice.Filter;
import com.dlvr.continuum.db.slice.Slice;

/**
 * Filter non-matching partices in slices
 * Created by zack on 2/23/16.
 */
public class ParticlesFilter implements Filter {

    private final Slice slice;

    public ParticlesFilter(Slice slice) {
        this.slice = slice;
    }

    @Override
    public Action filter(Atom atom) {
        if (slice.particles() == null) return Action.CONTINUE;
        if (atom.particles() == null) return Action.SKIP;

        for (String name : slice.particles().keySet()) {
            String atomVal = atom.particles().get(name);
            String sliceVal = slice.particles().get(name);
            if (sliceVal == null) continue;
            if (atomVal == null) return Action.STOP;
            if (!atomVal.equals((sliceVal))) {
                return Action.STOP;
            }
        }

        return Action.CONTINUE;
    }
}

@@ -830,34 +830,34 @@
  return Action.S
-TO
+KI
 P;%0A            i
@@ -892,59 +892,27 @@
 ))) 
-%7B%0A                return Action.STOP;%0A            %7D
+return Action.SKIP;
 %0A   

correct filtering