1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * 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 and16 * limitations under the License.17 */1819package org.apache.giraph.metrics;
2021import com.google.common.collect.ImmutableMap;
2223import java.util.concurrent.TimeUnit;
2425/**26 * Pair of long,TimeUnit27 */28publicclassLongAndTimeUnit {
29/** Mapping from TimeUnit to abbreviation used for printing */30privatestaticfinal ImmutableMap<TimeUnit, String> TIME_UNIT_TO_ABBREV =
31 ImmutableMap.<TimeUnit, String>builder().
32 put(TimeUnit.DAYS, "days").
33 put(TimeUnit.HOURS, "hours").
34 put(TimeUnit.MICROSECONDS, "us").
35 put(TimeUnit.MILLISECONDS, "ms").
36 put(TimeUnit.MINUTES, "mins").
37 put(TimeUnit.NANOSECONDS, "ns").
38 put(TimeUnit.SECONDS, "secs").build();
3940/** value held */41privatelong value;
42/** TimeUnit part */43private TimeUnit timeUnit;
4445 @Override
46public String toString() {
47if (timeUnit == null) {
48return String.valueOf(value);
49 } else {
50return value + " " + TIME_UNIT_TO_ABBREV.get(timeUnit);
51 }
52 }
5354/**55 * Get the value56 *57 * @return value58 */59publiclong getValue() {
60return value;
61 }
6263/**64 * Set the value65 *66 * @param value to set67 */68publicvoid setValue(long value) {
69this.value = value;
70 }
7172/**73 * Get the TimeUnit74 *75 * @return TimeUnit76 */77public TimeUnit getTimeUnit() {
78return timeUnit;
79 }
8081/**82 * Set the TimeUnit83 * @param timeUnit to set84 */85publicvoid setTimeUnit(TimeUnit timeUnit) {
86this.timeUnit = timeUnit;
87 }
88 }