blob: bdb1e668f84100796d769281253414630682e99a (
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.grouping.request;
/**
* This class represents an Infinite value that may be used as a bucket
* size specifier. This is immutable.
*
* @author Ulf Lilleengen
*/
@SuppressWarnings("rawtypes")
public class Infinite implements Comparable {
private final boolean negative;
/**
* Create an Infinite object with positive or negative sign.
*
* @param negative the signedness.
*/
public Infinite(boolean negative) {
this.negative = negative;
}
/**
* Override the toString method in order to be re-parseable.
*/
@Override
public String toString() {
return (negative ? "-inf" : "inf");
}
/**
* An infinity value is always less than or greater than.
*/
@Override
public int compareTo(Object rhs) {
return (negative ? -1 : 1);
}
@Override
public boolean equals(Object other) {
if (other == this) return true;
if ( ! (other instanceof Infinite)) return false;
return this.negative == ((Infinite)other).negative;
}
@Override
public int hashCode() { return negative ? -1 : 1; }
}
|