All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.javaprinciples.data.transformer.DiffResult Maven / Gradle / Ivy

package net.sf.javaprinciples.data.transformer;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * A holder of differences.
 *
 * @author Warwick Slade
 */
public class DiffResult implements Serializable
{
    private boolean different;
    private Map fields;

    public enum Difference
    {
        BOTH_NULL,
        LEFT_NULL,
        RIGHT_NULL,
        SAME,
        DIFFERENT
    }

    public DiffResult(String field, Difference difference)
    {
        fields = new HashMap();
        fields.put(field, difference);
        different = difference != Difference.SAME && difference != Difference.BOTH_NULL;
    }

    public boolean isDifferent()
    {
        return different;
    }

    public Set getFields()
    {
        return fields.keySet();
    }

    public Difference getDifference(String field)
    {
        return fields.get(field);
    }

    public String toString()
    {
        return isDifferent() ? "Different" : "Same";
    }

    public void add(DiffResult e)
    {
        fields.putAll(e.fields);
        if (!different)
        {
            different = e.isDifferent();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy