This project has retired. For details please refer to its Attic page.
LongAndTimeUnit xref
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.giraph.metrics;
20  
21  import com.google.common.collect.ImmutableMap;
22  
23  import java.util.concurrent.TimeUnit;
24  
25  /**
26   * Pair of long,TimeUnit
27   */
28  public class LongAndTimeUnit {
29    /** Mapping from TimeUnit to abbreviation used for printing */
30    private static final 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();
39  
40    /** value held */
41    private long value;
42    /** TimeUnit part */
43    private TimeUnit timeUnit;
44  
45    @Override
46    public String toString() {
47      if (timeUnit == null) {
48        return String.valueOf(value);
49      } else {
50        return value + " " + TIME_UNIT_TO_ABBREV.get(timeUnit);
51      }
52    }
53  
54    /**
55     * Get the value
56     *
57     * @return value
58     */
59    public long getValue() {
60      return value;
61    }
62  
63    /**
64     * Set the value
65     *
66     * @param value to set
67     */
68    public void setValue(long value) {
69      this.value = value;
70    }
71  
72    /**
73     * Get the TimeUnit
74     *
75     * @return TimeUnit
76     */
77    public TimeUnit getTimeUnit() {
78      return timeUnit;
79    }
80  
81    /**
82     * Set the TimeUnit
83     * @param timeUnit to set
84     */
85    public void setTimeUnit(TimeUnit timeUnit) {
86      this.timeUnit = timeUnit;
87    }
88  }