Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ValueWithHostname |
|
| 1.0;1 |
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 | /** | |
22 | * Pair of value with host it came from. | |
23 | * | |
24 | * @param <T> types of value (either long or double) | |
25 | */ | |
26 | public class ValueWithHostname<T extends Number> { | |
27 | /** long value we're holding */ | |
28 | private T value; | |
29 | /** host associated with value */ | |
30 | private String hostname; | |
31 | ||
32 | /** | |
33 | * Create with initial value | |
34 | * | |
35 | * @param value initial value to use | |
36 | */ | |
37 | 0 | public ValueWithHostname(T value) { |
38 | 0 | this.value = value; |
39 | 0 | this.hostname = null; |
40 | 0 | } |
41 | ||
42 | /** | |
43 | * @return value | |
44 | */ | |
45 | public T getValue() { | |
46 | 0 | return value; |
47 | } | |
48 | ||
49 | /** | |
50 | * @return String hostname | |
51 | */ | |
52 | public String getHostname() { | |
53 | 0 | return hostname; |
54 | } | |
55 | ||
56 | /** | |
57 | * Check if there is any hostname. Used as a flag that we have any data. | |
58 | * | |
59 | * @return true if hostname is set | |
60 | */ | |
61 | public boolean hasHostname() { | |
62 | 0 | return hostname != null; |
63 | } | |
64 | ||
65 | /** | |
66 | * Set value and partition together. | |
67 | * @param value value to use. | |
68 | * @param hostname String host it came from. | |
69 | */ | |
70 | public void set(T value, String hostname) { | |
71 | 0 | this.value = value; |
72 | 0 | this.hostname = hostname; |
73 | 0 | } |
74 | } |