Prefer valueOf() to create Number values

Update Long/Integer constructor calls with `valueOf` which can make use
of global caches.

Closes gh-4688
This commit is contained in:
mnhock
2015-12-06 15:01:07 +01:00
committed by Phillip Webb
parent dc3ead4c39
commit fcf6e5d6eb
6 changed files with 14 additions and 14 deletions

View File

@@ -92,7 +92,7 @@ public class Metric<T extends Number> {
*/
public Metric<Long> increment(int amount) {
return new Metric<Long>(this.getName(),
new Long(this.getValue().longValue() + amount));
Long.valueOf(this.getValue().longValue() + amount));
}
/**

View File

@@ -57,7 +57,7 @@ public class InMemoryMetricRepository implements MetricRepository, MultiMetricRe
metric.increment(amount).getValue(), timestamp);
}
else {
return new Metric<Long>(metricName, new Long(amount), timestamp);
return new Metric<Long>(metricName, Long.valueOf(amount), timestamp);
}
}
});

View File

@@ -64,12 +64,12 @@ public class MetricRegistryMetricReaderTests {
@Override
public Number getValue() {
return new Integer(5);
return Integer.valueOf(5);
}
});
Metric<Integer> metric = (Metric<Integer>) this.metricReader.findOne("test");
assertThat(metric.getValue(), equalTo(new Integer(5)));
assertThat(metric.getValue(), equalTo(Integer.valueOf(5)));
this.metricRegistry.remove("test");
assertThat(this.metricReader.findOne("test"), is(nullValue()));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -127,7 +127,7 @@ public class InMemoryRepositoryTests {
for (Future<Boolean> future : all) {
assertTrue(future.get(1, TimeUnit.SECONDS));
}
assertEquals(new Integer(0), repository.findOne("foo"));
assertEquals(Integer.valueOf(0), repository.findOne("foo"));
}
}