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

com.selesse.jxlint.model.LintErrorOrderings Maven / Gradle / Ivy

The newest version!
package com.selesse.jxlint.model;

import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Ordering;
import com.google.common.primitives.Ints;
import com.selesse.jxlint.model.rules.LintError;

import javax.annotation.Nullable;

public class LintErrorOrderings {
    private static Ordering lineNumberOrdering = new Ordering() {
        @Override
        public int compare(@Nullable LintError left, @Nullable LintError right) {
            return Ints.compare(left.getLineNumber(), right.getLineNumber());
        }
    };

    private static Ordering categoryNameOrdering = new Ordering() {
        @Override
        public int compare(@Nullable LintError left, @Nullable LintError right) {
            return LintRuleOrderings.getCategoryThenNameOrdering().
                    compare(left.getViolatedRule(), right.getViolatedRule());
        }
    };

    private static Ordering categoryNameFileLineNumberOrdering = new Ordering() {
        @Override
        public int compare(@Nullable LintError left, @Nullable LintError right) {
            return ComparisonChain.start()
                    .compare(left.getViolatedRule(), right.getViolatedRule(),
                            LintRuleOrderings.getCategoryThenNameOrdering())
                    .compare(left.getFile(), right.getFile())
                    .compare(left.getLineNumber(), right.getLineNumber())
                    .result();
        }
    };

    private static final Ordering fileThenLineNumberOrdering = new Ordering() {
        @Override
        public int compare(@Nullable LintError left, @Nullable LintError right) {
            return ComparisonChain.start()
                    .compare(left.getFile(), right.getFile())
                    .compare(left.getLineNumber(), right.getLineNumber())
                    .result();
        }
    };

    public static Ordering getLineNumberOrdering() {
        return lineNumberOrdering;
    }

    public static Ordering getCategoryThenNameOrdering() {
        return categoryNameOrdering;
    }

    public static Ordering getCategoryNameFileLineNumberOrdering() {
        return categoryNameFileLineNumberOrdering;
    }

    public static Ordering getFileThenLineNumberOrdering() {
        return fileThenLineNumberOrdering;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy