Skip to content

Commit a6f22b2

Browse files
committed
comments, docs and names improvement
1 parent dbf4fc0 commit a6f22b2

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

language-adaptors/rxjava-scala/src/examples/scala/rx/lang/scala/examples/RxScalaDemo.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,8 +895,8 @@ class RxScalaDemo extends JUnitSuite {
895895
val keySelector = (s: String) => s.head
896896
val valueSelector = (s: String) => s.tail
897897
val mapFactory = () => mutable.Map('d' -> mutable.ListBuffer("oug"))
898-
val valueFactory = (k: Char) => mutable.ListBuffer[String]()
899-
val m = o.toMultimap(keySelector, valueSelector, mapFactory, valueFactory)
898+
val bufferFactory = (k: Char) => mutable.ListBuffer[String]()
899+
val m = o.toMultimap(keySelector, valueSelector, mapFactory, bufferFactory)
900900
println(m.toBlocking.single)
901901
}
902902

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/Observable.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3915,7 +3915,7 @@ trait Observable[+T]
39153915
/**
39163916
* Returns an Observable that emits a single `mutable.Map[K, mutable.Buffer[V]]`, returned by a specified `mapFactory` function, that
39173917
* contains values, extracted by a specified `valueSelector` function from items emitted by the source Observable and
3918-
* keyed by the `keySelector` function.
3918+
* keyed by the `keySelector` function. `mutable.Map[K, B]` is the same instance create by `mapFactory`.
39193919
*
39203920
* <img width="640" height="305" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/toMultiMap.png">
39213921
*
@@ -3932,17 +3932,17 @@ trait Observable[+T]
39323932
/**
39333933
* Returns an Observable that emits a single `mutable.Map[K, B]`, returned by a specified `mapFactory` function, that
39343934
* contains values extracted by a specified `valueSelector` function from items emitted by the source Observable, and
3935-
* keyed by the `keySelector` function.
3935+
* keyed by the `keySelector` function. `mutable.Map[K, B]` is the same instance create by `mapFactory`.
39363936
*
39373937
* <img width="640" height="305" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/toMultiMap.png">
39383938
*
39393939
* @param keySelector the function that extracts a key from the source items to be used as the key in the Map
39403940
* @param valueSelector the function that extracts a value from the source items to be used as the value in the Map
39413941
* @param mapFactory the function that returns a Map instance to be used
3942-
* @param collectionFactory the function that returns a `mutable.Buffer[V]` instance for a particular key to be used in the Map
3943-
* @return an Observable that emits a single item: a `mutable.Map[K, B]` that contains mapped items from the source Observable
3942+
* @param bufferFactory the function that returns a `mutable.Buffer[V]` instance for a particular key to be used in the Map
3943+
* @return an Observable that emits a single item: a `mutable.Map[K, B]` that contains mapped items from the source Observable.
39443944
*/
3945-
def toMultimap[K, V, B <: mutable.Buffer[V], M <: mutable.Map[K, B]](keySelector: T => K, valueSelector: T => V, mapFactory: () => M, collectionFactory: K => B): Observable[M] = {
3945+
def toMultimap[K, V, B <: mutable.Buffer[V], M <: mutable.Map[K, B]](keySelector: T => K, valueSelector: T => V, mapFactory: () => M, bufferFactory: K => B): Observable[M] = {
39463946
// It's complicated to convert `mutable.Map[K, mutable.Buffer[V]]` to `java.util.Map[K, java.util.Collection[V]]`,
39473947
// so RxScala implements `toMultimap` directly.
39483948
// Choosing `mutable.Buffer/Map` is because `append/update` is necessary to implement an efficient `toMultimap`.
@@ -3955,7 +3955,7 @@ trait Observable[+T]
39553955
val key = keySelector(t)
39563956
val values = map.get(key) match {
39573957
case Some(v) => v
3958-
case None => collectionFactory(key)
3958+
case None => bufferFactory(key)
39593959
}
39603960
values += valueSelector(t)
39613961
map += key -> values: Unit

language-adaptors/rxjava-scala/src/test/scala/rx/lang/scala/ObservableTest.scala

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,20 +250,24 @@ class ObservableTests extends JUnitSuite {
250250
val o = Observable.items("a", "b", "cc", "dd").toMultimap(_.length, s => s, () => m)
251251
val expected = Map(1 -> List("a", "b"), 2 -> List("cc", "dd"))
252252
val r = o.toBlocking.single
253-
assertTrue(m eq r) // check same instance
253+
// r should be the same instance created by the `mapFactory`
254+
assertTrue(m eq r)
254255
assertEquals(expected, r)
255256
}
256257

257258
@Test
258-
def testToMultimapWithCollectionFactory() {
259+
def testToMultimapWithBufferFactory() {
259260
val m = mutable.Map[Int, mutable.Buffer[String]]()
260261
val ls = List(mutable.Buffer[String](), mutable.Buffer[String]())
261262
val o = Observable.items("a", "b", "cc", "dd").toMultimap(_.length, s => s, () => m, (i: Int) => ls(i - 1))
262263
val expected = Map(1 -> List("a", "b"), 2 -> List("cc", "dd"))
263264
val r = o.toBlocking.single
264-
assertTrue(m eq r) // check same instance
265-
assertTrue(ls(0) eq r(1)) // check same instance
266-
assertTrue(ls(1) eq r(2)) // check same instance
265+
// r should be the same instance created by the `mapFactory`
266+
assertTrue(m eq r)
267+
// r(1) should be the same instance created by the first calling `bufferFactory`
268+
assertTrue(ls(0) eq r(1))
269+
// r(2) should be the same instance created by the second calling `bufferFactory`
270+
assertTrue(ls(1) eq r(2))
267271
assertEquals(expected, r)
268272
}
269273

0 commit comments

Comments
 (0)