storm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ptgo...@apache.org
Subject [24/50] [abbrv] git commit: Rankings: add pruneZeroCounts() method
Date Thu, 20 Mar 2014 21:22:47 GMT
Rankings: add pruneZeroCounts() method


Project: http://git-wip-us.apache.org/repos/asf/incubator-storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-storm/commit/6d56eae9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-storm/tree/6d56eae9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-storm/diff/6d56eae9

Branch: refs/heads/master
Commit: 6d56eae9f0707462bdb3502b19debaceb4e7f266
Parents: a51c824
Author: Michael G. Noll <mnoll@verisign.com>
Authored: Thu Aug 29 12:45:19 2013 +0200
Committer: Michael G. Noll <mnoll@verisign.com>
Committed: Thu Aug 29 12:45:19 2013 +0200

----------------------------------------------------------------------
 src/jvm/storm/starter/tools/Rankings.java      | 17 ++++++++++++-
 test/jvm/storm/starter/tools/RankingsTest.java | 28 ++++++++++++++++++++-
 2 files changed, 43 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-storm/blob/6d56eae9/src/jvm/storm/starter/tools/Rankings.java
----------------------------------------------------------------------
diff --git a/src/jvm/storm/starter/tools/Rankings.java b/src/jvm/storm/starter/tools/Rankings.java
index a3f421a..8dbb35f 100644
--- a/src/jvm/storm/starter/tools/Rankings.java
+++ b/src/jvm/storm/starter/tools/Rankings.java
@@ -89,7 +89,22 @@ public class Rankings implements Serializable {
     }
   }
 
+  /**
+   * Removes ranking entries that have a count of zero.
+   */
+  public void pruneZeroCounts() {
+    int i = 0;
+    while (i < rankedItems.size()) {
+      if (rankedItems.get(i).getCount() == 0) {
+        rankedItems.remove(i);
+      }
+      else {
+        i++;
+      }
+    }
+  }
+
   public String toString() {
     return rankedItems.toString();
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-storm/blob/6d56eae9/test/jvm/storm/starter/tools/RankingsTest.java
----------------------------------------------------------------------
diff --git a/test/jvm/storm/starter/tools/RankingsTest.java b/test/jvm/storm/starter/tools/RankingsTest.java
index 138a8b3..7d3b4da 100644
--- a/test/jvm/storm/starter/tools/RankingsTest.java
+++ b/test/jvm/storm/starter/tools/RankingsTest.java
@@ -15,6 +15,7 @@ public class RankingsTest {
 
   private static final int ANY_TOPN = 42;
   private static final Rankable ANY_RANKABLE = new RankableObjectWithFields("someObject",
ANY_TOPN);
+  private static final Rankable ZERO = new RankableObjectWithFields("ZERO_COUNT", 0);
   private static final Rankable A = new RankableObjectWithFields("A", 1);
   private static final Rankable B = new RankableObjectWithFields("B", 2);
   private static final Rankable C = new RankableObjectWithFields("C", 3);
@@ -194,6 +195,31 @@ public class RankingsTest {
     assertThat(rankings.size()).isEqualTo(1);
   }
 
+  @DataProvider
+  public Object[][] removeZeroRankingsData() {
+    return new Object[][]{ { Lists.newArrayList(A, ZERO), Lists.newArrayList(A) }, { Lists.newArrayList(A),
+        Lists.newArrayList(A) }, { Lists.newArrayList(ZERO, A), Lists.newArrayList(A) },
{ Lists.newArrayList(ZERO),
+        Lists.newArrayList() }, { Lists.newArrayList(ZERO, new RankableObjectWithFields("ZERO2",
0)),
+        Lists.newArrayList() }, { Lists.newArrayList(B, ZERO, new RankableObjectWithFields("ZERO2",
0), D,
+        new RankableObjectWithFields("ZERO3", 0), new RankableObjectWithFields("ZERO4", 0),
C), Lists.newArrayList(D, C,
+        B) }, { Lists.newArrayList(A, ZERO, B), Lists.newArrayList(B, A) } };
+  }
+
+  @Test(dataProvider = "removeZeroRankingsData")
+  public void shouldRemoveZeroCounts(List<Rankable> unsorted, List<Rankable>
expSorted) {
+    // given
+    Rankings rankings = new Rankings(unsorted.size());
+    for (Rankable r : unsorted) {
+      rankings.updateWith(r);
+    }
+
+    // when
+    rankings.pruneZeroCounts();
+
+    // then
+    assertThat(rankings.getRankings()).isEqualTo(expSorted);
+  }
+
   @Test
   public void updatingWithNewRankablesShouldBeThreadSafe() throws InterruptedException {
     // given
@@ -232,4 +258,4 @@ public class RankingsTest {
     }
     assertThat(exceptions).isEmpty();
   }
-}
+}
\ No newline at end of file


Mime
View raw message