Further work creating pure interfaces for the collections

so we can validate their contents.  Also fixed an overly
loose upper bound in SequenceTemplate.

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@18613 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
extempore 2009-08-31 03:02:27 +00:00
parent 1b45254e24
commit 4d842529db
6 changed files with 110 additions and 4 deletions

View File

@ -29,7 +29,7 @@ import generic._
* @author Matthias Zenger
* @version 1.0, 16/07/2003
*/
trait SequenceTemplate[+A, +This <: IterableTemplate[A, This] with Sequence[A]] extends IterableTemplate[A, This] { self =>
trait SequenceTemplate[+A, +This <: SequenceTemplate[A, This] with Sequence[A]] extends IterableTemplate[A, This] { self =>
import Traversable.breaks._

View File

@ -12,13 +12,21 @@ import scala.collection._
import generic._
import mutable.Buffer
import scala.reflect.ClassManifest
import annotation.unchecked.uncheckedVariance
trait IterableMethods[+A, +This <: IterableTemplate[A, This] with Iterable[A]] extends TraversableMethods[A, This]
{
def dropRight(n: Int): Iterable[A]
// abstract
def iterator: Iterator[A]
// concrete
def dropRight(n: Int): Iterable[A]
def sameElements[B >: A](that: Iterable[B]): Boolean
def sortWith(lt: (A, A) => Boolean)(implicit m: ClassManifest[A @uncheckedVariance]): This
def takeRight(n: Int): Iterable[A]
def zipAll[B, A1 >: A, That](that: Iterable[B], e1: A1, e2: B)(implicit bf: BuilderFactory[(A1, B), That, This]): That
def zipWithIndex[A1 >: A, That](implicit bf: BuilderFactory[(A1, Int), That, This]): That
def zip[A1 >: A, B, That](that: Iterable[B])(implicit bf: BuilderFactory[(A1, B), That, This]): That
override def view: IterableView[A, This]
override def view(from: Int, until: Int): IterableView[A, This]

View File

@ -0,0 +1,41 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
package scala.collection.interfaces
import scala.collection._
import generic._
trait MapMethods[A, +B, +This <: MapTemplate[A, B, This] with Map[A, B]]
extends IterableMethods[(A, B), This]
with SubtractableMethods[A, This]
{
// abstract
def empty: This
def get(key: A): Option[B]
def iterator: Iterator[(A, B)]
def + [B1 >: B] (kv: (A, B1)): Map[A, B1]
def - (key: A): This
// concrete
def getOrElse[B1 >: B](key: A, default: => B1): B1
def apply(key: A): B
def contains(key: A): Boolean
def isDefinedAt(key: A): Boolean
def keySet: Set[A]
def keysIterator: Iterator[A]
def valueIterable: Iterable[B]
def valuesIterator: Iterator[B]
def default(key: A): B
def filterKeys(p: A => Boolean): DefaultMap[A, B]
def mapValues[C](f: B => C): DefaultMap[A, C]
def updated [B1 >: B](key: A, value: B1): Map[A, B1]
def + [B1 >: B] (elem1: (A, B1), elem2: (A, B1), elems: (A, B1) *): Map[A, B1]
def ++[B1 >: B](elems: Traversable[(A, B1)]): Map[A, B1]
def ++[B1 >: B] (iter: Iterator[(A, B1)]): Map[A, B1]
}

View File

@ -15,7 +15,10 @@ import scala.reflect.ClassManifest
trait SequenceMethods[+A, +This <: SequenceTemplate[A, This] with Sequence[A]] extends IterableMethods[A, This]
{
// abstract
def apply(idx: Int): A
def length: Int
def contains(elem: Any): Boolean
def diff[B >: A, That](that: Sequence[B]): This
def endsWith[B](that: Sequence[B]): Boolean
@ -34,7 +37,6 @@ trait SequenceMethods[+A, +This <: SequenceTemplate[A, This] with Sequence[A]] e
def lastIndexOf[B >: A](elem: B, end: Int): Int
def lastIndexWhere(p: A => Boolean): Int
def lastIndexWhere(p: A => Boolean, end: Int): Int
def length: Int
def lengthCompare(len: Int): Int
def padTo[B >: A, That](len: Int, elem: B)(implicit bf: BuilderFactory[B, That, This]): That
def patch[B >: A, That](from: Int, patch: Sequence[B], replaced: Int)(implicit bf: BuilderFactory[B, That, This]): That

View File

@ -0,0 +1,53 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
package scala.collection.interfaces
import scala.collection._
import generic._
import mutable.Buffer
import scala.reflect.ClassManifest
import annotation.unchecked.uncheckedVariance
trait AddableMethods[A, +This <: Addable[A, This]] {
protected def thisCollection: This
def +(elem: A): This
def + (elem1: A, elem2: A, elems: A*): This
def ++ (elems: Traversable[A]): This
def ++ (iter: Iterator[A]): This
}
trait SubtractableMethods[A, +This <: Subtractable[A, This]] {
protected def thisCollection: This
def -(elem: A): This
def -(elem1: A, elem2: A, elems: A*): This
def --(elems: Traversable[A]): This
def --(iter: Iterator[A]): This
}
trait SetMethods[A, +This <: SetTemplate[A, This] with Set[A]]
extends IterableMethods[A, This]
with AddableMethods[A, This]
with SubtractableMethods[A, This]
{
// abstract
def empty: This
def contains(elem: A): Boolean
def + (elem: A): This
def - (elem: A): This
// concrete
def apply(elem: A): Boolean
def intersect(that: Set[A]): This
def &(that: Set[A]): This
def union(that: Set[A]): This
def | (that: Set[A]): This
def diff(that: Set[A]): This
def &~(that: Set[A]): This
def subsetOf(that: Set[A]): Boolean
}

View File

@ -15,11 +15,13 @@ import scala.reflect.ClassManifest
trait TraversableMethods[+A, +This <: TraversableTemplate[A, This] with Traversable[A]]
{
// abstract
def foreach[U](f: A => U): Unit
// maps/iteration
def flatMap[B, That](f: A => Traversable[B])(implicit bf: BuilderFactory[B, That, This]): That
def map[B, That](f: A => B)(implicit bf: BuilderFactory[B, That, This]): That
def filterMap[B, That](pf: PartialFunction[Any, B])(implicit bf: BuilderFactory[B, That, This]): That
def foreach[U](f: A => U): Unit
// new collections
def ++[B >: A, That](that: Iterator[B])(implicit bf: BuilderFactory[B, That, This]): That