package com.capgemini.reports.definition.r19report;

import com.capgemini.reports.snecmaobjects.part.AbstractPart;

import java.io.Serializable;
import java.util.Comparator;

/**
 * {@link AbstractPart} {@link Comparator}. Compares the Item ID, then the Revision ID. If both are equal, parts are considered equal.
 */
public class PartIdRevComparator implements Comparator<AbstractPart>, Serializable {
    private static final long serialVersionUID = 618467339673492686L;

    /**
     * Compare two Abstract by their item_id and revision_id.
     *
     * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
     */
    @Override
    public int compare(final AbstractPart part1, final AbstractPart part2) {
        int comparatorValue = part1.getItemId().compareTo(part2.getItemId());
        if (comparatorValue == 0) {
            comparatorValue = part1.getRevisionId().compareTo(part2.getRevisionId());
        }
        return comparatorValue;
    }

}
