class LimitViolationComparator implements Comparator<LimitViolation> {

    @Override
    public int compare(LimitViolation violation1, LimitViolation violation2) {
        Objects.requireNonNull(violation1);
        Objects.requireNonNull(violation2);
        if (violation1.getSubjectId().compareTo(violation2.getSubjectId()) == 0) {
            if (violation1.getLimitType().compareTo(violation2.getLimitType()) == 0) {
                if (LimitViolationType.CURRENT == violation1.getLimitType()) {
                    return violation1.getSide().compareTo(violation2.getSide());
                }
                return 0;
            }
            return violation1.getLimitType().compareTo(violation2.getLimitType());
        }
        return violation1.getSubjectId().compareTo(violation2.getSubjectId());
    }

}