summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Zenger <mzenger@gmail.com>2004-02-11 13:24:30 +0000
committerMatthias Zenger <mzenger@gmail.com>2004-02-11 13:24:30 +0000
commit5cf09c3b1beba694440384d52d9d7a345f2fc579 (patch)
treeb045d46db7c8c9ee3002149743affca71ae7586c
parentd266b00a2d453a05a1192d6843c74ac7c052b3ef (diff)
downloadscala-5cf09c3b1beba694440384d52d9d7a345f2fc579.tar.gz
scala-5cf09c3b1beba694440384d52d9d7a345f2fc579.tar.bz2
scala-5cf09c3b1beba694440384d52d9d7a345f2fc579.zip
*** empty log message ***
-rw-r--r--config/list/library.lst1
-rw-r--r--sources/scala/Array.java90
-rw-r--r--sources/scala/Enumeration.scala24
3 files changed, 79 insertions, 36 deletions
diff --git a/config/list/library.lst b/config/list/library.lst
index dcd7509dfd..747733f0b1 100644
--- a/config/list/library.lst
+++ b/config/list/library.lst
@@ -15,6 +15,7 @@ Char.java
Console.scala
Double.java
Application.scala
+Enumeration.scala
Float.java
Function0.java
Function1.java
diff --git a/sources/scala/Array.java b/sources/scala/Array.java
index 6a139ffd98..261908682f 100644
--- a/sources/scala/Array.java
+++ b/sources/scala/Array.java
@@ -4,24 +4,76 @@
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
+** $Id$
\* */
-// $OldId: Array.java,v 1.9 2002/03/18 16:55:10 zenger Exp $
-// $Id$
-
package scala;
-/** @meta class [?T] extends scala.Function1[scala.Int, ?T];
+
+/** @meta class [?T] extends scala.Function1[scala.Int, ?T] with scala.ScalaObject with java.lang.Cloneable with java.io.Serializable;
*/
public abstract class Array
extends java.lang.Object
- implements Function1, Cloneable, java.io.Serializable {
+ implements ScalaObject, Function1, Cloneable, java.io.Serializable {
/** @meta constr (scala.Int);
*/
public Array() {
}
+ /** @meta method []scala.Int;
+ */
+ public abstract int length();
+
+ /** @meta method (scala.Int, ?T) scala.Unit;
+ */
+ public abstract void update(int i, java.lang.Object x);
+
+ /** @meta method (scala.Int) ?T;
+ */
+ public abstract java.lang.Object apply(int i);
+
+ public java.lang.Object apply(java.lang.Object i) {
+ return apply(((scala.Int)i).value);
+ }
+
+ /** @meta method () scala.Array[scala.AnyRef];
+ */
+ public java.lang.Object[] asObjectArray() {
+ throw new ClassCastException();
+ }
+
+ /** @meta method (scala.Function1[?T, scala.Unit]) scala.Unit;
+ */
+ public void foreach(Function1 f) {
+ for (int i = 0; i < length(); i++)
+ f.apply(apply(scala.runtime.RunTime.box_ivalue(i)));
+ }
+
+ /** @meta method (scala.Function1[?T, scala.Boolean]) scala.Boolean;
+ */
+ public boolean forall(Function1 f) {
+ for (int i = 0; i < length(); i++)
+ if (!((scala.Boolean)f.apply(apply(scala.runtime.RunTime.box_ivalue(i)))).value)
+ return false;
+ return true;
+ }
+
+ /** @meta method (scala.Function1[?T, scala.Boolean]) scala.Boolean;
+ */
+ public boolean exists(Function1 f) {
+ for (int i = 0; i < length(); i++)
+ if (((scala.Boolean)f.apply(apply(scala.runtime.RunTime.box_ivalue(i)))).value)
+ return true;
+ return false;
+ }
+
+ /** @meta method () scala.Array[?T];
+ */
+ public java.lang.Object asArray() {
+ throw new ClassCastException();
+ }
+
public boolean[] asBooleanArray() {
throw new ClassCastException();
}
@@ -54,31 +106,7 @@ public abstract class Array
throw new ClassCastException();
}
- /** @meta method () scala.Array[scala.AnyRef];
- */
- public java.lang.Object[] asObjectArray() {
- throw new ClassCastException();
- }
-
- /** @meta method () scala.Array[?T];
- */
- public java.lang.Object asArray() {
- throw new ClassCastException();
+ public int $tag() {
+ return 0;
}
-
- public java.lang.Object apply(java.lang.Object i) {
- return apply(((Number) i).intValue());
- }
-
- /** @meta method (scala.Int) ?T;
- */
- public abstract java.lang.Object apply(int i);
-
- /** @meta method (scala.Int, ?T) scala.Unit;
- */
- public abstract void update(int i, java.lang.Object x);
-
- /** @meta method []scala.Int;
- */
- public abstract int length();
}
diff --git a/sources/scala/Enumeration.scala b/sources/scala/Enumeration.scala
index 83c62534d2..44e478d0ab 100644
--- a/sources/scala/Enumeration.scala
+++ b/sources/scala/Enumeration.scala
@@ -14,10 +14,20 @@ import scala.collection.mutable._;
abstract class Enumeration(initial: Int, names: String*) {
- def this() = this(0, "0");
+ def this() = this(0, null);
def this(names: String*) = this(0, names: _*);
+ def name = {
+ val cname = getClass().getName();
+ if (cname.endsWith("$"))
+ cname.substring(0, cname.length() - 1);
+ else if (cname.endsWith("$class"))
+ cname.substring(0, cname.length() - 6);
+ else
+ cname;
+ }
+
/** A mapping between the enumeration value id and the enumeration
* object.
*/
@@ -65,14 +75,14 @@ abstract class Enumeration(initial: Int, names: String*) {
override def toString(): String = updateCache.mkString("{", ", ", "}");
protected final def Value: Value =
- new Val(nextId, if (nextName.hasNext) nextName.next else nextId.toString());
+ new Val(nextId, if (nextName.hasNext) nextName.next else null);
protected final def Value(i: Int): Value =
- new Val(i, if (nextName.hasNext) nextName.next else i.toString());
+ new Val(i, if (nextName.hasNext) nextName.next else null);
protected final def Value(name: String): Value = new Val(nextId, name);
- protected final def Value(i: Int, name: String): Value = new Val(nextId, nextId.toString());
+ protected final def Value(i: Int, name: String): Value = new Val(i, name);
trait Value extends Ord[Value] {
def id: Int;
@@ -91,6 +101,10 @@ abstract class Enumeration(initial: Int, names: String*) {
if (nextId > topId)
topId = nextId;
def id = i;
- override def toString() = name;
+ override def toString() =
+ if (name == null)
+ Enumeration.this.name + "(" + i + ")";
+ else
+ name;
}
}