diff options
author | Burak Emir <emir@epfl.ch> | 2006-11-06 14:55:38 +0000 |
---|---|---|
committer | Burak Emir <emir@epfl.ch> | 2006-11-06 14:55:38 +0000 |
commit | e2e0a9488d1c97ff7095d63996ef131c4bcf8eb3 (patch) | |
tree | 7050f1768a2cf13a1ba6e395577f1280b1055a18 /src/library | |
parent | 516f06d7bd48509f4baeff069b5113e3005ed631 (diff) | |
download | scala-e2e0a9488d1c97ff7095d63996ef131c4bcf8eb3.tar.gz scala-e2e0a9488d1c97ff7095d63996ef131c4bcf8eb3.tar.bz2 scala-e2e0a9488d1c97ff7095d63996ef131c4bcf8eb3.zip |
removed CaseClass
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/Iterator.scala | 9 | ||||
-rw-r--r-- | src/library/scala/List.scala | 5 | ||||
-rw-r--r-- | src/library/scala/Product.scala | 6 | ||||
-rw-r--r-- | src/library/scala/Seq.scala | 3 | ||||
-rw-r--r-- | src/library/scala/runtime/ScalaRunTime.scala | 56 |
5 files changed, 23 insertions, 56 deletions
diff --git a/src/library/scala/Iterator.scala b/src/library/scala/Iterator.scala index 3e9dbdb957..a7dd7c6aad 100644 --- a/src/library/scala/Iterator.scala +++ b/src/library/scala/Iterator.scala @@ -67,13 +67,16 @@ object Iterator { def head = str charAt i } - def fromCaseClass(n:CaseClass): Iterator[Any] = new Iterator[Any] { + def fromProduct(n:Product): Iterator[Any] = new Iterator[Any] { private var c: Int = 0 - private val cmax = n.caseArity + private val cmax = n.arity def hasNext = c < cmax - def next = { val a = n caseElement c; c = c + 1; a } + def next = { val a = n element c; c = c + 1; a } } + /** deprecated */ + def fromCaseClass(n:Product) = fromProduct(n) + /** Create an iterator with elements * <code>e<sub>n+1</sub> = e<sub>n</sub> + 1</code> * where <code>e<sub>0</sub> = lo</code> diff --git a/src/library/scala/List.scala b/src/library/scala/List.scala index 3d622bd68c..581122448c 100644 --- a/src/library/scala/List.scala +++ b/src/library/scala/List.scala @@ -29,6 +29,11 @@ object List { */ def apply[A](xs: A*): List[A] = xs.toList + /** for unapply matching + */ + def unapplySeq[A](x:Any):Option[Tuple1[List[A]]] = + if(x.isInstanceOf[List[A]]) Some(Tuple1(x.asInstanceOf[List[A]])) else None + /** Create a sorted list of all integers in a range. * * @param from the start value of the list diff --git a/src/library/scala/Product.scala b/src/library/scala/Product.scala index 07bc5b045c..929f6c2591 100644 --- a/src/library/scala/Product.scala +++ b/src/library/scala/Product.scala @@ -6,13 +6,13 @@ ** |/ ** \* */ -// $Id: CaseClass.scala 8756 2006-09-22 16:00:23Z michelou $ +// $Id$ package scala -/** The trait <code>CaseClass</code> defines access functions for instances - * of case classes. +/** The trait <code>Product</code> defines access functions for instances + * of products, in particular case classes. * * @author Burak Emir * @version 1.0 diff --git a/src/library/scala/Seq.scala b/src/library/scala/Seq.scala index 8879422969..264d1122dc 100644 --- a/src/library/scala/Seq.scala +++ b/src/library/scala/Seq.scala @@ -16,6 +16,9 @@ import Predef.IllegalArgumentException object Seq { + def unapplySeq[A](x:Any): Option[Tuple1[Seq[A]]] = + if(x.isInstanceOf[Seq[A]]) Some(Tuple1(x.asInstanceOf[Seq[A]])) else None + /** builds a singleton sequence * @author buraq */ diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala index f20f6106fa..7173253316 100644 --- a/src/library/scala/runtime/ScalaRunTime.scala +++ b/src/library/scala/runtime/ScalaRunTime.scala @@ -68,13 +68,6 @@ object ScalaRunTime { throw exception; } - def caseFields(x: CaseClass): List[Any] = { - val arity = x.caseArity; - def fields(from: Int): List[Any] = - if (from >= arity) List() - else x.caseElement(from) :: fields(from + 1); - fields(0) - } def caseFields(x: Product): List[Any] = { val arity = x.arity; def fields(from: Int): List[Any] = @@ -82,28 +75,12 @@ object ScalaRunTime { else x.element(from) :: fields(from + 1); fields(1) } - def _toStringCaseClass(x: CaseClass): String = { - caseFields(x).mkString(x.caseName + "(", ",", ")") - } - def _toStringProduct(x: Product): String = { + + def _toString(x: Product): String = { caseFields(x).mkString(x.productPrefix + "(", ",", ")") } - /** only for bootstrapping 2.2.1 remove afterwards, keeping only _equalsProduct */ - def _toString(x: AnyRef): String = x match { - case xc: CaseClass => _toStringCaseClass(xc) - case xp: Product => _toStringProduct(xp) - } - def _hashCodeCaseClass(x: CaseClass): Int = { - var code = x.getClass().hashCode(); - val arr = x.caseArity - var i = 0; - while (i < arr) { - code = code * 41 + x.caseElement(i).hashCode(); - i = i + 1 - } - code - } - def _hashCodeProduct(x: Product): Int = { + + def _hashCode(x: Product): Int = { var code = x.getClass().hashCode(); val arr = x.arity var i = 1; @@ -113,24 +90,8 @@ object ScalaRunTime { } code } - /** only for bootstrapping 2.2.1 remove afterwards, keeping only _equalsProduct */ - def _hashCode(x: AnyRef): Int = x match { - case xc: CaseClass => _hashCodeCaseClass(xc) - case xp: Product => _hashCodeProduct(xp) - } - def _equalsCaseClass(x: CaseClass, y: Any): Boolean = y match { - case y1: CaseClass => - /*(x.getClass() eq y1.getClass() &&*/ { - val arity = x.caseArity; - var i = 0; - while (i < arity && x.caseElement(i) == y1.caseElement(i)) - i = i + 1; - i == arity - } - case _ => - false - } - def _equalsProduct(x: Product, y: Any): Boolean = y match { + + def _equals(x: Product, y: Any): Boolean = y match { case y1: Product if x.arity == y1.arity => /*(x.getClass() eq y1.getClass() &&*/ { val arity = x.arity; @@ -142,11 +103,6 @@ object ScalaRunTime { case _ => false } - /** only for bootstrapping 2.2.1 remove afterwards, keeping only _equalsProduct */ - def _equals(x: AnyRef, y: Any): Boolean = x match { - case xc: CaseClass => _equalsCaseClass(xc, y) - case xp: Product => _equalsProduct(xp, y) - } //def checkDefined[T >: Null](x: T): T = // if (x == null) throw new UndefinedException else x |