View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.metrics2.util;
20  
21  import org.apache.hadoop.hbase.classification.InterfaceAudience;
22  
23  /**
24   * Specifies a quantile (with error bounds) to be watched by a
25   * {@link MetricSampleQuantiles} object.
26   */
27  @InterfaceAudience.Private
28  public class MetricQuantile {
29    public final double quantile;
30    public final double error;
31  
32    public MetricQuantile(double quantile, double error) {
33      this.quantile = quantile;
34      this.error = error;
35    }
36  
37    @Override
38    public boolean equals(Object aThat) {
39      if (this == aThat) {
40        return true;
41      }
42      if (!(aThat instanceof MetricQuantile)) {
43        return false;
44      }
45  
46      MetricQuantile that = (MetricQuantile) aThat;
47  
48      long qbits = Double.doubleToLongBits(quantile);
49      long ebits = Double.doubleToLongBits(error);
50  
51      return qbits == Double.doubleToLongBits(that.quantile)
52          && ebits == Double.doubleToLongBits(that.error);
53    }
54  
55    @Override
56    public int hashCode() {
57      return (int) (Double.doubleToLongBits(quantile) ^ Double
58          .doubleToLongBits(error));
59    }
60  }