Skip to content

Commit 5c13c92

Browse files
committed
Add and improve doc
Throws doc requires text Provide doc for aggregate Scaladoc tool gets a `-required` flag to check that there is doc text for public members. Internal-only for now.
1 parent 9ed412a commit 5c13c92

15 files changed

+239
-76
lines changed

library/src/scala/collection/IterableOnce.scala

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
401401
*
402402
* The matching prefix starts with the first element of this $coll,
403403
* and the element following the prefix is the first element that
404-
* does not satisfy the predicate. The matching prefix may empty,
404+
* does not satisfy the predicate. The matching prefix may be empty,
405405
* so that this method returns the entire $coll.
406406
*
407407
* Example:
@@ -1188,7 +1188,20 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
11881188
None
11891189
}
11901190

1191-
@deprecated("`aggregate` is not relevant for sequential collections. Use `foldLeft(z)(seqop)` instead.", "2.13.0")
1191+
/** Aggregates the results of applying an operator to subsequent elements.
1192+
*
1193+
* Since this method degenerates to `foldLeft` for sequential (non-parallel) collections,
1194+
* where the combining operation is ignored, it is advisable to prefer `foldLeft` for that case.
1195+
*
1196+
* For [[https://github.com/scala/scala-parallel-collections parallel collections]],
1197+
* use the `aggregate` method specified by `scala.collection.parallel.ParIterableLike`.
1198+
*
1199+
* @param z the start value, a neutral element for `seqop`.
1200+
* @param seqop the binary operator used to accumulate the result.
1201+
* @param combop an associative operator for combining sequential results, unused for sequential collections.
1202+
* @tparam B the result type, produced by `seqop`, `combop`, and by this function as a final result.
1203+
*/
1204+
@deprecated("For sequential collections, prefer `foldLeft(z)(seqop)`. For parallel collections, use `ParIterableLike#aggregate`.", "2.13.0")
11921205
def aggregate[B](z: => B)(seqop: (B, A) => B, combop: (B, B) => B): B = foldLeft(z)(seqop)
11931206

11941207
/** Tests whether every element of this collection's iterator relates to the

library/src/scala/collection/Map.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,14 @@ trait MapOps[K, +V, +CC[_, _] <: IterableOps[_, AnyConstr, _], +C]
276276
def mapValues[W](f: V => W): MapView[K, W] = new MapView.MapValues(this, f)
277277

278278
/** Defines the default value computation for the map,
279-
* returned when a key is not found
280-
* The method implemented here throws an exception,
281-
* but it might be overridden in subclasses.
282-
*
283-
* @param key the given key value for which a binding is missing.
284-
* @throws NoSuchElementException
285-
*/
279+
* returned when a key is not found.
280+
*
281+
* The method implemented here throws an exception,
282+
* but it may be overridden by subclasses.
283+
*
284+
* @param key the given key value for which a binding is missing.
285+
* @throws NoSuchElementException if no default value is defined
286+
*/
286287
@throws[NoSuchElementException]
287288
def default(key: K): V =
288289
throw new NoSuchElementException("key not found: " + key)

library/src/scala/collection/Seq.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any
928928
*
929929
* Patching at negative indices is the same as patching starting at 0.
930930
* Patching at indices at or larger than the length of the original $coll appends the patch to the end.
931-
* If more values are replaced than actually exist, the excess is ignored.
931+
* If the `replaced` count would exceed the available elements, the difference in excess is ignored.
932932
*
933933
* @param from the index of the first replaced element
934934
* @param other the replacement sequence

library/src/scala/collection/StringOps.scala

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -973,36 +973,38 @@ final class StringOps(private val s: String) extends AnyVal {
973973
}
974974

