summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorPhilipp Haller <hallerp@gmail.com>2009-08-03 18:47:21 +0000
committerPhilipp Haller <hallerp@gmail.com>2009-08-03 18:47:21 +0000
commit744049bb71e61fbf072ccdeeaae9bc63f127c069 (patch)
tree647fb9c361c763ca0f71e5014fd5839f9df33863 /src/library
parentec5e34144e6a8673ee1078fcf0d79411869b9829 (diff)
downloadscala-744049bb71e61fbf072ccdeeaae9bc63f127c069.tar.gz
scala-744049bb71e61fbf072ccdeeaae9bc63f127c069.tar.bz2
scala-744049bb71e61fbf072ccdeeaae9bc63f127c069.zip
Applied patch for #2145.
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/collection/generic/SequenceTemplate.scala27
-rw-r--r--src/library/scala/collection/generic/TraversableTemplate.scala24
2 files changed, 27 insertions, 24 deletions
diff --git a/src/library/scala/collection/generic/SequenceTemplate.scala b/src/library/scala/collection/generic/SequenceTemplate.scala
index ec08d8a160..9ae4a29770 100644
--- a/src/library/scala/collection/generic/SequenceTemplate.scala
+++ b/src/library/scala/collection/generic/SequenceTemplate.scala
@@ -578,6 +578,33 @@ trait SequenceTemplate[+A, +This <: IterableTemplate[A, This] with Sequence[A]]
*/
override def toString = super[IterableTemplate].toString
+ /** Sort the sequence according to the comparison function
+ * <code>&lt;(e1: a, e2: a) =&gt; Boolean</code>,
+ * which should be true iff <code>e1</code> is smaller than
+ * <code>e2</code>.
+ * The sort is stable. That is elements that are equal wrt `lt` appear in the
+ * same order in the sorted sequence as in the original.
+ *
+ * @param lt the comparison function
+ * @return a sequence sorted according to the comparison function
+ * <code>&lt;(e1: a, e2: a) =&gt; Boolean</code>.
+ * @ex <pre>
+ * List("Steve", "Tom", "John", "Bob")
+ * .sortWith((e1, e2) => (e1 compareTo e2) &lt; 0) =
+ * List("Bob", "John", "Steve", "Tom")</pre>
+ */
+ def sortWith(lt: (A, A) => Boolean): This = {
+ val arr = toArray
+ import java.util.{Arrays, Comparator}
+ Arrays.sort(arr, new Comparator[A] {
+ override def compare(a: A, b: A) =
+ if (lt(a, b)) -1 else if (lt(b, a)) 1 else 0
+ })
+ val b = newBuilder
+ for (x <- arr) b += x
+ b.result
+ }
+
/** Returns index of the last element satisying a predicate, or -1. */
@deprecated("use `lastIndexWhere' instead")
def findLastIndexOf(p: A => Boolean): Int = lastIndexWhere(p)
diff --git a/src/library/scala/collection/generic/TraversableTemplate.scala b/src/library/scala/collection/generic/TraversableTemplate.scala
index 6e2c32e251..79e050b976 100644
--- a/src/library/scala/collection/generic/TraversableTemplate.scala
+++ b/src/library/scala/collection/generic/TraversableTemplate.scala
@@ -716,30 +716,6 @@ self =>
@experimental
def toSet[B >: A]: immutable.Set[B] = immutable.Set() ++ thisCollection
- /** Sort the traversable according to the comparison function
- * <code>&lt;(e1: a, e2: a) =&gt; Boolean</code>,
- * which should be true iff <code>e1</code> is smaller than
- * <code>e2</code>.
- * The sort is stable. That is elements that are equal wrt `lt` appear in the
- * same order in the sorted traversable as in the original.
- *
- * @param lt the comparison function
- * @return a traversable sorted according to the comparison function
- * <code>&lt;(e1: a, e2: a) =&gt; Boolean</code>.
- * @ex <pre>
- * List("Steve", "Tom", "John", "Bob")
- * .sort((e1, e2) => (e1 compareTo e2) &lt; 0) =
- * List("Bob", "John", "Steve", "Tom")</pre>
- * !!!
- def sortWith(lt : (A,A) => Boolean): This = {
- val arr = toArray
- Array.sortWith(arr, lt)
- val b = newBuilder[A]
- for (x <- arr) b += x
- b.result
- }
- */
-
/** Returns a string representation of this traversable object. The resulting string
* begins with the string <code>start</code> and is finished by the string
* <code>end</code>. Inside, the string representations of elements (w.r.t.