From 21284e8b46a517e66a4a1bf4f9de3a6b19ae27c6 Mon Sep 17 00:00:00 2001 From: Antonio Cunei Date: Thu, 8 Apr 2010 20:57:55 +0000 Subject: Merged revisions 21372,21374-21375,21378-21383 ... Merged revisions 21372,21374-21375,21378-21383 via svnmerge from https://lampsvn.epfl.ch/svn-repos/scala/scala/trunk ........ r21372 | extempore | 2010-04-07 17:50:16 +0200 (Wed, 07 Apr 2010) | 3 lines Tore out some unnecessary ambiguity-creating aliases in the XML package object. I have a feeling we'll be traversing this kind of territory again. Closes #3264, no review. ........ r21374 | extempore | 2010-04-07 21:06:52 +0200 (Wed, 07 Apr 2010) | 10 lines Created a test.suite.clean.checkinit ant target which: runs ant all.clean builds with -Xcheckinit runs the test suite with -Xcheckinit Review by cunei? If the nightly is trying to do the above sequence with command line options, I suggest it be changed to run this target or a similar one so the logic is not separated from the buildfile. ........ r21375 | extempore | 2010-04-07 21:23:08 +0200 (Wed, 07 Apr 2010) | 4 lines Gave Stream a lazy withFilter implementation. Now you too can have a collection containing all the even numbers in the universe and still be home in time for tea. Threw in some Stream cleanups for free. Closes #3265, review by community. ........ r21378 | prokopec | 2010-04-08 14:04:55 +0200 (Thu, 08 Apr 2010) | 1 line Some typos in collections. Review by odersky. ........ r21379 | prokopec | 2010-04-08 15:05:33 +0200 (Thu, 08 Apr 2010) | 1 line Mostly some undocumented stuff in JavaConversions. Review by milessabin. ........ r21380 | dubochet | 2010-04-08 15:20:58 +0200 (Thu, 08 Apr 2010) | 1 line [scaladoc] Fixed filter method in template page (inherited filtering works again). No review. Fixed whitespace in sources. ........ r21381 | prokopec | 2010-04-08 16:16:31 +0200 (Thu, 08 Apr 2010) | 1 line Another set of typos fixed. Scan* added to TraversableMethods interface. Review by odersky. ........ r21382 | prokopec | 2010-04-08 18:09:24 +0200 (Thu, 08 Apr 2010) | 1 line More cleanups in docs. Review by odersky. ........ r21383 | extempore | 2010-04-08 20:12:34 +0200 (Thu, 08 Apr 2010) | 1 line Fix and test for Iterator corner case. Closes #3269, no review. ........ --- .../scala/tools/nsc/doc/html/resource/lib/index.js | 8 +- .../tools/nsc/doc/html/resource/lib/template.js | 207 +++++++++++---------- src/library/scala/collection/DefaultMap.scala | 2 +- src/library/scala/collection/IterableLike.scala | 8 +- src/library/scala/collection/Iterator.scala | 7 +- src/library/scala/collection/JavaConversions.scala | 21 +++ src/library/scala/collection/Map.scala | 2 +- src/library/scala/collection/MapLike.scala | 6 +- src/library/scala/collection/SeqLike.scala | 11 +- src/library/scala/collection/SetLike.scala | 2 +- src/library/scala/collection/TraversableLike.scala | 8 +- src/library/scala/collection/TraversableOnce.scala | 30 +-- .../scala/collection/TraversableProxyLike.scala | 2 +- .../generic/GenericTraversableTemplate.scala | 1 + .../scala/collection/immutable/Stream.scala | 112 +++++++---- .../collection/interfaces/TraversableMethods.scala | 2 + src/library/scala/xml/factory/XMLLoader.scala | 1 + .../scala/xml/include/sax/XIncludeFilter.scala | 4 +- src/library/scala/xml/include/sax/XIncluder.scala | 2 +- src/library/scala/xml/package.scala | 7 - 20 files changed, 255 insertions(+), 188 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/doc/html/resource/lib/index.js b/src/compiler/scala/tools/nsc/doc/html/resource/lib/index.js index 815a176390..e7cf484fa2 100644 --- a/src/compiler/scala/tools/nsc/doc/html/resource/lib/index.js +++ b/src/compiler/scala/tools/nsc/doc/html/resource/lib/index.js @@ -97,7 +97,7 @@ function configureTextFilter() { scheduler.add("init", function() { $("#filter").append("
"); var input = $("#textfilter > input"); - resizeFilterBlock(); + resizeFilterBlock(); input.bind("keyup", function(event) { if (event.keyCode == 27) { // escape input.attr("value", ""); @@ -105,7 +105,7 @@ function configureTextFilter() { textFilter(); }); input.focus(function(event) { input.select(); }); - }); + }); } // Filters all focused templates and packages. This function should be made less-blocking. @@ -227,9 +227,9 @@ function focusFilter(package) { domCache.update(); $("#focusfilter").show(); $("#kindfilter").hide(); - resizeFilterBlock(); + resizeFilterBlock(); focusFilterState = package; - kindFilterSync(); + kindFilterSync(); }); } diff --git a/src/compiler/scala/tools/nsc/doc/html/resource/lib/template.js b/src/compiler/scala/tools/nsc/doc/html/resource/lib/template.js index 47de01f6e2..a13c502ba5 100644 --- a/src/compiler/scala/tools/nsc/doc/html/resource/lib/template.js +++ b/src/compiler/scala/tools/nsc/doc/html/resource/lib/template.js @@ -2,115 +2,116 @@ // code by Gilles Dubochet with contributions by Pedro Furlanetto $(document).ready(function(){ - var prefilters = $("#ancestors > ol > li").filter(function(){ - var name = $(this).attr("name"); - return name == "scala.Any" || name == "scala.AnyRef"; - }); - prefilters.removeClass("in"); - prefilters.addClass("out"); - filter(); - $("#ancestors > ol > li").click(function(){ - if ($(this).hasClass("in")) { - $(this).removeClass("in"); - $(this).addClass("out"); - } - else if ($(this).hasClass("out")) { - $(this).removeClass("out"); - $(this).addClass("in"); - }; - filter(); - }); - $("#ancestors > ol > li.hideall").click(function() { - $("#ancestors > ol > li.in").removeClass("in").addClass("out"); - filter(); - }) - $("#ancestors > ol > li.showall").click(function() { - var filtered = - $("#ancestors > ol > li.out").filter(function() { - var name = $(this).attr("name"); - return !(name == "scala.Any" || name == "scala.AnyRef"); - }); - filtered.removeClass("out").addClass("in"); - filter(); - }); - $("#visbl > ol > li.public").click(function() { - if ($(this).hasClass("out")) { + var prefilters = $("#ancestors > ol > li").filter(function(){ + var name = $(this).attr("name"); + return name == "scala.Any" || name == "scala.AnyRef"; + }); + prefilters.removeClass("in"); + prefilters.addClass("out"); + filter(); + $("#ancestors > ol > li").click(function(){ + if ($(this).hasClass("in")) { + $(this).removeClass("in"); + $(this).addClass("out"); + } + else if ($(this).hasClass("out")) { + $(this).removeClass("out"); + $(this).addClass("in"); + }; + filter(); + }); + $("#ancestors > ol > li.hideall").click(function() { + $("#ancestors > ol > li.in").removeClass("in").addClass("out"); + filter(); + }) + $("#ancestors > ol > li.showall").click(function() { + var filtered = + $("#ancestors > ol > li.out").filter(function() { + var name = $(this).attr("name"); + return !(name == "scala.Any" || name == "scala.AnyRef"); + }); + filtered.removeClass("out").addClass("in"); + filter(); + }); + $("#visbl > ol > li.public").click(function() { + if ($(this).hasClass("out")) { $(this).removeClass("out").addClass("in"); $("#visbl > ol > li.all").removeClass("in").addClass("out"); - filter(); + filter(); }; - }) - $("#visbl > ol > li.all").click(function() { - if ($(this).hasClass("out")) { + }) + $("#visbl > ol > li.all").click(function() { + if ($(this).hasClass("out")) { $(this).removeClass("out").addClass("in"); $("#visbl > ol > li.public").removeClass("in").addClass("out"); - filter(); + filter(); }; - }); - //http://flowplayer.org/tools/tooltip.html - $(".extype").tooltip({ - tip: "#tooltip", - position:"top center", - onBeforeShow: function(ev) { + }); + //http://flowplayer.org/tools/tooltip.html + $(".extype").tooltip({ + tip: "#tooltip", + position:"top center", + onBeforeShow: function(ev) { $(this.getTip()).text(this.getTrigger().attr("name")); - } - }); - $("#template div.fullcomment").hide(); - var docAllSigs = $("#template .signature"); - function commentShowFct(fullComment){ - var vis = $(":visible", fullComment); - if (vis.length > 0) { - fullComment.slideUp(100); - } - else { - fullComment.slideDown(100); - } - }; - var docShowSigs = docAllSigs.filter(function(){ - return $("+ div.fullcomment", $(this)).length > 0; - }); - docShowSigs.css("cursor", "help"); - docShowSigs.click(function(){ - commentShowFct($("+ div.fullcomment", $(this))); - }); - function commentToggleFct(shortComment){ - var vis = $("~ div.fullcomment:visible", shortComment); - if (vis.length > 0) { - shortComment.slideDown(100); - vis.slideUp(100); - } - else { - var hid = $("~ div.fullcomment:hidden", shortComment); - hid.slideDown(100); - shortComment.slideUp(100); - } - }; - var docToggleSigs = docAllSigs.filter(function(){ - return $("+ p.shortcomment", $(this)).length > 0; - }); - docToggleSigs.css("cursor", "help"); - docToggleSigs.click(function(){ - commentToggleFct($("+ p.shortcomment", $(this))); - }); - $("p.shortcomment").click(function(){ - commentToggleFct($(this)); - }); + } + }); + $("#template div.fullcomment").hide(); + var docAllSigs = $("#template .signature"); + function commentShowFct(fullComment){ + var vis = $(":visible", fullComment); + if (vis.length > 0) { + fullComment.slideUp(100); + } + else { + fullComment.slideDown(100); + } + }; + var docShowSigs = docAllSigs.filter(function(){ + return $("+ div.fullcomment", $(this)).length > 0; + }); + docShowSigs.css("cursor", "help"); + docShowSigs.click(function(){ + commentShowFct($("+ div.fullcomment", $(this))); + }); + function commentToggleFct(shortComment){ + var vis = $("~ div.fullcomment:visible", shortComment); + if (vis.length > 0) { + shortComment.slideDown(100); + vis.slideUp(100); + } + else { + var hid = $("~ div.fullcomment:hidden", shortComment); + hid.slideDown(100); + shortComment.slideUp(100); + } + }; + var docToggleSigs = docAllSigs.filter(function(){ + return $("+ p.shortcomment", $(this)).length > 0; + }); + docToggleSigs.css("cursor", "help"); + docToggleSigs.click(function(){ + commentToggleFct($("+ p.shortcomment", $(this))); + }); + $("p.shortcomment").click(function(){ + commentToggleFct($(this)); + }); }); function filter() { var outOwners = - $("#mbrsel > div > ol > li.out").map(function(){ - $(this).attr("name") + $("#mbrsel ol#linearization > li.out").map(function(){ + var r = $(this).attr("name"); + return r }).get(); var prtVisbl = $("#visbl > ol > li.all").hasClass("in"); - $(".members > ol > li").each(function(){ - var vis1 = $(this).attr("visbl"); - var qualName1 = $(this).attr("name"); - var owner1 = qualName1.slice(0, qualName1.indexOf("#")); - //var name1 = qualName1.slice(qualName1.indexOf("#") + 1); - var showByOwned = true; + $(".members > ol > li").each(function(){ + var vis1 = $(this).attr("visbl"); + var qualName1 = $(this).attr("name"); + var owner1 = qualName1.slice(0, qualName1.indexOf("#")); + //var name1 = qualName1.slice(qualName1.indexOf("#") + 1); + var showByOwned = true; for (out in outOwners) { - if (out == owner1) { + if (outOwners[out] == owner1) { showByOwned = false; }; }; @@ -118,12 +119,12 @@ function filter() { if (vis1 == "prt") { showByVis = prtVisbl; }; - if (showByOwned && showByVis) { - $(this).show(); - } - else { - $(this).hide(); - }; - }); - return false + if (showByOwned && showByVis) { + $(this).show(); + } + else { + $(this).hide(); + }; + }); + return false }; diff --git a/src/library/scala/collection/DefaultMap.scala b/src/library/scala/collection/DefaultMap.scala index 6dd922a5b1..4ac4ad66c5 100644 --- a/src/library/scala/collection/DefaultMap.scala +++ b/src/library/scala/collection/DefaultMap.scala @@ -14,7 +14,7 @@ package scala.collection import generic._ /**