975975
/** Uses the underlying string as a pattern (in a fashion similar to
976-
* printf in C), and uses the supplied arguments to fill in the
977-
* holes.
978-
*
979-
* The interpretation of the formatting patterns is described in
980-
* [[java.util.Formatter]], with the addition that
981-
* classes deriving from `ScalaNumber` (such as [[scala.BigInt]] and
982-
* [[scala.BigDecimal]]) are unwrapped to pass a type which `Formatter`
983-
* understands.
984-
*
985-
* @param args the arguments used to instantiating the pattern.
986-
* @throws java.lang.IllegalArgumentException
987-
*/
988-
def format(args : Any*): String =
989-
java.lang.String.format(s, args map unwrapArg: _*)
976+
* printf in C), and uses the supplied arguments to fill in the
977+
* holes.
978+
*
979+
* The interpretation of the formatting patterns is described in
980+
* [[java.util.Formatter]], with the addition that
981+
* classes deriving from `ScalaNumber` (such as [[scala.BigInt]] and
982+
* [[scala.BigDecimal]]) are unwrapped to pass a type which `Formatter` understands.
983+
*
984+
* See [[scala.StringContext#f]] for a formatting interpolator that
985+
* checks the format string at compilation.
986+
*
987+
* @param args the arguments used to instantiating the pattern.
988+
* @throws java.util.IllegalFormatException if the format contains syntax or conversion errors
989+
*/
990+
def format(args: Any*): String =
991+
java.lang.String.format(s, args.map(unwrapArg): _*)
990992

991993
/** Like `format(args*)` but takes an initial `Locale` parameter
992-
* which influences formatting as in `java.lang.String`'s format.
993-
*
994-
* The interpretation of the formatting patterns is described in
995-
* [[java.util.Formatter]], with the addition that
996-
* classes deriving from `ScalaNumber` (such as `scala.BigInt` and
997-
* `scala.BigDecimal`) are unwrapped to pass a type which `Formatter`
998-
* understands.
999-
*
1000-
* @param l an instance of `java.util.Locale`
1001-
* @param args the arguments used to instantiating the pattern.
1002-
* @throws java.lang.IllegalArgumentException
1003-
*/
994+
* which influences formatting as in `java.lang.String`'s format.
995+
*
996+
* The interpretation of the formatting patterns is described in
997+
* [[java.util.Formatter]], with the addition that
998+
* classes deriving from `ScalaNumber` (such as `scala.BigInt` and
999+
* `scala.BigDecimal`) are unwrapped to pass a type which `Formatter`
1000+
* understands.
1001+
*
1002+
* @param l an instance of `java.util.Locale`
1003+
* @param args the arguments used to instantiating the pattern.
1004+
* @throws java.util.IllegalFormatException if the format contains syntax or conversion errors
1005+
*/
10041006
def formatLocal(l: java.util.Locale, args: Any*): String =
1005-
java.lang.String.format(l, s, args map unwrapArg: _*)
1007+
java.lang.String.format(l, s, args.map(unwrapArg): _*)
10061008

10071009
def compare(that: String): Int = s.compareTo(that)
10081010

library/src/scala/collection/immutable/Queue.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ sealed class Queue[+A] protected(protected val in: List[A], protected val out: L
163163
def enqueueAll[B >: A](iter: scala.collection.Iterable[B]): Queue[B] = appendedAll(iter)
164164

165165
/** Returns a tuple with the first element in the queue,
166-
* and a new queue with this element removed.
167-
*
168-
* @throws NoSuchElementException
169-
* @return the first element of the queue.
170-
*/
166+
* and a new queue with this element removed.
167+
*
168+
* @return the first element of the queue.
169+
* @throws NoSuchElementException if the queue is empty
170+
*/
171171
def dequeue: (A, Queue[A]) = out match {
172172
case Nil if !in.isEmpty => val rev = in.reverse ; (rev.head, new Queue(Nil, rev.tail))
173173
case x :: xs => (x, new Queue(in, xs))
@@ -182,11 +182,11 @@ sealed class Queue[+A] protected(protected val in: List[A], protected val out: L
182182
def dequeueOption: Option[(A, Queue[A])] = if(isEmpty) None else Some(dequeue)
183183

184184
/** Returns the first element in the queue, or throws an error if there
185-
* is no element contained in the queue.
186-
*
187-
* @throws NoSuchElementException
188-
* @return the first element.
189-
*/
185+
* is no element contained in the queue.
186+
*
187+
* @throws NoSuchElementException if the queue is empty
188+
* @return the first element.
189+
*/
190190
def front: A = head
191191

192192
/** Returns a string representation of this queue.

library/src/scala/collection/mutable/AnyRefMap.scala

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,30 @@ class AnyRefMap[K <: AnyRef, V] private[collection] (defaultEntry: K => V, initi
475475
this
476476
}
477477

478-
// The implicit dummy parameter is necessary to distinguish these methods from the base methods they overload (not override)
478+
// The implicit dummy parameter is necessary to distinguish these methods from the base methods they overload (not override).
479+
// Previously, in Scala 2, f took `K with AnyRef` scala/bug#11035
480+
/**
481+
* An overload of `map` which produces an `AnyRefMap`.
482+
*
483+
* @param f the mapping function must produce a key-value pair where the key is an `AnyRef`
484+
* @param dummy an implicit placeholder for purposes of distinguishing the (erased) signature of this method
485+
*/
479486
def map[K2 <: AnyRef, V2](f: ((K, V)) => (K2, V2))(implicit dummy: DummyImplicit): AnyRefMap[K2, V2] =
480487
AnyRefMap.from(new View.Map(this, f))
488+
/**
489+
* An overload of `flatMap` which produces an `AnyRefMap`.
490+
*
491+
* @param f the mapping function must produce key-value pairs where the key is an `AnyRef`
492+
* @param dummy an implicit placeholder for purposes of distinguishing the (erased) signature of this method
493+
*/
481494
def flatMap[K2 <: AnyRef, V2](f: ((K, V)) => IterableOnce[(K2, V2)])(implicit dummy: DummyImplicit): AnyRefMap[K2, V2] =
482495
AnyRefMap.from(new View.FlatMap(this, f))
496+
/**
497+
* An overload of `collect` which produces an `AnyRefMap`.
498+
*
499+
* @param pf the mapping function must produce a key-value pair where the key is an `AnyRef`
500+
* @param dummy an implicit placeholder for purposes of distinguishing the (erased) signature of this method
501+
*/
483502
def collect[K2 <: AnyRef, V2](pf: PartialFunction[(K, V), (K2, V2)])(implicit dummy: DummyImplicit): AnyRefMap[K2, V2] =
484503
strictOptimizedCollect(AnyRefMap.newBuilder[K2, V2], pf)
485504

library/src/scala/collection/mutable/ArrayBuffer.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ class ArrayBuffer[A] private (initialElements: Array[AnyRef], initialSize: Int)
7777
array = ArrayBuffer.ensureSize(array, size0, size0.toLong + n)
7878
}
7979

80+
/** Uses the given size to resize internal storage, if necessary.
81+
*
82+
* @param size Expected maximum number of elements.
83+
*/
8084
def sizeHint(size: Int): Unit =
8185
if(size > length && size >= 1) ensureSize(size)
8286

library/src/scala/collection/mutable/ArrayBuilder.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ sealed abstract class ArrayBuilder[T]
2727
protected[this] def elems: Array[T]
2828
protected var size: Int = 0
2929

30+
/** Current number of elements. */
3031
def length: Int = size
3132

33+
/** Current number of elements. */
3234
override def knownSize: Int = size
3335

3436
protected[this] final def ensureSize(size: Int): Unit = {

library/src/scala/collection/mutable/Buffer.scala

Lines changed: 89 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,28 @@ trait Buffer[A]
3737
def prepend(elem: A): this.type
3838

3939
/** Appends the given elements to this buffer.
40-
*
41-
* @param elem the element to append.
42-
*/
40+
*
41+
* @param elem the element to append.
42+
* @return this $coll
43+
*/
4344
@`inline` final def append(elem: A): this.type = addOne(elem)
4445

4546
@deprecated("Use appendAll instead", "2.13.0")
4647
@`inline` final def append(elems: A*): this.type = addAll(elems)
4748

4849
/** Appends the elements contained in a iterable object to this buffer.
49-
* @param xs the iterable object containing the elements to append.
50-
*/
51-
@`inline` final def appendAll(xs: IterableOnce[A]): this.type = addAll(xs)
52-
50+
* @param elems the iterable object containing the elements to append.
51+
* @return this $coll
52+
*/
53+
@`inline` final def appendAll(@deprecatedName("xs") elems: IterableOnce[A]): this.type = addAll(elems)
5354

5455
/** Alias for `prepend` */
5556
@`inline` final def +=: (elem: A): this.type = prepend(elem)
5657

58+
/** Prepends the elements contained in a iterable object to this buffer.
59+
* @param elems the iterable object containing the elements to append.
60+
* @return this $coll
61+
*/
5762
def prependAll(elems: IterableOnce[A]): this.type = { insertAll(0, elems); this }
5863

5964
@deprecated("Use prependAll instead", "2.13.0")
@@ -132,6 +137,17 @@ trait Buffer[A]
132137
@deprecated("use dropRightInPlace instead", since = "2.13.4")
133138
def trimEnd(n: Int): Unit = dropRightInPlace(n)
134139

140+
/** Replaces a slice of elements in this $coll by another sequence of elements.
141+
*
142+
* Patching at negative indices is the same as patching starting at 0.
143+
* Patching at indices at or larger than the length of the original $coll appends the patch to the end.
144+
* If the `replaced` count would exceed the available elements, the difference in excess is ignored.
145+
*
146+
* @param from the index of the first replaced element
147+
* @param patch the replacement sequence
148+
* @param replaced the number of elements to drop in the original $coll
149+
* @return this $coll
150+
*/
135151
def patchInPlace(from: Int, patch: scala.collection.IterableOnce[A], replaced: Int): this.type
136152

137153
// +=, ++=, clear inherited from Growable
@@ -141,29 +157,85 @@ trait Buffer[A]
141157
// def +=:(elem1: A, elem2: A, elems: A*): this.type = elem1 +=: elem2 +=: elems ++=: this
142158
// def ++=:(elems: IterableOnce[A]): this.type = { insertAll(0, elems); this }
143159

160+
/** Removes the first `n` elements from this $coll.
161+
*
162+
* @param n the number of elements to remove
163+
* @return this $coll
164+
*
165+
*/
144166
def dropInPlace(n: Int): this.type = { remove(0, normalized(n)); this }
167+
168+
/** Removes the last `n` elements from this $coll.
169+
*
170+
* @param n the number of elements to remove
171+
* @return this $coll
172+
*
173+
*/
145174
def dropRightInPlace(n: Int): this.type = {
146175
val norm = normalized(n)
147176
remove(length - norm, norm)
148177
this
149178
}
179+
180+
/** Retains the first `n` elements from this $coll and removes the rest.
181+
*
182+
* @param n the number of elements to retain
183+
* @return this $coll
184+
*
185+
*/
150186
def takeInPlace(n: Int): this.type = {
151187
val norm = normalized(n)
152188
remove(norm, length - norm)
153189
this
154190
}
191+
192+
/** Retains the last `n` elements from this $coll and removes the rest.
193+
*
194+
* @param n the number of elements to retain
195+
* @return this $coll
196+
*
197+
*/
155198
def takeRightInPlace(n: Int): this.type = { remove(0, length - normalized(n)); this }
199+
200+
/** Retains the specified slice from this $coll and removes the rest.
201+
*
202+
* @param start the lowest index to include
203+
* @param end the lowest index to exclude
204+
* @return this $coll
205+
*
206+
*/
156207
def sliceInPlace(start: Int, end: Int): this.type = takeInPlace(end).dropInPlace(start)
208+
157209
private def normalized(n: Int): Int = math.min(math.max(n, 0), length)
158210

211+
/** Drops the longest prefix of elements that satisfy a predicate.
212+
*
213+
* @param p The predicate used to test elements.
214+
* @return this $coll
215+
* @see [[dropWhile]]
216+
*/
159217
def dropWhileInPlace(p: A => Boolean): this.type = {
160218
val idx = indexWhere(!p(_))
161219
if (idx < 0) { clear(); this } else dropInPlace(idx)
162220
}
221+
222+
/** Retains the longest prefix of elements that satisfy a predicate.
223+
*
224+
* @param p The predicate used to test elements.
225+
* @return this $coll
226+
* @see [[takeWhile]]
227+
*/
163228
def takeWhileInPlace(p: A => Boolean): this.type = {
164229
val idx = indexWhere(!p(_))
165230
if (idx < 0) this else takeInPlace(idx)
166231
}
232+
233+
/** Append the given element to this $coll until a target length is reached.
234+
*
235+
* @param len the target length
236+
* @param elem the padding value
237+
* @return this $coll
238+
*/
167239
def padToInPlace(len: Int, elem: A): this.type = {
168240
while (length < len) +=(elem)
169241
this
@@ -180,6 +252,11 @@ trait IndexedBuffer[A] extends IndexedSeq[A]
180252

181253
override def iterableFactory: SeqFactory[IndexedBuffer] = IndexedBuffer
182254

255+
/** Replace the contents of this $coll with the flatmapped result.
256+
*
257+
* @param f the mapping function
258+
* @return this $coll
259+
*/
183260
def flatMapInPlace(f: A => IterableOnce[A]): this.type = {
184261
// There's scope for a better implementation which copies elements in place.
185262
var i = 0
@@ -192,6 +269,11 @@ trait IndexedBuffer[A] extends IndexedSeq[A]
192269
this
193270
}
194271

272+
/** Replace the contents of this $coll with the filtered result.
273+
*
274+
* @param f the filtering function
275+
* @return this $coll
276+
*/
195277
def filterInPlace(p: A => Boolean): this.type = {
196278
var i, j = 0
197279
while (i < size) {

0 commit comments

Comments
 (0)