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.hbase.metrics;
20  
21  import com.google.common.base.Objects;
22  import com.google.common.base.Preconditions;
23  
24  import org.apache.hadoop.classification.InterfaceAudience;
25  import org.apache.hadoop.metrics2.MetricsInfo;
26  
27  /**
28   * Making implementing metric info a little easier
29   */
30  @InterfaceAudience.Private
31  class MetricsInfoImpl implements MetricsInfo {
32    private final String name, description;
33  
34    MetricsInfoImpl(String name, String description) {
35      this.name = Preconditions.checkNotNull(name, "name");
36      this.description = Preconditions.checkNotNull(description, "description");
37    }
38  
39    @Override public String name() {
40      return name;
41    }
42  
43    @Override public String description() {
44      return description;
45    }
46  
47    @Override public boolean equals(Object obj) {
48      if (obj instanceof MetricsInfo) {
49        MetricsInfo other = (MetricsInfo) obj;
50        return Objects.equal(name, other.name()) &&
51            Objects.equal(description, other.description());
52      }
53      return false;
54    }
55  
56    @Override public int hashCode() {
57      return Objects.hashCode(name, description);
58    }
59  
60    @Override public String toString() {
61      return Objects.toStringHelper(this)
62          .add("name", name).add("description", description)
63          .toString();
64    }
65  }