Permalink
Browse files

Use prettier withDefaultValue method to initialize HashMap

  • Loading branch information...
1 parent 52771ba commit 45200f7fab2a0fa713cc6ad40a1e0a499f104d03 Evan Chan committed Oct 10, 2011
Showing with 3 additions and 1 deletion.
  1. +3 −1 examples/WordCountTopology.scala
@@ -12,7 +12,9 @@ class SplitSentence extends StormBolt(outputFields = List("word")) {
}
class WordCount extends StormBolt(outputFields = List("word", "count")) {
- val counts = new HashMap[String, Int]() { override def default(key:String) = 0 }
+ // NOTE: withDefaultValue is new to 2.9.1. If using <= 2.9.0.x, you need to
+ // replace it with { override def default(key:String) = 0 }
+ val counts = new HashMap[String, Int]().withDefaultValue(0)
process { t =>
val word = t.getString(0)
counts(word) += 1

0 comments on commit 45200f7

Please sign in to comment.