Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use prettier withDefaultValue method to initialize HashMap

  • Loading branch information...
commit 45200f7fab2a0fa713cc6ad40a1e0a499f104d03 1 parent 52771ba
Evan Chan authored
Showing with 3 additions and 1 deletion.
  1. +3 −1 examples/WordCountTopology.scala
4 examples/WordCountTopology.scala
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.