Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

Commit 4bd2de1

Browse files
authored
Merge pull request #23 from sebright/cleanup
Cleanup
2 parents 1a7feea + 0d93f65 commit 4bd2de1

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

core/java/com/google/census/MetricMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public MetricMap build() {
107107
return new MetricMap(metrics);
108108
}
109109

110-
private ArrayList<Metric> metrics = new ArrayList<Metric>();
110+
private final ArrayList<Metric> metrics = new ArrayList<Metric>();
111111

112112
private Builder() {
113113
}

core/java/com/google/census/Provider.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package com.google.census;
1515

16+
import java.lang.reflect.InvocationTargetException;
17+
1618
/**
1719
* Census-specific service provider mechanism.
1820
*
@@ -40,14 +42,20 @@ class Provider<T> {
4042
T newInstance() {
4143
try {
4244
if (provider != null) {
43-
return (T) provider.newInstance();
45+
return (T) provider.getConstructor().newInstance();
4446
}
4547
} catch (InstantiationException e) {
4648
// TODO(dpo): decide what to do here - log, crash, or both.
4749
System.err.println(e);
4850
} catch (IllegalAccessException e) {
4951
// TODO(dpo): decide what to do here - log, crash, or both.
5052
System.err.println(e);
53+
} catch (NoSuchMethodException e) {
54+
// TODO(dpo): decide what to do here - log, crash, or both.
55+
System.err.println(e);
56+
} catch (InvocationTargetException e) {
57+
// TODO(dpo): decide what to do here - log, crash, or both.
58+
System.err.println(e);
5159
}
5260
return null;
5361
}

core/javatests/com/google/census/TagTest.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,9 @@ public void testGetValue() {
3838
assertThat(new Tag("key", "val").getValue()).isEqualTo("val");
3939
}
4040

41-
@Test
41+
@Test(expected = UnsupportedOperationException.class)
4242
public void testSetValue() {
43-
boolean fail = true;
44-
try {
45-
new Tag("key", "val").setValue("val1");
46-
fail = false;
47-
} catch (UnsupportedOperationException expected) {
48-
}
49-
assertThat(fail).isTrue();
43+
new Tag("key", "val").setValue("val1");
5044
}
5145

5246
@Test

core_native/java/com/google/census/CensusContextFactoryImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
final class CensusContextFactoryImpl extends CensusContextFactory {
2222
static final CensusContextImpl DEFAULT = new CensusContextImpl(new HashMap<String, String>(0));
2323

24+
public CensusContextFactoryImpl() {}
25+
2426
/**
2527
* Deserializes a {@link CensusContextImpl} from a serialized {@code CensusContextProto}.
2628
*

examples/java/com/google/census/CensusRunner.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,13 @@
1111
* limitations under the License.
1212
*/
1313

14-
package com.google.census.examples;
15-
16-
import com.google.census.Census;
17-
import com.google.census.CensusContext;
18-
import com.google.census.CensusGrpcContext;
19-
import com.google.census.MetricMap;
20-
import com.google.census.MetricName;
21-
import com.google.census.TagKey;
22-
import com.google.census.TagValue;
14+
package com.google.census;
2315

2416
import io.grpc.Context;
2517

18+
/**
19+
* Simple program that uses Census contexts.
20+
*/
2621
public class CensusRunner {
2722
private static final TagKey K1 = new TagKey("k1");
2823
private static final TagKey K2 = new TagKey("k2");
@@ -37,7 +32,7 @@ public class CensusRunner {
3732
private static final MetricName M1 = new MetricName("m1");
3833
private static final MetricName M2 = new MetricName("m2");
3934

40-
public static void main(String args[]) {
35+
public static void main(String[] args) {
4136
System.out.println("Hello Census World");
4237
System.out.println("Default Tags: " + DEFAULT);
4338
System.out.println("Current Tags: " + getCurrentCensusContext());

0 commit comments

Comments
 (0)