- * A default map which implements the updated and - + * A default map which implements the + and - * methods of maps.
* Instances that inherit from DefaultMap[A, B] still have to * define: diff --git a/src/library/scala/collection/IterableLike.scala b/src/library/scala/collection/IterableLike.scala index 6f88c72ffd..e348ba12e5 100644 --- a/src/library/scala/collection/IterableLike.scala +++ b/src/library/scala/collection/IterableLike.scala @@ -228,7 +228,7 @@ self => * @param bf $zipbfinfo * @return a new collection of type `That` containing pairs consisting of * corresponding elements of this $coll and `that`. The length - * of the returned collection is the minimum of the lengths of this $coll$ and `that`. + * of the returned collection is the minimum of the lengths of this $coll and `that`. * * @usecase def zip[B](that: Iterable[B]): $Coll[(A, B)] * @@ -236,7 +236,7 @@ self => * @tparam B the type of the second half of the returned pairs * @return a new $coll containing pairs consisting of * corresponding elements of this $coll and `that`. The length - * of the returned collection is the minimum of the lengths of this $coll$ and `that`. + * of the returned collection is the minimum of the lengths of this $coll and `that`. */ def zip[A1 >: A, B, That](that: Iterable[B])(implicit bf: CanBuildFrom[Repr, (A1, B), That]): That = { val b = bf(repr) @@ -259,7 +259,7 @@ self => * @param thatElem the element to be used to fill up the result if `that` is shorter than this $coll. * @return a new collection of type `That` containing pairs consisting of * corresponding elements of this $coll and `that`. The length - * of the returned collection is the maximum of the lengths of this $coll$ and `that`. + * of the returned collection is the maximum of the lengths of this $coll and `that`. * If this $coll is shorter than `that`, `thisElem` values are used to pad the result. * If `that` is shorter than this $coll, `thatElem` values are used to pad the result. * @@ -271,7 +271,7 @@ self => * @tparam B the type of the second half of the returned pairs * @return a new $coll containing pairs consisting of * corresponding elements of this $coll and `that`. The length - * of the returned collection is the maximum of the lengths of this $coll$ and `that`. + * of the returned collection is the maximum of the lengths of this $coll and `that`. * If this $coll is shorter than `that`, `thisElem` values are used to pad the result. * If `that` is shorter than this $coll, `thatElem` values are used to pad the result. */ diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala index 701b24f300..2ee4e8056e 100644 --- a/src/library/scala/collection/Iterator.scala +++ b/src/library/scala/collection/Iterator.scala @@ -374,9 +374,12 @@ trait Iterator[+A] extends TraversableOnce[A] { def ++[B >: A](that: => Iterator[B]): Iterator[B] = new Iterator[B] { // optimize a little bit to prevent n log n behavior. private var cur : Iterator[B] = self - // this was unnecessarily looping forever on x ++ x + // since that is by-name, make sure it's only referenced once - + // if "val it = that" is inside the block, then hasNext on an empty + // iterator will continually reevaluate it. (ticket #3269) + lazy val it = that + // the eq check is to avoid an infinite loop on "x ++ x" def hasNext = cur.hasNext || ((cur eq self) && { - val it = that it.hasNext && { cur = it true diff --git a/src/library/scala/collection/JavaConversions.scala b/src/library/scala/collection/JavaConversions.scala index 00f2d745af..20f44b7f21 100644 --- a/src/library/scala/collection/JavaConversions.scala +++ b/src/library/scala/collection/JavaConversions.scala @@ -25,6 +25,8 @@ package scala.collection *

  • scala.collection.mutable.Buffer <=> java.util.List
  • *
  • scala.collection.mutable.Set <=> java.util.Set
  • *
  • scala.collection.mutable.Map <=> java.util.Map
  • + *
  • scala.collection.mutable.ConcurrentMap <=> java.util.concurrent.ConcurrentMap
  • + *
  • java.util.Properties
  • => scala.collection.mutable.Map[String, String] * *

    * In all cases, converting from a source type to a target type and back @@ -184,6 +186,16 @@ object JavaConversions { case _ => new MutableMapWrapper(m)(ma) } + /** + * Implicitly converts a Scala mutable `ConcurrentMap` to a Java `ConcurrentMap`. + * The returned Java `ConcurrentMap` is backed by the provided Scala `ConcurrentMap` + * and any side-effects of using it via the Java interface will be visible + * via the Scala interface and vice versa. + *

    + * If the Scala ConcurrentMap was previously obtained from an implicit or + * explicit call of asConcurrentMap(java.util.concurrect.ConcurrentMap) then the original + * Java ConcurrentMap will be returned. + */ implicit def asConcurrentMap[A, B](m: mutable.ConcurrentMap[A, B]) (implicit ma: ClassManifest[A], mb: ClassManifest[B]): juc.ConcurrentMap[A, B] = m match { case JConcurrentMapWrapper(wrapped) => wrapped @@ -334,6 +346,15 @@ object JavaConversions { case _ => new JConcurrentMapWrapper(m) } + /** + * Implicitly converts a Java Properties to a Scala mutable Map[String, String]. + * The returned Scala Map[String, String] is backed by the provided Java + * Properties and any side-effects of using it via the Scala interface will + * be visible via the Java interface and vice versa. + * + * @param m The Properties to be converted. + * @return A Scala mutable Map[String, String] view of the argument. + */ implicit def asMap(p: ju.Properties): mutable.Map[String, String] = p match { case _ => new JPropertiesWrapper(p) } diff --git a/src/library/scala/collection/Map.scala b/src/library/scala/collection/Map.scala index c5d7b03687..9d44a950de 100644 --- a/src/library/scala/collection/Map.scala +++ b/src/library/scala/collection/Map.scala @@ -23,7 +23,7 @@ import generic._ * def + [B1 >: B](kv: (A, B1)): This * def -(key: A): This *

    - * If you wish that methods like, take, drop, filter return the same kind + * If you wish that methods like `take`, `drop`, `filter` return the same kind * of map, you should also override: *

      *    def empty: This
    diff --git a/src/library/scala/collection/MapLike.scala b/src/library/scala/collection/MapLike.scala index 5e1af7a2d7..6a9fffe3e1 100644 --- a/src/library/scala/collection/MapLike.scala +++ b/src/library/scala/collection/MapLike.scala @@ -60,7 +60,7 @@ self => // note: can't inherit Addable because of variance problems: Map // is covariant in its value type B, but Addable is nonvariant. - /* The empty map of the same type as this map + /** The empty map of the same type as this map * @return an empty map of type `This`. */ def empty: This @@ -295,7 +295,7 @@ self => * @param p A predicate over key-value pairs * @note This method works by successively removing elements fro which the * predicate is false from this set. - * If removal is slow, or you expect that most elements of the set$ + * If removal is slow, or you expect that most elements of the set * will be removed, you might consider using filter * with a negated predicate instead. */ @@ -311,7 +311,7 @@ self => * `end`. Inside, the string representations of all bindings of this map * in the form of `key -> value` are separated by the string `sep`. * - * @param b the builder to which strings are appended. + * @param b the builder to which strings are appended. * @param start the starting string. * @param sep the separator string. * @param end the ending string. diff --git a/src/library/scala/collection/SeqLike.scala b/src/library/scala/collection/SeqLike.scala index 0db64926a6..c35039c520 100644 --- a/src/library/scala/collection/SeqLike.scala +++ b/src/library/scala/collection/SeqLike.scala @@ -296,7 +296,7 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] { self => * @return the index `>= from` of the first element of this $coll that is equal (wrt `==`) * to `elem`, or `-1`, if none exists. * - * @usecase def indexOf(elem: A): Int + * @usecase def indexOf(elem: A, from: Int): Int */ def indexOf[B >: A](elem: B, from: Int): Int = indexWhere(elem ==, from) @@ -321,7 +321,7 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] { self => * @return the index `<= end` of the last element of this $coll that is equal (wrt `==`) * to `elem`, or `-1`, if none exists. * - * @usecase def lastIndexOf(elem: A): Int + * @usecase def lastIndexOf(elem: A, end: Int): Int */ def lastIndexOf[B >: A](elem: B, end: Int): Int = lastIndexWhere(elem ==, end) @@ -434,7 +434,6 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] { self => * * @param that the sequence to test * @return `true` if this collection has `that` as a prefix, `false` otherwise. - * otherwise false */ def startsWith[B](that: Seq[B]): Boolean = startsWith(that, 0) @@ -524,7 +523,7 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] { self => * * Another way to express this * is that `xs union ys` computes the order-presevring multi-set union of `xs` and `ys`. - * `union` is hence a counter-oart of `diff` and `intersect` which also work on multi-sets. + * `union` is hence a counter-part of `diff` and `intersect` which also work on multi-sets. * * $willNotTerminateInf * @@ -553,7 +552,7 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] { self => * If an element value `x` appears * ''n'' times in `that`, then the first ''n'' occurrences of `x` will not form * part of the result, but any following occurrences will. - * @usecase def union(that: Seq[A]): $Coll[A] + * @usecase def diff(that: Seq[A]): $Coll[A] * @return a new $coll which contains all elements of this $coll * except some of occurrences of elements that also appear in `that`. * If an element value `x` appears @@ -581,7 +580,7 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] { self => * If an element value `x` appears * ''n'' times in `that`, then the first ''n'' occurrences of `x` will be retained * in the result, but any following occurrences will be omitted. - * @usecase def union(that: Seq[A]): $Coll[A] + * @usecase def intersect(that: Seq[A]): $Coll[A] * @return a new $coll which contains all elements of this $coll * which also appear in `that`. * If an element value `x` appears diff --git a/src/library/scala/collection/SetLike.scala b/src/library/scala/collection/SetLike.scala index 48b5358afc..44dac8e8fe 100644 --- a/src/library/scala/collection/SetLike.scala +++ b/src/library/scala/collection/SetLike.scala @@ -53,7 +53,7 @@ extends IterableLike[A, This] with Subtractable[A, This] { self => - /* The empty set of the same type as this set + /** The empty set of the same type as this set * @return an empty set of type `This`. */ def empty: This diff --git a/src/library/scala/collection/TraversableLike.scala b/src/library/scala/collection/TraversableLike.scala index 7008d3b5fd..c5db41005e 100644 --- a/src/library/scala/collection/TraversableLike.scala +++ b/src/library/scala/collection/TraversableLike.scala @@ -473,7 +473,7 @@ trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr] with Traversable /** Optionally selects the first element. * $orderDependent - * @return the first element of this $coll$ if it is nonempty, `None` if it is empty. + * @return the first element of this $coll if it is nonempty, `None` if it is empty. */ def headOption: Option[A] = if (isEmpty) None else Some(head) @@ -688,7 +688,7 @@ trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr] with Traversable def toTraversable: Traversable[A] = thisCollection def toIterator: Iterator[A] = toIterable.iterator - /** Converts this $coll to a string + /** Converts this $coll to a string. * @return a string representation of this collection. By default this * string consists of the `stringPrefix` of this $coll, * followed by all elements separated by commas and enclosed in parentheses. @@ -743,7 +743,7 @@ trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr] with Traversable * @return an object of class `WithFilter`, which supports * `map`, `flatMap`, `foreach`, and `withFilter` operations. * All these operations apply to those elements of this $coll which - * satify the predicate `p`. + * satisfy the predicate `p`. */ def withFilter(p: A => Boolean): WithFilter = new WithFilter(p) @@ -820,7 +820,7 @@ trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr] with Traversable * @return an object of class `WithFilter`, which supports * `map`, `flatMap`, `foreach`, and `withFilter` operations. * All these operations apply to those elements of this $coll which - * satify the predicate `q` in addition to the predicate `p`. + * satisfy the predicate `q` in addition to the predicate `p`. */ def withFilter(q: A => Boolean): WithFilter = new WithFilter(x => p(x) && q(x)) diff --git a/src/library/scala/collection/TraversableOnce.scala b/src/library/scala/collection/TraversableOnce.scala index 6e4917b77e..ad3a8c6198 100644 --- a/src/library/scala/collection/TraversableOnce.scala +++ b/src/library/scala/collection/TraversableOnce.scala @@ -31,7 +31,7 @@ import mutable.{ Buffer, ListBuffer, ArrayBuffer } * @define coll traversable or iterator * @define orderDependentFold * - * Note: might return different results for different runs, unless the underlying collection type is ordered. + * Note: might return different results for different runs, unless the underlying collection type is ordered * or the operator is associative and commutative. * @define willNotTerminateInf * @@ -123,7 +123,7 @@ trait TraversableOnce[+A] { * @param z the start value. * @param op the binary operator. * @tparam B the result type of the binary operator. - * @return the result of inserting `op` between consecutive elements of this $coll$, + * @return the result of inserting `op` between consecutive elements of this $coll, * going left to right with the start value `z` on the left: * {{{ * op(...op(op(z, x,,1,,), x,,2,,), ..., x,,n,,) @@ -141,7 +141,7 @@ trait TraversableOnce[+A] { * @param z the start value * @param op the binary operator * @tparam B the result type of the binary operator. - * @return the result of inserting `op` between consecutive elements of this $coll$, + * @return the result of inserting `op` between consecutive elements of this $coll, * going right to left with the start value `z` on the right: * {{{ * op(x,,1,,, op(x,,2,,, ... op(x,,n,,, z)...)) @@ -158,7 +158,7 @@ trait TraversableOnce[+A] { * @param z the start value. * @param op the binary operator. * @tparam B the result type of the binary operator. - * @return the result of inserting `op` between consecutive elements of this $coll$, + * @return the result of inserting `op` between consecutive elements of this $coll, * going left to right with the start value `z` on the left: * {{{ * op(...op(z, x,,1,,), x,,2,,, ..., x,,n,,) @@ -178,7 +178,7 @@ trait TraversableOnce[+A] { * @param z the start value. * @param op the binary operator. * @tparam B the result type of the binary operator. - * @return the result of inserting `op` between consecutive elements of this $coll$, + * @return the result of inserting `op` between consecutive elements of this $coll, * going right to left with the start value `z` on the right: * {{{ * op(x,,1,,, op(x,,2,,, ... op(x,,n,,, z)...)) @@ -194,7 +194,7 @@ trait TraversableOnce[+A] { * * @param op the binary operator. * @tparam B the result type of the binary operator. - * @return the result of inserting `op` between consecutive elements of this $coll$, + * @return the result of inserting `op` between consecutive elements of this $coll, * going left to right: * {{{ * op(...(op(x,,1,,, x,,2,,), ... ) , x,,n,,) @@ -225,7 +225,7 @@ trait TraversableOnce[+A] { * * @param op the binary operator. * @tparam B the result type of the binary operator. - * @return the result of inserting `op` between consecutive elements of this $coll$, + * @return the result of inserting `op` between consecutive elements of this $coll, * going right to left: * {{{ * op(x,,1,,, op(x,,2,,, ..., op(x,,n-1,,, x,,n,,)...)) @@ -335,9 +335,9 @@ trait TraversableOnce[+A] { */ def copyToBuffer[B >: A](dest: Buffer[B]): Unit = dest ++= self - /** Copies values produced by this iterator to an array. - * Fills the given array `xs` with values produced by this iterator, after skipping `start` values. - * Copying will stop once either the end of the current iterator is reached, + /** Copies values of this $coll to an array. + * Fills the given array `xs` with values of this $coll, after skipping `start` values. + * Copying will stop once either the end of the current $coll is reached, * or the end of the array is reached. * * $willNotTerminateInf @@ -346,14 +346,14 @@ trait TraversableOnce[+A] { * @param start the starting index. * @tparam B the type of the elements of the array. * - * @usecase def copyToArray(xs: Array[A], start: Int, len: Int): Unit + * @usecase def copyToArray(xs: Array[A], start: Int): Unit */ def copyToArray[B >: A](xs: Array[B], start: Int): Unit = copyToArray(xs, start, xs.length - start) - /** Copies values produced by this iterator to an array. - * Fills the given array `xs` with values produced by this iterator. - * Copying will stop once either the end of the current iterator is reached, + /** Copies values of this $coll to an array. + * Fills the given array `xs` with values of this $coll. + * Copying will stop once either the end of the current $coll is reached, * or the end of the array is reached. * * $willNotTerminateInf @@ -361,7 +361,7 @@ trait TraversableOnce[+A] { * @param xs the array to fill. * @tparam B the type of the elements of the array. * - * @usecase def copyToArray(xs: Array[A], start: Int, len: Int): Unit + * @usecase def copyToArray(xs: Array[A]): Unit */ def copyToArray[B >: A](xs: Array[B]): Unit = copyToArray(xs, 0, xs.length) diff --git a/src/library/scala/collection/TraversableProxyLike.scala b/src/library/scala/collection/TraversableProxyLike.scala index fb8da98a6b..7b4bf99d04 100644 --- a/src/library/scala/collection/TraversableProxyLike.scala +++ b/src/library/scala/collection/TraversableProxyLike.scala @@ -18,7 +18,7 @@ import mutable.{Buffer, StringBuilder} /** This trait implements a proxy for traversable objects. It forwards - * all calls to a different traversable object + * all calls to a different traversable object. * * @author Martin Odersky * @version 2.8 diff --git a/src/library/scala/collection/generic/GenericTraversableTemplate.scala b/src/library/scala/collection/generic/GenericTraversableTemplate.scala index 683f609686..ecbfa8c20c 100644 --- a/src/library/scala/collection/generic/GenericTraversableTemplate.scala +++ b/src/library/scala/collection/generic/GenericTraversableTemplate.scala @@ -100,6 +100,7 @@ trait GenericTraversableTemplate[+A, +CC[X] <: Traversable[X]] extends HasNewBui } /** Transposes this $coll of traversable collections into + * a $coll of ${coll}s. * @tparam B the type of the elements of each traversable collection. * @param asTraversable an implicit conversion which asserts that the element type of this * $coll is a `Traversable`. diff --git a/src/library/scala/collection/immutable/Stream.scala b/src/library/scala/collection/immutable/Stream.scala index 3b10963ddb..7f0b21050a 100644 --- a/src/library/scala/collection/immutable/Stream.scala +++ b/src/library/scala/collection/immutable/Stream.scala @@ -72,17 +72,17 @@ self => def append[B >: A](rest: => Traversable[B]): Stream[B] = if (isEmpty) rest.toStream else new Stream.Cons(head, tail append rest) - /** Force evaluation of the whole stream and return it */ + /** Forces evaluation of the whole stream and returns it. */ def force: Stream[A] = { var these = this while (!these.isEmpty) these = these.tail this } - /** Prints elements of this stream one by one, separated by commas */ + /** Prints elements of this stream one by one, separated by commas. */ def print() { print(", ") } - /** Prints elements of this stream one by one, separated by sep + /** Prints elements of this stream one by one, separated by sep. * @param sep The separator string printed between consecutive elements. */ def print(sep: String) { @@ -97,6 +97,12 @@ self => loop(this, "") } + /** It's an imperfect world, but at least we can bottle up the + * imperfection in a capsule. + */ + @inline private def asThat[That](x: AnyRef): That = x.asInstanceOf[That] + @inline private def asStream[B](x: AnyRef): Stream[B] = x.asInstanceOf[Stream[B]] + // Overridden methods from Traversable override def toStream: Stream[A] = this @@ -107,27 +113,29 @@ self => } /** Create a new stream which contains all elements of this stream - * followed by all elements of Traversable `that' + * followed by all elements of Traversable `that`. * @note It's subtle why this works. We know that if the target type * of the Builder That is either a Stream, or one of its supertypes, or undefined, * then StreamBuilder will be chosen for the implicit. * we recognize that fact and optimize to get more laziness. */ - override def ++[B >: A, That](that: TraversableOnce[B])(implicit bf: CanBuildFrom[Stream[A], B, That]): That = { + override def ++[B >: A, That](that: TraversableOnce[B])(implicit bf: CanBuildFrom[Stream[A], B, That]): That = // we assume there is no other builder factory on streams and therefore know that That = Stream[A] - (if (isEmpty) that.toStream - else new Stream.Cons(head, (tail ++ that).asInstanceOf[Stream[A]])).asInstanceOf[That] - } + asThat[That]( + if (isEmpty) that.toStream + else new Stream.Cons(head, asStream[A](tail ++ that)) + ) /** * Create a new stream which contains all intermediate results of applying the operator * to subsequent elements left to right. * @note This works because the target type of the Builder That is a Stream. */ - override final def scanLeft[B, That](z: B)(op: (B, A) => B)(implicit bf: CanBuildFrom[Stream[A], B, That]): That = { - (if (this.isEmpty) Stream(z) - else new Stream.Cons(z, tail.scanLeft(op(z, head))(op).asInstanceOf[Stream[B]])).asInstanceOf[That] - } + override final def scanLeft[B, That](z: B)(op: (B, A) => B)(implicit bf: CanBuildFrom[Stream[A], B, That]): That = + asThat[That]( + if (isEmpty) Stream(z) + else new Stream.Cons(z, asStream[B](tail.scanLeft(op(z, head))(op))) + ) /** Returns the stream resulting from applying the given function * f to each element of this stream. @@ -136,10 +144,11 @@ self => * @return f(a0), ..., f(an) if this * sequence is a0, ..., an. */ - override final def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Stream[A], B, That]): That = { - (if (isEmpty) Stream.Empty - else new Stream.Cons(f(head), (tail map f).asInstanceOf[Stream[B]])).asInstanceOf[That] - } + override final def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Stream[A], B, That]): That = + asThat[That]( + if (isEmpty) Stream.Empty + else new Stream.Cons(f(head), asStream[B](tail map f)) + ) /** Applies the given function f to each element of * this stream, then concatenates the results. @@ -152,20 +161,22 @@ self => // we assume there is no other builder factory on streams and therefore know that That = Stream[B] // optimisations are not for speed, but for functionality // see tickets #153, #498, #2147, and corresponding tests in run/ (as well as run/stream_flatmap_odds.scala) - (if (isEmpty) Stream.Empty - else { - // establish !prefix.isEmpty || nonEmptyPrefix.isEmpty - var nonEmptyPrefix = this - var prefix = f(nonEmptyPrefix.head).toStream - while (!nonEmptyPrefix.isEmpty && prefix.isEmpty) { - nonEmptyPrefix = nonEmptyPrefix.tail - if(!nonEmptyPrefix.isEmpty) - prefix = f(nonEmptyPrefix.head).toStream + asThat[That]( + if (isEmpty) Stream.Empty + else { + // establish !prefix.isEmpty || nonEmptyPrefix.isEmpty + var nonEmptyPrefix = this + var prefix = f(nonEmptyPrefix.head).toStream + while (!nonEmptyPrefix.isEmpty && prefix.isEmpty) { + nonEmptyPrefix = nonEmptyPrefix.tail + if(!nonEmptyPrefix.isEmpty) + prefix = f(nonEmptyPrefix.head).toStream + } + + if (nonEmptyPrefix.isEmpty) Stream.empty + else prefix append asStream[B](nonEmptyPrefix.tail flatMap f) } - - if(nonEmptyPrefix.isEmpty) Stream.empty - else prefix append (nonEmptyPrefix.tail flatMap f).asInstanceOf[Stream[B]] - }).asInstanceOf[That] + ) /** Returns all the elements of this stream that satisfy the * predicate p. The order of the elements is preserved. @@ -180,6 +191,37 @@ self => else new Stream.Cons(rest.head, rest.tail filter p) } + override final def withFilter(p: A => Boolean): StreamWithFilter = new StreamWithFilter(p) + + /** A lazier implementation of WithFilter than TraversableLike's. + */ + final class StreamWithFilter(p: A => Boolean) extends WithFilter(p) { + override def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Stream[A], B, That]): That = { + def tailMap = asStream[B](tail withFilter p map f) + asThat[That]( + if (isEmpty) Stream.Empty + else if (p(head)) new Stream.Cons(f(head), tailMap) + else tailMap + ) + } + + override def flatMap[B, That](f: A => Traversable[B])(implicit bf: CanBuildFrom[Stream[A], B, That]): That = { + def tailFlatMap = asStream[B](tail withFilter p flatMap f) + asThat[That]( + if (isEmpty) Stream.Empty + else if (p(head)) f(head).toStream append tailFlatMap + else tailFlatMap + ) + } + + override def foreach[B](f: A => B) = + for (x <- self) + if (p(x)) f(x) + + override def withFilter(q: A => Boolean): StreamWithFilter = + new StreamWithFilter(x => p(x) && q(x)) + } + /** Apply the given function f to each element of this linear sequence * (while respecting the order of the elements). * @@ -224,11 +266,12 @@ self => * Stream(a0, ..., am) * zip Stream(b0, ..., bn) is invoked. */ - override final def zip[A1 >: A, B, That](that: Iterable[B])(implicit bf: CanBuildFrom[Stream[A], (A1, B), That]): That = { + override final def zip[A1 >: A, B, That](that: Iterable[B])(implicit bf: CanBuildFrom[Stream[A], (A1, B), That]): That = // we assume there is no other builder factory on streams and therefore know that That = Stream[(A1, B)] - (if (this.isEmpty || that.isEmpty) Stream.Empty - else new Stream.Cons((this.head, that.head), (this.tail zip that.tail).asInstanceOf[Stream[(A1, B)]])).asInstanceOf[That] - } + asThat[That]( + if (this.isEmpty || that.isEmpty) Stream.Empty + else new Stream.Cons((this.head, that.head), asStream[(A1, B)](this.tail zip that.tail)) + ) /** Zips this iterable with its indices. `s.zipWithIndex` is equivalent to * `s zip s.indices` @@ -359,7 +402,8 @@ self => def loop(len: Int, these: Stream[A]): Stream[B] = if (these.isEmpty) Stream.fill(len)(elem) else new Stream.Cons(these.head, loop(len - 1, these.tail)) - loop(len, this).asInstanceOf[That] + + asThat[That](loop(len, this)) // was: if (bf.isInstanceOf[Stream.StreamCanBuildFrom[_]]) loop(len, this).asInstanceOf[That] // else super.padTo(len, elem) } diff --git a/src/library/scala/collection/interfaces/TraversableMethods.scala b/src/library/scala/collection/interfaces/TraversableMethods.scala index 1fc2451ec0..7ec878b3d3 100644 --- a/src/library/scala/collection/interfaces/TraversableMethods.scala +++ b/src/library/scala/collection/interfaces/TraversableMethods.scala @@ -25,6 +25,8 @@ trait TraversableMethods[+A, +This <: TraversableLike[A, This] with Traversable[ def flatMap[B, That](f: A => Traversable[B])(implicit bf: CanBuildFrom[This, B, That]): That def map[B, That](f: A => B)(implicit bf: CanBuildFrom[This, B, That]): That def collect[B, That](pf: PartialFunction[A, B])(implicit bf: CanBuildFrom[This, B, That]): That + def scanLeft[B, That](z: B)(op: (B, A) => B)(implicit bf: CanBuildFrom[This, B, That]): That // could be fold or new collection too - where to put it? + def scanRight[B, That](z: B)(op: (A, B) => B)(implicit bf: CanBuildFrom[This, B, That]): That // new collections def ++[B >: A, That](xs: TraversableOnce[B])(implicit bf: CanBuildFrom[This, B, That]): That diff --git a/src/library/scala/xml/factory/XMLLoader.scala b/src/library/scala/xml/factory/XMLLoader.scala index 8bb0cf4188..6321c10e97 100644 --- a/src/library/scala/xml/factory/XMLLoader.scala +++ b/src/library/scala/xml/factory/XMLLoader.scala @@ -14,6 +14,7 @@ package factory import javax.xml.parsers.SAXParserFactory import parsing.{ FactoryAdapter, NoBindingFactoryAdapter } import java.io.{ InputStream, Reader, StringReader, File, FileDescriptor, FileInputStream } +import java.net.URL /** Presents collection of XML loading methods which use the parser * created by "def parser". diff --git a/src/library/scala/xml/include/sax/XIncludeFilter.scala b/src/library/scala/xml/include/sax/XIncludeFilter.scala index 6e64fa9aa5..b5c468dc81 100644 --- a/src/library/scala/xml/include/sax/XIncludeFilter.scala +++ b/src/library/scala/xml/include/sax/XIncludeFilter.scala @@ -10,13 +10,15 @@ package scala.xml package include.sax + import scala.xml.include._ import org.xml.sax.{ Attributes, XMLReader, Locator } import org.xml.sax.helpers.{ XMLReaderFactory, XMLFilterImpl, NamespaceSupport, AttributesImpl } -import java.io.{ InputStream, BufferedInputStream, InputStreamReader } +import java.io.{ InputStream, BufferedInputStream, InputStreamReader, IOException, UnsupportedEncodingException } import java.util.Stack +import java.net.{ URL, MalformedURLException } /** *

    diff --git a/src/library/scala/xml/include/sax/XIncluder.scala b/src/library/scala/xml/include/sax/XIncluder.scala index bd9da10c59..8bc3c4e41a 100644 --- a/src/library/scala/xml/include/sax/XIncluder.scala +++ b/src/library/scala/xml/include/sax/XIncluder.scala @@ -16,7 +16,7 @@ import collection.mutable.Stack import org.xml.sax.{ ContentHandler, XMLReader, Locator, Attributes } import org.xml.sax.ext.LexicalHandler -import java.io.{ File, OutputStream, OutputStreamWriter, Writer } +import java.io.{ File, OutputStream, OutputStreamWriter, Writer, IOException } /** XIncluder is a SAX ContentHandler * that writes its XML document onto an output stream after resolving diff --git a/src/library/scala/xml/package.scala b/src/library/scala/xml/package.scala index 33639ed978..dec05abd2a 100644 --- a/src/library/scala/xml/package.scala +++ b/src/library/scala/xml/package.scala @@ -7,12 +7,5 @@ package object xml { type SAXParseException = org.xml.sax.SAXParseException type EntityResolver = org.xml.sax.EntityResolver type InputSource = org.xml.sax.InputSource - type SAXParser = javax.xml.parsers.SAXParser - - type IOException = java.io.IOException - type UnsupportedEncodingException = java.io.UnsupportedEncodingException - - type URL = java.net.URL - type MalformedURLException = java.net.MalformedURLException } \ No newline at end of file -- cgit v1.2.3