From efa75a3bee4c285e8d4f44f974131d653bfeb8b8 Mon Sep 17 00:00:00 2001 From: Ayman Abdel Ghany Date: Tue, 2 Feb 2016 06:08:43 +0200 Subject: [PATCH] Simplify the generics declaration by using the diamond operator ("<>") to reduce the verbosity of generics code. --- .../org/jmxtrans/agent/ExpressionLanguageEngineImpl.java | 2 +- .../org/jmxtrans/agent/JmxTransConfigurationXmlLoader.java | 6 +++--- .../org/jmxtrans/agent/JmxTransExporterConfiguration.java | 4 ++-- src/main/java/org/jmxtrans/agent/OutputWritersChain.java | 4 ++-- .../org/jmxtrans/agent/PerMinuteSummarizerOutputWriter.java | 4 ++-- src/main/java/org/jmxtrans/agent/util/StringUtils2.java | 4 ++-- .../java/org/jmxtrans/agent/util/collect/EvictingQueue.java | 2 +- .../jmxtrans/agent/JmxTransConfigurationXmlLoaderTest.java | 2 +- .../org/jmxtrans/agent/LibratoMetricsIntegrationTest.java | 2 +- src/test/java/org/jmxtrans/agent/QueryTest.java | 2 +- .../jmxtrans/agent/StatsDOutputWriterIntegrationTest.java | 2 +- .../org/jmxtrans/agent/util/collect/Iterables2Test.java | 6 +++--- 12 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/jmxtrans/agent/ExpressionLanguageEngineImpl.java b/src/main/java/org/jmxtrans/agent/ExpressionLanguageEngineImpl.java index fc8b1fcb..367d60df 100644 --- a/src/main/java/org/jmxtrans/agent/ExpressionLanguageEngineImpl.java +++ b/src/main/java/org/jmxtrans/agent/ExpressionLanguageEngineImpl.java @@ -72,7 +72,7 @@ public ExpressionLanguageEngineImpl() { * Function based evaluators for expressions like '#hostname#' or '#hostname_canonical#' */ @Nonnull - private Map functionsByName = new HashMap(); + private Map functionsByName = new HashMap<>(); /** * Replace all the '#' based keywords (e.g. #hostname#) by their value. diff --git a/src/main/java/org/jmxtrans/agent/JmxTransConfigurationXmlLoader.java b/src/main/java/org/jmxtrans/agent/JmxTransConfigurationXmlLoader.java index b7b62306..d2dfbb49 100644 --- a/src/main/java/org/jmxtrans/agent/JmxTransConfigurationXmlLoader.java +++ b/src/main/java/org/jmxtrans/agent/JmxTransConfigurationXmlLoader.java @@ -221,7 +221,7 @@ private void buildResultNameStrategy(Element rootElement, JmxTransExporterConfig try { resultNameStrategy = (ResultNameStrategy) Class.forName(outputWriterClass).newInstance(); - Map settings = new HashMap(); + Map settings = new HashMap<>(); NodeList settingsNodeList = resultNameStrategyElement.getElementsByTagName("*"); for (int j = 0; j < settingsNodeList.getLength(); j++) { Element settingElement = (Element) settingsNodeList.item(j); @@ -241,7 +241,7 @@ private void buildResultNameStrategy(Element rootElement, JmxTransExporterConfig private void buildOutputWriters(Element rootElement, JmxTransExporterConfiguration configuration, PropertyPlaceholderResolver placeholderResolver) { NodeList outputWriterNodeList = rootElement.getElementsByTagName("outputWriter"); - List outputWriters = new ArrayList(); + List outputWriters = new ArrayList<>(); for (int i = 0; i < outputWriterNodeList.getLength(); i++) { Element outputWriterElement = (Element) outputWriterNodeList.item(i); @@ -252,7 +252,7 @@ private void buildOutputWriters(Element rootElement, JmxTransExporterConfigurati OutputWriter outputWriter; try { outputWriter = (OutputWriter) Class.forName(outputWriterClass).newInstance(); - Map settings = new HashMap(); + Map settings = new HashMap<>(); NodeList settingsNodeList = outputWriterElement.getElementsByTagName("*"); for (int j = 0; j < settingsNodeList.getLength(); j++) { Element settingElement = (Element) settingsNodeList.item(j); diff --git a/src/main/java/org/jmxtrans/agent/JmxTransExporterConfiguration.java b/src/main/java/org/jmxtrans/agent/JmxTransExporterConfiguration.java index 4ba3e4dc..c102e97c 100644 --- a/src/main/java/org/jmxtrans/agent/JmxTransExporterConfiguration.java +++ b/src/main/java/org/jmxtrans/agent/JmxTransExporterConfiguration.java @@ -41,11 +41,11 @@ public class JmxTransExporterConfiguration { /** * visible for test */ - protected List queries = new ArrayList(); + protected List queries = new ArrayList<>(); /** * visible for test */ - protected List invocations = new ArrayList(); + protected List invocations = new ArrayList<>(); /** * visible for test */ diff --git a/src/main/java/org/jmxtrans/agent/OutputWritersChain.java b/src/main/java/org/jmxtrans/agent/OutputWritersChain.java index ab2057c3..737470be 100644 --- a/src/main/java/org/jmxtrans/agent/OutputWritersChain.java +++ b/src/main/java/org/jmxtrans/agent/OutputWritersChain.java @@ -35,11 +35,11 @@ public class OutputWritersChain extends AbstractOutputWriter implements OutputWr protected final List outputWriters; public OutputWritersChain() { - outputWriters = new ArrayList(); + outputWriters = new ArrayList<>(); } public OutputWritersChain(List outputWriters) { - this.outputWriters = new ArrayList(outputWriters.size()); + this.outputWriters = new ArrayList<>(outputWriters.size()); this.outputWriters.addAll(outputWriters); } diff --git a/src/main/java/org/jmxtrans/agent/PerMinuteSummarizerOutputWriter.java b/src/main/java/org/jmxtrans/agent/PerMinuteSummarizerOutputWriter.java index 14928358..5ff8c768 100644 --- a/src/main/java/org/jmxtrans/agent/PerMinuteSummarizerOutputWriter.java +++ b/src/main/java/org/jmxtrans/agent/PerMinuteSummarizerOutputWriter.java @@ -41,7 +41,7 @@ public class PerMinuteSummarizerOutputWriter extends AbstractOutputWriter implements OutputWriter { protected OutputWriter delegate; - protected Map> previousQueryResultsByMetricName = new HashMap>(); + protected Map> previousQueryResultsByMetricName = new HashMap<>(); public PerMinuteSummarizerOutputWriter() { } @@ -87,7 +87,7 @@ protected void storeQueryResult(@Nullable QueryResult currentResult) { Queue queue = previousQueryResultsByMetricName.get(currentResult.getName()); if (queue == null) { - queue = new EvictingQueue(3); + queue = new EvictingQueue<>(3); previousQueryResultsByMetricName.put(currentResult.getName(), queue); } queue.add(currentResult); diff --git a/src/main/java/org/jmxtrans/agent/util/StringUtils2.java b/src/main/java/org/jmxtrans/agent/util/StringUtils2.java index b61515e8..c2f60c0f 100644 --- a/src/main/java/org/jmxtrans/agent/util/StringUtils2.java +++ b/src/main/java/org/jmxtrans/agent/util/StringUtils2.java @@ -50,7 +50,7 @@ public static List delimitedStringToList(@Nullable String delimitedStrin } String[] splits = delimitedString.split("[,;\\n]"); - List result = new ArrayList(); + List result = new ArrayList<>(); for (String split : splits) { split = split.trim(); @@ -104,7 +104,7 @@ public static String reverseTokens(@Nullable String str, @Nonnull String delimit Preconditions2.checkNotNull(delimiter, "given delimiter can not be null"); StringTokenizer st = new StringTokenizer(str, delimiter); - List tokens = new ArrayList(); + List tokens = new ArrayList<>(); while (st.hasMoreTokens()) { tokens.add(st.nextToken()); diff --git a/src/main/java/org/jmxtrans/agent/util/collect/EvictingQueue.java b/src/main/java/org/jmxtrans/agent/util/collect/EvictingQueue.java index 437f2790..30cb558c 100644 --- a/src/main/java/org/jmxtrans/agent/util/collect/EvictingQueue.java +++ b/src/main/java/org/jmxtrans/agent/util/collect/EvictingQueue.java @@ -33,7 +33,7 @@ public EvictingQueue(int capacity) { } public static EvictingQueue create(int maxCapacity) { - return new EvictingQueue(maxCapacity); + return new EvictingQueue<>(maxCapacity); } @Nonnull diff --git a/src/test/java/org/jmxtrans/agent/JmxTransConfigurationXmlLoaderTest.java b/src/test/java/org/jmxtrans/agent/JmxTransConfigurationXmlLoaderTest.java index 9aa0056b..ee50722f 100644 --- a/src/test/java/org/jmxtrans/agent/JmxTransConfigurationXmlLoaderTest.java +++ b/src/test/java/org/jmxtrans/agent/JmxTransConfigurationXmlLoaderTest.java @@ -204,7 +204,7 @@ public Map loadProperties() { } Map indexQueriesByResultAlias(Iterable queries) { - Map result = new HashMap(); + Map result = new HashMap<>(); for (Query query : queries) { result.put(query.resultAlias, query); } diff --git a/src/test/java/org/jmxtrans/agent/LibratoMetricsIntegrationTest.java b/src/test/java/org/jmxtrans/agent/LibratoMetricsIntegrationTest.java index d7064e1b..d3318cc7 100644 --- a/src/test/java/org/jmxtrans/agent/LibratoMetricsIntegrationTest.java +++ b/src/test/java/org/jmxtrans/agent/LibratoMetricsIntegrationTest.java @@ -51,7 +51,7 @@ public void before() throws IOException { config.load(in); libratoWriter = new LibratoWriter(); - Map settings = new HashMap(); + Map settings = new HashMap<>(); settings.put(LibratoWriter.SETTING_USERNAME,config.getProperty("LIBRATO_USER")); settings.put(LibratoWriter.SETTING_TOKEN, config.getProperty("LIBRATO_TOKEN")); diff --git a/src/test/java/org/jmxtrans/agent/QueryTest.java b/src/test/java/org/jmxtrans/agent/QueryTest.java index f5146631..4a424506 100644 --- a/src/test/java/org/jmxtrans/agent/QueryTest.java +++ b/src/test/java/org/jmxtrans/agent/QueryTest.java @@ -213,7 +213,7 @@ public void attribute_list_attribute_does_not_return_not_specified_attribute() t public static class MockOutputWriter extends AbstractOutputWriter { protected final boolean failOnDuplicateResult; - protected final Map resultsByName = new HashMap(); + protected final Map resultsByName = new HashMap<>(); public MockOutputWriter() { this(true); diff --git a/src/test/java/org/jmxtrans/agent/StatsDOutputWriterIntegrationTest.java b/src/test/java/org/jmxtrans/agent/StatsDOutputWriterIntegrationTest.java index 3f4f5de5..4344db14 100644 --- a/src/test/java/org/jmxtrans/agent/StatsDOutputWriterIntegrationTest.java +++ b/src/test/java/org/jmxtrans/agent/StatsDOutputWriterIntegrationTest.java @@ -16,7 +16,7 @@ public class StatsDOutputWriterIntegrationTest { @Ignore public void test() throws IOException { StatsDOutputWriter writer = new StatsDOutputWriter(); - Map settings = new HashMap(); + Map settings = new HashMap<>(); settings.put(StatsDOutputWriter.SETTING_HOST, "localhost"); settings.put(StatsDOutputWriter.SETTING_PORT, "8125"); writer.postConstruct(settings); diff --git a/src/test/java/org/jmxtrans/agent/util/collect/Iterables2Test.java b/src/test/java/org/jmxtrans/agent/util/collect/Iterables2Test.java index 5f7c8754..f08d37f6 100644 --- a/src/test/java/org/jmxtrans/agent/util/collect/Iterables2Test.java +++ b/src/test/java/org/jmxtrans/agent/util/collect/Iterables2Test.java @@ -44,20 +44,20 @@ public void get_on_list_return_value() { @Test public void get_on_iterator_return_value() { - Set in = new TreeSet(Arrays.asList("val0", "val1", "val2", "val3")); + Set in = new TreeSet<>(Arrays.asList("val0", "val1", "val2", "val3")); String actual = Iterables2.get(in, 2); assertThat(actual, is("val2")); } @Test(expected = IndexOutOfBoundsException.class) public void get_negative_position_throws_an_exception() { - Set in = new HashSet(Arrays.asList("val0", "val1", "val2", "val3")); + Set in = new HashSet<>(Arrays.asList("val0", "val1", "val2", "val3")); Iterables2.get(in, -1); } @Test(expected = IndexOutOfBoundsException.class) public void get_out_of_range_position_throws_an_exception() { - Set in = new HashSet(Arrays.asList("val0", "val1", "val2", "val3")); + Set in = new HashSet<>(Arrays.asList("val0", "val1", "val2", "val3")); Iterables2.get(in, 10); } }