Source:
public List<Point> getServerData() throws Exception { ObjectMapper objectMapper = new ObjectMapper(); HttpURLConnection urlConnection = (HttpURLConnection) new URL(findGaugeMetricsUrl).openConnection(); urlConnection.setRequestProperty("Hawkular-Tenant", tenant); urlConnection.connect(); int responseCode = urlConnection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_NO_CONTENT) { return Collections.emptyList(); } if (responseCode != HttpURLConnection.HTTP_OK) { String msg = "Could not get metrics list from server: %s, %d"; fail(String.format(Locale.ROOT, msg, findGaugeMetricsUrl, responseCode)); } List<String> metricNames; try (InputStream inputStream = urlConnection.getInputStream()) { TypeFactory typeFactory = objectMapper.getTypeFactory(); CollectionType valueType = typeFactory.constructCollectionType(List.class, MetricName.class); List<MetricName> value = objectMapper.readValue(inputStream, valueType); metricNames = value.stream().map(MetricName::getId).collect(toList()); } Stream<Point> points = Stream.empty(); for (String metricName : metricNames) { urlConnection = (HttpURLConnection) new URL(findGaugeDataUrl(metricName)).openConnection(); urlConnection.setRequestProperty("Hawkular-Tenant", tenant); urlConnection.connect(); responseCode = urlConnection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_NO_CONTENT) { continue; } if (responseCode != HttpURLConnection.HTTP_OK) { fail("Could not load metric data from server: " + responseCode); } try (InputStream inputStream = urlConnection.getInputStream()) { TypeFactory typeFactory = objectMapper.getTypeFactory(); CollectionType valueType = typeFactory.constructCollectionType(List.class, MetricData.class); List<MetricData> data = objectMapper.readValue(inputStream, valueType); Stream<Point> metricPoints = data.stream().map( metricData -> new Point(metricName, metricData.timestamp, metricData.value) ); points = Stream.concat(points, metricPoints); } } return points.collect(toList()); }

Target:
public List<Point> getServerData() throws Exception { ObjectMapper objectMapper = new ObjectMapper(); HttpURLConnection urlConnection = (HttpURLConnection) new URL(findGaugeMetricsUrl).openConnection(); urlConnection.setRequestProperty(HAWKULAR_TENANT_HEADER, tenant); urlConnection.connect(); int responseCode = urlConnection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_NO_CONTENT) { return Collections.emptyList(); } if (responseCode != HttpURLConnection.HTTP_OK) { String msg = "Could not get metrics list from server: %s, %d"; fail(String.format(Locale.ROOT, msg, findGaugeMetricsUrl, responseCode)); } List<String> metricNames; try (InputStream inputStream = urlConnection.getInputStream()) { TypeFactory typeFactory = objectMapper.getTypeFactory(); CollectionType valueType = typeFactory.constructCollectionType(List.class, MetricName.class); List<MetricName> value = objectMapper.readValue(inputStream, valueType); metricNames = value.stream().map(MetricName::getId).collect(toList()); } Stream<Point> points = Stream.empty(); for (String metricName : metricNames) { urlConnection = (HttpURLConnection) new URL(findGaugeDataUrl(metricName)).openConnection(); urlConnection.setRequestProperty(HAWKULAR_TENANT_HEADER, tenant); urlConnection.connect(); responseCode = urlConnection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_NO_CONTENT) { continue; } if (responseCode != HttpURLConnection.HTTP_OK) { fail("Could not load metric data from server: " + responseCode); } try (InputStream inputStream = urlConnection.getInputStream()) { TypeFactory typeFactory = objectMapper.getTypeFactory(); CollectionType valueType = typeFactory.constructCollectionType(List.class, MetricData.class); List<MetricData> data = objectMapper.readValue(inputStream, valueType); Stream<Point> metricPoints = data.stream().map( metricData -> new Point(metricName, metricData.timestamp, metricData.value) ); points = Stream.concat(points, metricPoints); } } return points.collect(toList()); }