aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/grouping/request/ConstantValueComparator.java
blob: 6d15e1678900b0d210117d6ec141cca9da8713dd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.grouping.request;

import java.util.Comparator;

/**
 * This class compares two constant values, and takes into account that one of
 * the arguments may be the very special infinity value.
 *
 * @author Ulf Lilleengen
 */
@SuppressWarnings("rawtypes")
public class ConstantValueComparator implements Comparator<ConstantValue> {

    @SuppressWarnings("unchecked")
    @Override
    public int compare(ConstantValue lhs, ConstantValue rhs) {
        // Run infinite comparison method if one of the arguments are infinite.
        if (rhs instanceof InfiniteValue) {
            return (-1 * rhs.getValue().compareTo(lhs));
        }
        return (lhs.getValue().compareTo(rhs.getValue()));
    }

}