commit cb966bc48ce30d4cef0195b713168e2020e412bf Author: Karsten Loesing karsten.loesing@gmx.net Date: Mon Aug 20 15:10:15 2018 +0200
Replace anonymous types with lambdas. --- .../metrics/stats/hidserv/Aggregator.java | 7 +--- .../torproject/metrics/stats/hidserv/Simulate.java | 14 ++------ .../org/torproject/metrics/web/NewsServlet.java | 8 ++--- .../torproject/metrics/web/RObjectGenerator.java | 39 ++++++++++------------ 4 files changed, 23 insertions(+), 45 deletions(-)
diff --git a/src/main/java/org/torproject/metrics/stats/hidserv/Aggregator.java b/src/main/java/org/torproject/metrics/stats/hidserv/Aggregator.java index 004bcf8..2420485 100644 --- a/src/main/java/org/torproject/metrics/stats/hidserv/Aggregator.java +++ b/src/main/java/org/torproject/metrics/stats/hidserv/Aggregator.java @@ -125,12 +125,7 @@ public class Aggregator { * element. (The second array element contains the computed * network fraction as weight.) */ Collections.sort(weightedValues, - new Comparator<double[]>() { - public int compare(double[] first, double[] second) { - return Double.compare(first[0], second[0]); - } - } - ); + Comparator.comparingDouble(doubles -> doubles[0]));
/* For the weighted mean, sum up all previously extrapolated * values weighted with their network fractions (which happens to diff --git a/src/main/java/org/torproject/metrics/stats/hidserv/Simulate.java b/src/main/java/org/torproject/metrics/stats/hidserv/Simulate.java index a7bc1c3..2c525d7 100644 --- a/src/main/java/org/torproject/metrics/stats/hidserv/Simulate.java +++ b/src/main/java/org/torproject/metrics/stats/hidserv/Simulate.java @@ -172,12 +172,7 @@ public class Simulate { } while (totalReportingProbability < fraction - 0.001 || totalReportingProbability > fraction + 0.001); Collections.sort(singleRelayExtrapolations, - new Comparator<double[]>() { - public int compare(double[] o1, double[] o2) { - return o1[0] < o2[0] ? -1 : o1[0] > o2[0] ? 1 : 0; - } - } - ); + Comparator.comparingDouble(o -> o[0])); double totalProbability = 0.0; double totalValues = 0.0; double totalInterquartileProbability = 0.0; @@ -332,12 +327,7 @@ public class Simulate { } while (totalReportingProbability < fraction - 0.001 || totalReportingProbability > fraction + 0.001); Collections.sort(singleRelayExtrapolations, - new Comparator<double[]>() { - public int compare(double[] first, double[] second) { - return Double.compare(first[0], second[0]); - } - } - ); + Comparator.comparingDouble(doubles -> doubles[0])); double totalProbability = 0.0; double totalValues = 0.0; double totalInterquartileProbability = 0.0; diff --git a/src/main/java/org/torproject/metrics/web/NewsServlet.java b/src/main/java/org/torproject/metrics/web/NewsServlet.java index a5775dd..fc4d39f 100644 --- a/src/main/java/org/torproject/metrics/web/NewsServlet.java +++ b/src/main/java/org/torproject/metrics/web/NewsServlet.java @@ -7,7 +7,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; -import java.util.Comparator; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; @@ -37,11 +36,8 @@ public class NewsServlet extends AnyServlet { sortedNews.add(news); } } - Collections.sort(sortedNews, new Comparator<News>() { - public int compare(News o1, News o2) { - return o1.getStart().compareTo(o2.getStart()) * -1; - } - }); + Collections.sort(sortedNews, + (o1, o2) -> o1.getStart().compareTo(o2.getStart()) * -1); this.sortedNews = sortedNews; SortedMap<String, String> countries = new TreeMap<>(); for (String[] country : Countries.getInstance().getCountryList()) { diff --git a/src/main/java/org/torproject/metrics/web/RObjectGenerator.java b/src/main/java/org/torproject/metrics/web/RObjectGenerator.java index 49e24ec..9943f17 100644 --- a/src/main/java/org/torproject/metrics/web/RObjectGenerator.java +++ b/src/main/java/org/torproject/metrics/web/RObjectGenerator.java @@ -76,30 +76,27 @@ public class RObjectGenerator implements ServletContextListener { servletContext.setAttribute("RObjectGenerator", this);
/* Periodically generate R objects with default parameters. */ - new Thread() { - @Override - public void run() { - long lastUpdated = 0L; - long sleep; - while (true) { - while ((sleep = maxCacheAge * 1000L / 2L + lastUpdated - - System.currentTimeMillis()) > 0L) { - try { - Thread.sleep(sleep); - } catch (InterruptedException e) { - /* Nothing we can handle. */ - } + new Thread(() -> { + long lastUpdated = 0L; + long sleep; + while (true) { + while ((sleep = maxCacheAge * 1000L / 2L + lastUpdated + - System.currentTimeMillis()) > 0L) { + try { + Thread.sleep(sleep); + } catch (InterruptedException e) { + /* Nothing we can handle. */ } - for (String tableId : availableTables.keySet()) { - generateTable(tableId, new HashMap(), false); - } - for (String graphId : availableGraphs.keySet()) { - generateGraph(graphId, "png", new HashMap(), false); - } - lastUpdated = System.currentTimeMillis(); } + for (String tableId : availableTables.keySet()) { + generateTable(tableId, new HashMap(), false); + } + for (String graphId : availableGraphs.keySet()) { + generateGraph(graphId, "png", new HashMap(), false); + } + lastUpdated = System.currentTimeMillis(); } - }.start(); + }).start(); }
@Override
tor-commits@lists.torproject.org