Skip to content

Commit

Permalink
Simplify the generics declaration by using the diamond operator ("<>"…
Browse files Browse the repository at this point in the history
…) to reduce the verbosity of generics code.
  • Loading branch information
Ayman-Abdelghany committed Feb 2, 2016
1 parent 230e17b commit efa75a3
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public ExpressionLanguageEngineImpl() {
* Function based evaluators for expressions like '#hostname#' or '#hostname_canonical#'
*/
@Nonnull
private Map<String, Function> functionsByName = new HashMap<String, Function>();
private Map<String, Function> functionsByName = new HashMap<>();

/**
* Replace all the '#' based keywords (e.g. <code>#hostname#</code>) by their value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private void buildResultNameStrategy(Element rootElement, JmxTransExporterConfig

try {
resultNameStrategy = (ResultNameStrategy) Class.forName(outputWriterClass).newInstance();
Map<String, String> settings = new HashMap<String, String>();
Map<String, String> settings = new HashMap<>();
NodeList settingsNodeList = resultNameStrategyElement.getElementsByTagName("*");
for (int j = 0; j < settingsNodeList.getLength(); j++) {
Element settingElement = (Element) settingsNodeList.item(j);
Expand All @@ -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<OutputWriter> outputWriters = new ArrayList<OutputWriter>();
List<OutputWriter> outputWriters = new ArrayList<>();

for (int i = 0; i < outputWriterNodeList.getLength(); i++) {
Element outputWriterElement = (Element) outputWriterNodeList.item(i);
Expand All @@ -252,7 +252,7 @@ private void buildOutputWriters(Element rootElement, JmxTransExporterConfigurati
OutputWriter outputWriter;
try {
outputWriter = (OutputWriter) Class.forName(outputWriterClass).newInstance();
Map<String, String> settings = new HashMap<String, String>();
Map<String, String> settings = new HashMap<>();
NodeList settingsNodeList = outputWriterElement.getElementsByTagName("*");
for (int j = 0; j < settingsNodeList.getLength(); j++) {
Element settingElement = (Element) settingsNodeList.item(j);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public class JmxTransExporterConfiguration {
/**
* visible for test
*/
protected List<Query> queries = new ArrayList<Query>();
protected List<Query> queries = new ArrayList<>();
/**
* visible for test
*/
protected List<Invocation> invocations = new ArrayList<Invocation>();
protected List<Invocation> invocations = new ArrayList<>();
/**
* visible for test
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jmxtrans/agent/OutputWritersChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public class OutputWritersChain extends AbstractOutputWriter implements OutputWr
protected final List<OutputWriter> outputWriters;

public OutputWritersChain() {
outputWriters = new ArrayList<OutputWriter>();
outputWriters = new ArrayList<>();
}

public OutputWritersChain(List<OutputWriter> outputWriters) {
this.outputWriters = new ArrayList<OutputWriter>(outputWriters.size());
this.outputWriters = new ArrayList<>(outputWriters.size());
this.outputWriters.addAll(outputWriters);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
public class PerMinuteSummarizerOutputWriter extends AbstractOutputWriter implements OutputWriter {

protected OutputWriter delegate;
protected Map<String, Queue<QueryResult>> previousQueryResultsByMetricName = new HashMap<String, Queue<QueryResult>>();
protected Map<String, Queue<QueryResult>> previousQueryResultsByMetricName = new HashMap<>();

public PerMinuteSummarizerOutputWriter() {
}
Expand Down Expand Up @@ -87,7 +87,7 @@ protected void storeQueryResult(@Nullable QueryResult currentResult) {

Queue<QueryResult> queue = previousQueryResultsByMetricName.get(currentResult.getName());
if (queue == null) {
queue = new EvictingQueue<QueryResult>(3);
queue = new EvictingQueue<>(3);
previousQueryResultsByMetricName.put(currentResult.getName(), queue);
}
queue.add(currentResult);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jmxtrans/agent/util/StringUtils2.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static List<String> delimitedStringToList(@Nullable String delimitedStrin
}
String[] splits = delimitedString.split("[,;\\n]");

List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();

for (String split : splits) {
split = split.trim();
Expand Down Expand Up @@ -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<String> tokens = new ArrayList<String>();
List<String> tokens = new ArrayList<>();

while (st.hasMoreTokens()) {
tokens.add(st.nextToken());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public EvictingQueue(int capacity) {
}

public static <E> EvictingQueue<E> create(int maxCapacity) {
return new EvictingQueue<E>(maxCapacity);
return new EvictingQueue<>(maxCapacity);
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public Map<String, String> loadProperties() {
}

Map<String, Query> indexQueriesByResultAlias(Iterable<Query> queries) {
Map<String, Query> result = new HashMap<String, Query>();
Map<String, Query> result = new HashMap<>();
for (Query query : queries) {
result.put(query.resultAlias, query);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void before() throws IOException {
config.load(in);

libratoWriter = new LibratoWriter();
Map<String, String> settings = new HashMap<String, String>();
Map<String, String> settings = new HashMap<>();
settings.put(LibratoWriter.SETTING_USERNAME,config.getProperty("LIBRATO_USER"));
settings.put(LibratoWriter.SETTING_TOKEN, config.getProperty("LIBRATO_TOKEN"));

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/jmxtrans/agent/QueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> resultsByName = new HashMap<String, Object>();
protected final Map<String, Object> resultsByName = new HashMap<>();

public MockOutputWriter() {
this(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class StatsDOutputWriterIntegrationTest {
@Ignore
public void test() throws IOException {
StatsDOutputWriter writer = new StatsDOutputWriter();
Map<String, String> settings = new HashMap<String, String>();
Map<String, String> settings = new HashMap<>();
settings.put(StatsDOutputWriter.SETTING_HOST, "localhost");
settings.put(StatsDOutputWriter.SETTING_PORT, "8125");
writer.postConstruct(settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ public void get_on_list_return_value() {

@Test
public void get_on_iterator_return_value() {
Set<String> in = new TreeSet<String>(Arrays.asList("val0", "val1", "val2", "val3"));
Set<String> 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<String> in = new HashSet<String>(Arrays.asList("val0", "val1", "val2", "val3"));
Set<String> 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<String> in = new HashSet<String>(Arrays.asList("val0", "val1", "val2", "val3"));
Set<String> in = new HashSet<>(Arrays.asList("val0", "val1", "val2", "val3"));
Iterables2.get(in, 10);
}
}

0 comments on commit efa75a3

Please sign in to comment.