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

querqy.PriorityComparator Maven / Gradle / Ivy

There is a newer version: 3.18.1
Show newest version
package querqy;

import java.util.Comparator;
import java.util.List;
import java.util.Objects;

public class PriorityComparator implements Comparator {

    private final List> comparators;

    public PriorityComparator(final List> comparators) {
        this.comparators = comparators;
    }


    @Override
    public int compare(final T o1, final T o2) {
        for (final Comparator comparator : comparators) {
            int c = comparator.compare(o1, o2);
            if (c != 0) {
                return c;
            }
        }
        return 0;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof PriorityComparator)) return false;
        PriorityComparator that = (PriorityComparator) o;
        return Objects.equals(comparators, that.comparators);
    }

    @Override
    public int hashCode() {
        return Objects.hash(comparators);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy