Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Convert the Index class to a case class

As suggested by Viktor
  • Loading branch information...
commit 53043e327ff3b5a13b22ec41b93c2f6b350ea6ad 1 parent 049250e
@havocp havocp authored
View
22 common/src/main/scala/com/typesafe/webwords/common/Index.scala
@@ -4,24 +4,12 @@ package com.typesafe.webwords.common
* This is the information we scrape about a URL.
* Links found on the site, and word counts of words on the site.
*/
-final class Index(val links: Seq[(String, String)],
- val wordCounts: Seq[(String, Int)]) {
+case class Index(links: Seq[(String, String)],
+ wordCounts: Seq[(String, Int)]) {
+
+ // the default toString for a case class would recursively show
+ // the entire lists, which is not convenient. so override.
override def toString = {
"Index(" + links.size + " links," + wordCounts.size + " counts)"
}
-
- override def equals(other: Any): Boolean = {
- other match {
- case that: Index => {
- // no canEqual since we're final
- links == that.links &&
- wordCounts == that.wordCounts
- }
- case _ => false
- }
- }
-
- override def hashCode: Int = {
- 41 * (41 + links.hashCode) + wordCounts.hashCode
- }
}
View
2  common/src/main/scala/com/typesafe/webwords/common/IndexStorageActor.scala
@@ -259,7 +259,7 @@ object IndexStorageActor {
}
}
- new Index(links, wordCounts)
+ Index(links, wordCounts)
}
private[common] case class MongoURIParts(user: Option[String], password: Option[String],
View
8 common/src/test/scala/com/typesafe/webwords/common/IndexSpec.scala
@@ -5,7 +5,7 @@ import org.scalatest._
import akka.actor._
class IndexSpec extends FlatSpec with ShouldMatchers {
- private val sampleIndex = new Index(
+ private val sampleIndex = Index(
links = Seq(
"dogs" -> "http://dogs.com/",
"cats" -> "http://cats.com/"),
@@ -14,8 +14,8 @@ class IndexSpec extends FlatSpec with ShouldMatchers {
"world" -> 5,
"quick" -> 4,
"brown" -> 3))
- private val copyOfSampleIndex = new Index(links = sampleIndex.links, wordCounts = sampleIndex.wordCounts)
- private val sampleIndexDifferentOrder = new Index(
+ private val copyOfSampleIndex = Index(links = sampleIndex.links, wordCounts = sampleIndex.wordCounts)
+ private val sampleIndexDifferentOrder = Index(
links = Seq(
"cats" -> "http://cats.com/",
"dogs" -> "http://dogs.com/"),
@@ -24,7 +24,7 @@ class IndexSpec extends FlatSpec with ShouldMatchers {
"hello" -> 10,
"brown" -> 3,
"quick" -> 4))
- private val emptyIndex = new Index(Nil, Nil)
+ private val emptyIndex = Index(Nil, Nil)
behavior of "Index"
View
6 common/src/test/scala/com/typesafe/webwords/common/IndexStorageActorSpec.scala
@@ -6,7 +6,7 @@ import akka.actor._
import java.net.URL
class IndexStorageActorSpec extends FlatSpec with ShouldMatchers {
- private val sampleIndex = new Index(
+ private val sampleIndex = Index(
links = Seq(
"dogs" -> "http://dogs.com/",
"cats" -> "http://cats.com/"),
@@ -15,7 +15,7 @@ class IndexStorageActorSpec extends FlatSpec with ShouldMatchers {
"world" -> 5,
"quick" -> 4,
"brown" -> 3))
- private val anotherIndex = new Index(
+ private val anotherIndex = Index(
links = Seq(
"pigs" -> "http://pigs.com/",
"cows" -> "http://cows.com/"),
@@ -24,7 +24,7 @@ class IndexStorageActorSpec extends FlatSpec with ShouldMatchers {
"world" -> 1,
"quick" -> 4,
"brown" -> 2))
- private val emptyIndex = new Index(Nil, Nil)
+ private val emptyIndex = Index(Nil, Nil)
private val exampleUrl = new URL("http://example.com/")
private val exampleUrl2 = new URL("http://example2.com/")
View
2  indexer/src/main/scala/com/typesafe/webwords/indexer/IndexerActor.scala
@@ -76,7 +76,7 @@ class IndexerActor
case request: IndexerRequest => request match {
case IndexHtml(url, docString) =>
val doc = Jsoup.parse(docString, url.toExternalForm)
- val index = new Index(links(doc), wordCounts(doc))
+ val index = Index(links(doc), wordCounts(doc))
self.tryReply(IndexedHtml(index))
}
}
View
2  indexer/src/main/scala/com/typesafe/webwords/indexer/SpiderActor.scala
@@ -134,7 +134,7 @@ object SpiderActor {
// ideally we might combine and count length at the same time, but we'll live
val counts = combineCounts(a.wordCounts, b.wordCounts).take(math.max(a.wordCounts.length, b.wordCounts.length))
- new Index(links, counts)
+ Index(links, counts)
}
private def combineIndexes(indexes: TraversableOnce[Index]): Index = {
Please sign in to comment.
Something went wrong with that request. Please try again.