diff options
author | michelou <michelou@epfl.ch> | 2007-01-17 14:29:25 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2007-01-17 14:29:25 +0000 |
commit | 81d2963d4c9f959429ec2e38f4928ec62db9c410 (patch) | |
tree | cb59c9f995624d2dc3b828b97bf53b72463f2092 /src/library | |
parent | 767bb1b875dbde7aef1994edf445dbc687dbe8eb (diff) | |
download | scala-81d2963d4c9f959429ec2e38f4928ec62db9c410.tar.gz scala-81d2963d4c9f959429ec2e38f4928ec62db9c410.tar.bz2 scala-81d2963d4c9f959429ec2e38f4928ec62db9c410.zip |
added svn:keywords and file header to collectio...
added svn:keywords and file header to collection/jcl/*.scala
Diffstat (limited to 'src/library')
32 files changed, 569 insertions, 148 deletions
diff --git a/src/library/scala/collection/jcl/ArrayList.scala b/src/library/scala/collection/jcl/ArrayList.scala index 5de213ce2a..abb7378732 100644 --- a/src/library/scala/collection/jcl/ArrayList.scala +++ b/src/library/scala/collection/jcl/ArrayList.scala @@ -1,7 +1,18 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; /** Creates a buffer backed by a Java array list. - * @author Sean McDirmid + * + * @author Sean McDirmid */ class ArrayList[A](override val underlying : java.util.ArrayList) extends ConcreteWrapper[A] with BufferWrapper[A] { def this() = this(new java.util.ArrayList); diff --git a/src/library/scala/collection/jcl/Buffer.scala b/src/library/scala/collection/jcl/Buffer.scala index 0919e62914..69c59bd447 100644 --- a/src/library/scala/collection/jcl/Buffer.scala +++ b/src/library/scala/collection/jcl/Buffer.scala @@ -1,23 +1,39 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; /** A mutable sequence that supports element insertion and update. * - * @author Sean McDirmid + * @author Sean McDirmid */ trait Buffer[A] extends MutableSeq[A] with Collection[A] with Sorted[Int,A] { final protected type SortedSelf = Buffer[A]; + override def elements : BufferIterator[Int,A]; + /** The first index of a buffer is 0. */ override def first = 0; + /** The last index of a buffer is its size - 1. */ override def last = size - 1; + /** Indices are compared through subtraction. */ final def compare(k0 : Int, k1 : Int) = k0 - k1; + /** Removes the element at index "idx" */ def remove(idx : Int) = { val i = elements; val ret = i.seek(idx); i.remove; ret; } + /** Replaces the element at index "idx" with "a." * @returns the element replaced. */ @@ -25,8 +41,10 @@ trait Buffer[A] extends MutableSeq[A] with Collection[A] with Sorted[Int,A] { val i = elements; val ret = i.seek(idx); i.set(a); ret; } + /** Equivalent to set except the replaced element is not returned. */ def update(idx : Int, a : A) : Unit = set(idx, a); + /** @returns always true. */ def add(a : A) : Boolean = { val i = elements; @@ -34,19 +52,27 @@ trait Buffer[A] extends MutableSeq[A] with Collection[A] with Sorted[Int,A] { i.add(a); true; } + /** Inserts "a" into this buffer just before the element at index "idx." */ - def add(idx : Int, a : A) : Unit = { + def add(idx: Int, a: A): Unit = { val i = elements; i.seek(idx); i.add(a); } - /** Inserts all elements of "that" into this buffer just before the element at index "idx." */ - def addAll(idx : Int, that : Iterable[A]) : Unit = { + + /** Inserts all elements of <code>that</code> into this buffer just before + * the element at index <code>idx</code>. + * + * @param idx .. + * @param that .. + */ + def addAll(idx: Int, that: Iterable[A]): Unit = { val i = elements; i.seek(idx); for (val that <- that) { i.add(that); i.next; } } - override def transform(f : A => A) : Boolean = { + + override def transform(f: A => A): Boolean = { var changed = false; val i = elements; while (i.hasNext) { diff --git a/src/library/scala/collection/jcl/BufferIterator.scala b/src/library/scala/collection/jcl/BufferIterator.scala index be1101df9f..3faeb0b354 100644 --- a/src/library/scala/collection/jcl/BufferIterator.scala +++ b/src/library/scala/collection/jcl/BufferIterator.scala @@ -1,19 +1,32 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; /** An iterator for a buffer that supports element update and insertion. - * @author Sean McDirmid + * + * @author Sean McDirmid */ trait BufferIterator[K,A] extends SeqIterator[K,A] { + /** Sets the element before this iterator's cursor to "a." - * Replaces either the last element returned by "next" or, - * if previous was called, - * the next element that would be return by "previous." - */ - def set(a : A) : Unit; + * Replaces either the last element returned by "next" or, + * if previous was called, + * the next element that would be return by "previous." + */ + def set(a: A): Unit; /** Inserts "a" after the iterator's cursor. - If next was last called, "a" is inserted after the element returned. - If previous was last called, "a" is inserted before the element returned. - */ - def add(a : A) : Unit; + * If next was last called, "a" is inserted after the element returned. + * If previous was last called, "a" is inserted before the element returned. + */ + def add(a: A): Unit; + } diff --git a/src/library/scala/collection/jcl/BufferWrapper.scala b/src/library/scala/collection/jcl/BufferWrapper.scala index 2364322d28..af97e9f03f 100644 --- a/src/library/scala/collection/jcl/BufferWrapper.scala +++ b/src/library/scala/collection/jcl/BufferWrapper.scala @@ -1,8 +1,19 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; /** Wraps Java lists. - * @author Sean McDirmid - */ + * + * @author Sean McDirmid + */ trait BufferWrapper[A] extends Buffer[A] with CollectionWrapper[A] { protected def underlying : java.util.List; override def elements : BufferIterator[Int,A] = new IteratorWrapper(underlying.listIterator); diff --git a/src/library/scala/collection/jcl/Collection.scala b/src/library/scala/collection/jcl/Collection.scala index 2b2589fdfc..2f2dd646cb 100644 --- a/src/library/scala/collection/jcl/Collection.scala +++ b/src/library/scala/collection/jcl/Collection.scala @@ -1,43 +1,61 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; + object Collection { val DEFAULT_FILTER : Any => Boolean = x => true; } /** Analogous to a Java collection. - ** - ** @author Sean McDirmid - **/ + * + * @author Sean McDirmid + */ trait Collection[A] extends MutableIterable[A] { /** Type-safe version of containsAll. ** ** @author Sean McDirmid **/ - def hasAll(i : Iterable[A]) : Boolean = i.forall(elements.has); + def hasAll(i: Iterable[A]): Boolean = i.forall(elements.has); + /** Adds "a" to the collection, return true if "a" is actually added. */ - def add(a : A ) : Boolean; + def add(a: A): Boolean; + /** Adds all elements in "i" to the collection, return true if any elements are added. */ - def addAll(i : Iterable[A]) : Boolean = { + def addAll(i: Iterable[A]): Boolean = { var changed = false; i.foreach(t => changed = add(t) || changed); changed; } /** Operator shortcut for addAll. */ - def ++(that : Iterable[A]) : this.type = { + def ++(that: Iterable[A]): this.type = { addAll(that); this; } - /** removes "a" from the collection. */ def -=(a : A) : Unit = remove(a); + /** adds "a" from the collection. */ def +=(t : A) : Unit = add(t); + /** adds "a" from the collection. Useful for chaining. */ def +(t : A) : this.type = { add(t); this; } - /** Transforms each element of the collection in-place according to "f." Returns true - ** if the collection is actually updated. - **/ - def transform(f : A => A) : Boolean; + /** Transforms each element of the collection in-place according to + * <code>f</code>. + * + * @param f + * @return <code>true</code> if the collection is actually updated. + */ + def transform(f: A => A): Boolean; + /** Used for non-strict filtered collection that only includes elements of this collection that are true for "p." ** Any elements added to or removed from the resulting ** filter will update this collection. Any changes to this collection @@ -45,6 +63,7 @@ trait Collection[A] extends MutableIterable[A] { ** @return a non-strict filter of this collection. **/ def pfilter(p : A => Boolean) : MutableIterable[A] = new Filter(p); + /** Base implementation of a filtered collection */ class Filter(p : A => Boolean) extends Collection[A] { def transform(f : A => A) = diff --git a/src/library/scala/collection/jcl/CollectionWrapper.scala b/src/library/scala/collection/jcl/CollectionWrapper.scala index 94a439e269..4b70eaa887 100644 --- a/src/library/scala/collection/jcl/CollectionWrapper.scala +++ b/src/library/scala/collection/jcl/CollectionWrapper.scala @@ -1,9 +1,19 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; /** Used to wrap Java collections in Scala. - ** - ** @author Sean McDirmid - **/ + * + * @author Sean McDirmid + */ trait CollectionWrapper[A] extends Collection[A] with IterableWrapper[A] { /** Override to specify the collection being accessed through this wrapper. ** Collection operations are then routed through the wrapped Java collection. diff --git a/src/library/scala/collection/jcl/ConcreteMapWrapper.scala b/src/library/scala/collection/jcl/ConcreteMapWrapper.scala index 1f9a16dab4..6b622fdeec 100644 --- a/src/library/scala/collection/jcl/ConcreteMapWrapper.scala +++ b/src/library/scala/collection/jcl/ConcreteMapWrapper.scala @@ -1,14 +1,26 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; -/** A concrete wrapper around a Java map. The identity of the wraper is fixed to the identity of the underlying map. - * @author Sean McDirmid - */ +/** A concrete wrapper around a Java map. The identity of the wraper is + * fixed to the identity of the underlying map. + * + * @author Sean McDirmid + */ abstract class ConcreteMapWrapper[K,E] extends MapWrapper[K,E] { - val underlying : java.util.Map; + val underlying: java.util.Map; override def toString = underlying.toString; override def hashCode = underlying.hashCode; override def equals(that : Any) = that match { - case that : ConcreteMapWrapper[_,_] => underlying == that.underlying; - case _ => false; + case that: ConcreteMapWrapper[_,_] => underlying == that.underlying; + case _ => false; } } diff --git a/src/library/scala/collection/jcl/ConcreteWrapper.scala b/src/library/scala/collection/jcl/ConcreteWrapper.scala index f113ba827e..d24cbb1951 100644 --- a/src/library/scala/collection/jcl/ConcreteWrapper.scala +++ b/src/library/scala/collection/jcl/ConcreteWrapper.scala @@ -1,18 +1,28 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; -/* Describes wrappers around concrete underlying collections. The identity - * of the wrapper is related strictly to the Java collection being wrapped, - * which is structurally determined. +/** Describes wrappers around concrete underlying collections. The identity + * of the wrapper is related strictly to the Java collection being wrapped, + * which is structurally determined. * - * @author Sean McDirmid + * @author Sean McDirmid */ abstract class ConcreteWrapper[A] extends CollectionWrapper[A] { - val underlying : java.util.Collection; + val underlying: java.util.Collection; override def elements : MutableIterator[A] = super.elements; override def toString = underlying.toString; override def hashCode = underlying.hashCode; override def equals(that : Any) = that match { - case that : ConcreteWrapper[_] => underlying == that.underlying; - case _ => false; + case that: ConcreteWrapper[_] => underlying == that.underlying; + case _ => false; } } diff --git a/src/library/scala/collection/jcl/HashMap.scala b/src/library/scala/collection/jcl/HashMap.scala index f87631396e..31281c1694 100644 --- a/src/library/scala/collection/jcl/HashMap.scala +++ b/src/library/scala/collection/jcl/HashMap.scala @@ -1,8 +1,19 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; /** A map that is backed by a Java hash map. - * @author Sean McDirmid - */ -class HashMap[K,E](override val underlying : java.util.HashMap) extends ConcreteMapWrapper[K,E] { + * + * @author Sean McDirmid + */ +class HashMap[K,E](override val underlying: java.util.HashMap) extends ConcreteMapWrapper[K,E] { def this() = this(new java.util.HashMap); } diff --git a/src/library/scala/collection/jcl/HashSet.scala b/src/library/scala/collection/jcl/HashSet.scala index 005db81a36..255415e5cd 100644 --- a/src/library/scala/collection/jcl/HashSet.scala +++ b/src/library/scala/collection/jcl/HashSet.scala @@ -1,10 +1,20 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; /** A hash set that is backed by a Java hash set. - ** - ** @author Sean McDirmid - **/ -class HashSet[A](override val underlying : java.util.HashSet) extends ConcreteWrapper[A] with SetWrapper[A] { + * + * @author Sean McDirmid + */ +class HashSet[A](override val underlying: java.util.HashSet) extends ConcreteWrapper[A] with SetWrapper[A] { /** Creates an underlying Java hash set. */ def this() = this(new java.util.HashSet); } diff --git a/src/library/scala/collection/jcl/IdentityHashMap.scala b/src/library/scala/collection/jcl/IdentityHashMap.scala index e1aa07c72e..5df2363009 100644 --- a/src/library/scala/collection/jcl/IdentityHashMap.scala +++ b/src/library/scala/collection/jcl/IdentityHashMap.scala @@ -1,9 +1,22 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; -/** A map that is backed by a Java identity hash map, which compares keys by their reference-based identity - * as opposed to using equals and hashCode. An identity hash map will often perform better than traditional hash map because it can utilize linear probing. - * @author Sean McDirmid - */ +/** A map that is backed by a Java identity hash map, which compares keys + * by their reference-based identity as opposed to using equals and hashCode. + * An identity hash map will often perform better than traditional hash map + * because it can utilize linear probing. + * + * @author Sean McDirmid + */ class IdentityHashMap[K,E](override val underlying : java.util.IdentityHashMap) extends ConcreteMapWrapper[K,E] { def this() = this(new java.util.IdentityHashMap); } diff --git a/src/library/scala/collection/jcl/IterableWrapper.scala b/src/library/scala/collection/jcl/IterableWrapper.scala index 10d37f5549..b904342af6 100644 --- a/src/library/scala/collection/jcl/IterableWrapper.scala +++ b/src/library/scala/collection/jcl/IterableWrapper.scala @@ -1,17 +1,29 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; + /** A wrapper around a Java collection that only supports remove mutations. - * @author Sean McDirmid + * + * @author Sean McDirmid */ trait IterableWrapper[A] extends MutableIterable[A] { - protected def underlying : java.util.Collection; - override def remove(a : A) = underlying.remove(a); - override def removeAll(that : Iterable[A]) = that match { - case that : IterableWrapper[_] => underlying.removeAll(that.underlying); - case _ => super.removeAll(that); + protected def underlying: java.util.Collection; + override def remove(a: A) = underlying.remove(a); + override def removeAll(that: Iterable[A]) = that match { + case that: IterableWrapper[_] => underlying.removeAll(that.underlying); + case _ => super.removeAll(that); } override def retainAll(that : Iterable[A]) = that match { - case that : IterableWrapper[_] => underlying.retainAll(that.underlying); - case _ => super.retainAll(that); + case that : IterableWrapper[_] => underlying.retainAll(that.underlying); + case _ => super.retainAll(that); } override def size = underlying.size; override def isEmpty = underlying.isEmpty; diff --git a/src/library/scala/collection/jcl/LinkedHashMap.scala b/src/library/scala/collection/jcl/LinkedHashMap.scala index f2050d05e3..f0d16584af 100644 --- a/src/library/scala/collection/jcl/LinkedHashMap.scala +++ b/src/library/scala/collection/jcl/LinkedHashMap.scala @@ -1,8 +1,20 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; -/** A map that is backed by a Java linked hash map, which fixes iteration order in terms of insertion order. - * @author Sean McDirmid - */ -class LinkedHashMap[K,E](override val underlying : java.util.LinkedHashMap) extends ConcreteMapWrapper[K,E] { +/** A map that is backed by a Java linked hash map, which fixes iteration + * order in terms of insertion order. + * + * @author Sean McDirmid + */ +class LinkedHashMap[K,E](override val underlying: java.util.LinkedHashMap) extends ConcreteMapWrapper[K,E] { def this() = this(new java.util.LinkedHashMap); } diff --git a/src/library/scala/collection/jcl/LinkedHashSet.scala b/src/library/scala/collection/jcl/LinkedHashSet.scala index d3c7485cb8..463f2d3ca3 100644 --- a/src/library/scala/collection/jcl/LinkedHashSet.scala +++ b/src/library/scala/collection/jcl/LinkedHashSet.scala @@ -1,8 +1,20 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; -/** A set that is backed by a Java linked hash set, which fixes iteration order in terms of insertion order. - * @author Sean McDirmid - */ -class LinkedHashSet[A](override val underlying : java.util.LinkedHashSet) extends ConcreteWrapper[A] with SetWrapper[A] { +/** A set that is backed by a Java linked hash set, which fixes iteration + * order in terms of insertion order. + * + * @author Sean McDirmid + */ +class LinkedHashSet[A](override val underlying: java.util.LinkedHashSet) extends ConcreteWrapper[A] with SetWrapper[A] { def this() = this(new java.util.LinkedHashSet); } diff --git a/src/library/scala/collection/jcl/LinkedList.scala b/src/library/scala/collection/jcl/LinkedList.scala index d05e68746f..3aaeecd95a 100644 --- a/src/library/scala/collection/jcl/LinkedList.scala +++ b/src/library/scala/collection/jcl/LinkedList.scala @@ -1,9 +1,21 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; -/** Creates a buffer backed by a Java linked list. Includes additional peek/poll/removeFirst/removeLast APIs - * that are useful in implementing queues and stacks. - * @author Sean McDirmid - */ +/** Creates a buffer backed by a Java linked list. Includes additional + * peek/poll/removeFirst/removeLast APIs that are useful in implementing + * queues and stacks. + * + * @author Sean McDirmid + */ class LinkedList[A](override val underlying : java.util.LinkedList) extends ConcreteWrapper[A] with BufferWrapper[A] { def this() = this(new java.util.LinkedList); override def elements = super[BufferWrapper].elements; diff --git a/src/library/scala/collection/jcl/Map.scala b/src/library/scala/collection/jcl/Map.scala index a16ba82d53..de888c08a8 100644 --- a/src/library/scala/collection/jcl/Map.scala +++ b/src/library/scala/collection/jcl/Map.scala @@ -1,7 +1,18 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; /** A mutable map that is compatible with Java maps. - * @author Sean McDirmid + * + * @author Sean McDirmid */ trait Map[K,E] extends MutableIterable[Tuple2[K,E]] with scala.collection.mutable.Map[K,E] { override def clear = super[MutableIterable].clear; diff --git a/src/library/scala/collection/jcl/MapWrapper.scala b/src/library/scala/collection/jcl/MapWrapper.scala index 5fb1a8d6b4..7677c5ffca 100644 --- a/src/library/scala/collection/jcl/MapWrapper.scala +++ b/src/library/scala/collection/jcl/MapWrapper.scala @@ -1,8 +1,19 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; /** A wrapper around a Java map. - * @author Sean McDirmid - */ + * + * @author Sean McDirmid + */ trait MapWrapper[K,E] extends jcl.Map[K,E] { protected def underlying : java.util.Map; override def size = underlying.size; diff --git a/src/library/scala/collection/jcl/MutableIterable.scala b/src/library/scala/collection/jcl/MutableIterable.scala index baf5a0c727..52aab52914 100644 --- a/src/library/scala/collection/jcl/MutableIterable.scala +++ b/src/library/scala/collection/jcl/MutableIterable.scala @@ -1,3 +1,13 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; /** diff --git a/src/library/scala/collection/jcl/MutableIterator.scala b/src/library/scala/collection/jcl/MutableIterator.scala index 4a4530c641..fadb45e5f5 100644 --- a/src/library/scala/collection/jcl/MutableIterator.scala +++ b/src/library/scala/collection/jcl/MutableIterator.scala @@ -1,25 +1,43 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; /** An iterator that supports the remove operation. - ** These iterators wrap Java iterators, and so have the same fail fast behavior when dealing - ** with concurrent modifications. - ** - ** @author Sean McDirmid - **/ + * These iterators wrap Java iterators, and so have the same fail fast + * behavior when dealing with concurrent modifications. + * + * @author Sean McDirmid + */ trait MutableIterator[A] extends Iterator[A] { def remove : Unit; + override def filter(f : A => Boolean) : MutableIterator[A] = { val buffered = this.buffered0; new buffered.Filter(f); } - override def map[B](f : A => B) : MutableIterator[B] = new Map(f); + + override def map[B](f: A => B) : MutableIterator[B] = new Map(f); /** A type-safe version of contains. **/ - def has(a : A) = exists(b => a == a); - /** Finds and removes the first instance of "a" through the iterator. After execution, the iterator's cursor is located where the removed element existed. - ** Returns false if "a" is not encountered in the iterator and the iterator's cursor is located at the end of its elements. - **/ - def remove(a : A) : Boolean = { + def has(a: A) = exists(b => a == a); + + /** Finds and removes the first instance of "a" through the iterator. + * After execution, the iterator's cursor is located where the removed + * element existed. + * + * @param a .. + * @return <code>false</code> if "a" is not encountered in the iterator + * and the iterator's cursor is located at the end of its elements. + */ + def remove(a: A): Boolean = { while (hasNext) if (next == a) { remove; return true; } return false; @@ -41,6 +59,7 @@ trait MutableIterator[A] extends Iterator[A] { def next = f(MutableIterator.this.next); def remove = MutableIterator.this.remove; } + private[jcl] trait Buffered extends MutableIterator[A] { private[jcl] override def buffered0 : this.type = this; private[jcl] def peekNext : A; @@ -60,6 +79,7 @@ trait MutableIterator[A] extends Iterator[A] { override def remove : Unit = Buffered.this.remove; } } + private[jcl] class BufferedImpl extends Buffered { protected var head : A = _; protected def underlying = MutableIterator.this; diff --git a/src/library/scala/collection/jcl/MutableSeq.scala b/src/library/scala/collection/jcl/MutableSeq.scala index f1ea9fc61b..a84f248966 100644 --- a/src/library/scala/collection/jcl/MutableSeq.scala +++ b/src/library/scala/collection/jcl/MutableSeq.scala @@ -1,22 +1,37 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; /** A mutable sequence that supports the remove operation and is ordered. * - * @author Sean McDirmid + * @author Sean McDirmid */ trait MutableSeq[A] extends MutableIterable[A] with Seq[A] { override def elements : SeqIterator[Int,A]; + override def isEmpty = super[MutableIterable].isEmpty; + override def length = size; + override def apply(idx : Int) = elements.seek(idx); + def pfilter(p : A => Boolean) : MutableSeq[A] = new Filter(p); + override def pmap[B](f : A => B) : MutableSeq[B] = new Map[B](f); + /** Find the index of "a" in this sequence. * @returns None if the "a" is not in this sequence. */ def indexOf(a : A) = elements.indexOf(a); - protected class Filter(p : A => Boolean) extends MutableSeq[A] { def elements : SeqIterator[Int,A] = new FilterIterator(MutableSeq.this.elements); class FilterIterator(underlying : SeqIterator[Int,A]) extends SeqIterator[Int,A] { @@ -59,6 +74,7 @@ trait MutableSeq[A] extends MutableIterable[A] with Seq[A] { def remove = underlying.remove; } } + protected class Map[B](f : A => B) extends super.Map[B](f) with MutableSeq[B] { override def elements = MutableSeq.this.elements.map(f); override def apply(idx : Int) = f(MutableSeq.this.apply(idx)); diff --git a/src/library/scala/collection/jcl/SeqIterator.scala b/src/library/scala/collection/jcl/SeqIterator.scala index 584f2dfb79..5461928735 100644 --- a/src/library/scala/collection/jcl/SeqIterator.scala +++ b/src/library/scala/collection/jcl/SeqIterator.scala @@ -1,27 +1,44 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; /** An iterator for a sequence that can move both forwards and backwards. - * over a set of ordered keys. - * @author Sean McDirmid - */ + * over a set of ordered keys. + * + * @author Sean McDirmid + */ trait SeqIterator[K,A] extends MutableIterator[A] { /** @returns The index at the iterator's cursor. */ - def nextIndex : K; + def nextIndex: K; + /** @returns The index of the element before the iterator's cursor. */ - def previousIndex : K; - /** @returns The previous element, will move the iterator's cursor backwards. */ - def previous : A; - /** @returns True if and only if the iterator's cursor is not at the beging of the iteration. */ + def previousIndex: K; + + /** @return The previous element, will move the iterator's cursor backwards. */ + def previous: A; + + /** @return True if and only if the iterator's cursor is not at the beging of the iteration. */ def hasPrevious : Boolean; /** Winds the iteration forward until index "idx" is found */ - def seek(idx : K) = { + def seek(idx: K) = { while (nextIndex != idx) next; next; } /** finds the index of the next "a" in this iteration. - @returns None if "a" is not found in the iteration. */ - def indexOf(a : A) : Option[K] = { + * + * @param a .. + * @return <code>None</code> if "a" is not found in the iteration. + */ + def indexOf(a: A): Option[K] = { while (hasNext) { val ret = next; if (ret == a) return Some(previousIndex); @@ -29,8 +46,8 @@ trait SeqIterator[K,A] extends MutableIterator[A] { return None; } - override def map[B](f : A => B) : SeqIterator[K,B] = new Map[B](f); - class Map[B](f : A => B) extends super.Map[B](f) with SeqIterator[K,B] { + override def map[B](f: A => B) : SeqIterator[K,B] = new Map[B](f); + class Map[B](f: A => B) extends super.Map[B](f) with SeqIterator[K,B] { override def hasPrevious = SeqIterator.this.hasPrevious; override def previous = f(SeqIterator.this.previous); override def previousIndex = SeqIterator.this.previousIndex; diff --git a/src/library/scala/collection/jcl/Set.scala b/src/library/scala/collection/jcl/Set.scala index 68a92a7e6e..3589064df1 100644 --- a/src/library/scala/collection/jcl/Set.scala +++ b/src/library/scala/collection/jcl/Set.scala @@ -1,10 +1,21 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; /** Analogous to a Java set. - ** - ** @author Sean McDirmid - **/ + * + * @author Sean McDirmid + */ trait Set[A] extends Collection[A] with scala.collection.mutable.Set[A] { + /** Add will return false if "a" already exists in the set. **/ override def add(a : A) : Boolean; @@ -15,6 +26,7 @@ trait Set[A] extends Collection[A] with scala.collection.mutable.Set[A] { override def retain(f : A => Boolean) = super[Collection].retain(f); override def isEmpty = super[Collection].isEmpty; override final def contains(a : A) = has(a); + override def transform(f : A => A) = { var toAdd : List[A] = Nil; val i = elements; @@ -27,6 +39,7 @@ trait Set[A] extends Collection[A] with scala.collection.mutable.Set[A] { } addAll(toAdd); } + override def pfilter(p : A => Boolean) : Set[A] = new Filter(p); class Filter(p : A => Boolean) extends super.Filter(p) with Set[A] { override def filter(p : A => Boolean) = super[Set].filter(p); diff --git a/src/library/scala/collection/jcl/SetWrapper.scala b/src/library/scala/collection/jcl/SetWrapper.scala index 54d19e6675..9388fdcea1 100644 --- a/src/library/scala/collection/jcl/SetWrapper.scala +++ b/src/library/scala/collection/jcl/SetWrapper.scala @@ -1,10 +1,20 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; /** Used to wrap Java sets. - ** - ** @author Sean McDirmid - **/ + * + * @author Sean McDirmid + */ trait SetWrapper[A] extends CollectionWrapper[A] with Set[A] { - protected def underlying : java.util.Set; + protected def underlying: java.util.Set; override def isEmpty = super[Set].isEmpty; } diff --git a/src/library/scala/collection/jcl/Sorted.scala b/src/library/scala/collection/jcl/Sorted.scala index 5381720141..62e2e0dcb5 100644 --- a/src/library/scala/collection/jcl/Sorted.scala +++ b/src/library/scala/collection/jcl/Sorted.scala @@ -1,36 +1,55 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; /** Any collection (including maps) whose keys (or elements) are ordered. - ** - ** @author Sean McDirmid - **/ + * + * @author Sean McDirmid + */ trait Sorted[K,A] extends MutableIterable[A] { protected type SortedSelf <: Sorted[K,A]; /** Returns the first key of the collection. */ - def first : K; + def first: K; + /** Returns the last key of the collection. */ - def last : K; + def last: K; + /** Comparison function that orders keys. */ - def compare(k0 : K, k1 : K) : Int; - /** Creates a ranged projection of this collection. Any mutations in the ranged projection - ** will update this collection and vice versa. - ** @param from The lower-bound (inclusive) of the ranged projection. None if there is no lower bound. - ** @param until The upper-bound (exclusive) of the ranged projection. None if there is no upper bound. - **/ - def rangeImpl(from : Option[K], until : Option[K]) : SortedSelf; + def compare(k0: K, k1: K): Int; + + /** Creates a ranged projection of this collection. Any mutations in the + * ranged projection will update this collection and vice versa. + * + * @param from The lower-bound (inclusive) of the ranged projection. + * <code>None</code> if there is no lower bound. + * @param until The upper-bound (exclusive) of the ranged projection. + * <code>None</code> if there is no upper bound. + */ + def rangeImpl(from: Option[K], until: Option[K]) : SortedSelf; + /** Creates a ranged projection of this collection with no upper-bound. ** @param from The lower-bound (inclusive) of the ranged projection. **/ - final def from(from : K) : SortedSelf = rangeImpl(Some(from), None); + final def from(from: K): SortedSelf = rangeImpl(Some(from), None); + /** Creates a ranged projection of this collection with no lower-bound. ** @param from The upper-bound (exclusive) of the ranged projection. **/ - final def until(until : K) : SortedSelf = rangeImpl(None, Some(until)); + final def until(until: K): SortedSelf = rangeImpl(None, Some(until)); + /** Creates a ranged projection of this collection with both a lower-bound and an upper-bound. ** @param from The upper-bound (exclusive) of the ranged projection. **/ - final def range(from : K, until : K) : SortedSelf = rangeImpl(Some(from),Some(until)); + final def range(from: K, until: K) : SortedSelf = rangeImpl(Some(from),Some(until)); /** A wrapper around Java comparators. */ protected class Comparator[K <% Ordered[K]] extends java.util.Comparator { diff --git a/src/library/scala/collection/jcl/SortedMap.scala b/src/library/scala/collection/jcl/SortedMap.scala index 968a9887e3..1449addf3b 100644 --- a/src/library/scala/collection/jcl/SortedMap.scala +++ b/src/library/scala/collection/jcl/SortedMap.scala @@ -1,8 +1,19 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; /** A map whose keys are sorted. - * @author Sean McDirmid - */ + * + * @author Sean McDirmid + */ trait SortedMap[K,E] extends Map[K,E] with Sorted[K,Tuple2[K,E]] { final protected type SortedSelf = SortedMap[K,E]; override def compare(k0 : K, k1 : K) : Int; @@ -43,6 +54,7 @@ trait SortedMap[K,E] extends Map[K,E] with Sorted[K,Tuple2[K,E]] { override def rangeImpl(from : Option[K], until : Option[K]) : SortedMap[K,E] = SortedMap.this.Range(from, until).pfilter(p); } + protected def Range(from : Option[K], until : Option[K]) : SortedMap[K,E] = new Range(from,until); protected class Range(from : Option[K], until : Option[K]) extends SuperFilter(key => { ((from == None || (compare(from.get,key) <= 0)) && diff --git a/src/library/scala/collection/jcl/SortedMapWrapper.scala b/src/library/scala/collection/jcl/SortedMapWrapper.scala index c96aba9ff9..a4deaad5cd 100644 --- a/src/library/scala/collection/jcl/SortedMapWrapper.scala +++ b/src/library/scala/collection/jcl/SortedMapWrapper.scala @@ -1,8 +1,19 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; /** A sorted map that wraps an underlying Java sorted map. - * @author Sean McDirmid - */ + * + * @author Sean McDirmid + */ trait SortedMapWrapper[K,E] extends MapWrapper[K,E] with SortedMap[K,E] { protected override def underlying : java.util.SortedMap; /** the comparator function of this sorted map is defined in terms diff --git a/src/library/scala/collection/jcl/SortedSet.scala b/src/library/scala/collection/jcl/SortedSet.scala index c5d5242e21..80fc56a813 100644 --- a/src/library/scala/collection/jcl/SortedSet.scala +++ b/src/library/scala/collection/jcl/SortedSet.scala @@ -1,5 +1,17 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; + /** Analogous to a Java sorted set. + * * @author Sean McDirmid */ trait SortedSet[A] extends jcl.Set[A] with Sorted[A,A] { diff --git a/src/library/scala/collection/jcl/SortedSetWrapper.scala b/src/library/scala/collection/jcl/SortedSetWrapper.scala index e087af93b8..7e1af55690 100644 --- a/src/library/scala/collection/jcl/SortedSetWrapper.scala +++ b/src/library/scala/collection/jcl/SortedSetWrapper.scala @@ -1,9 +1,24 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; -/** A wrapper around a Java sorted set. - ** The comparator of the sorted set matches the comparator of this set. - @author Sean McDirmid - */ +/** <p> + * A wrapper around a Java sorted set. + * </p> + * <p> + * The comparator of the sorted set matches the comparator of this set. + * </p> + * + * @author Sean McDirmid + */ trait SortedSetWrapper[A] extends SortedSet[A] with SetWrapper[A] { protected def underlying : java.util.SortedSet; /** delegates to the comparator of the underlying Java sorted set */ diff --git a/src/library/scala/collection/jcl/Tests.scala b/src/library/scala/collection/jcl/Tests.scala index 91f9d34943..779a04e399 100644 --- a/src/library/scala/collection/jcl/Tests.scala +++ b/src/library/scala/collection/jcl/Tests.scala @@ -1,11 +1,23 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; private[jcl] object Tests { + def main(args : Array[String]) : Unit = { hashSet; treeSet; treeMap; } + def treeSet : Unit = { val set = new TreeSet[String]; set + "aaa" + "bbb" + "ccc" + "ddd" + "eee" + "fff"; @@ -24,6 +36,7 @@ private[jcl] object Tests { Console.println(rset); Console.println(fset); } + def treeMap : Unit = { val map = new TreeMap[String,Integer]; map + ("bb" -> 3) + ("cc" -> 4) + ("aa" -> 2) + ("dd" -> 5); @@ -34,10 +47,8 @@ private[jcl] object Tests { //Console.println(map); val fmap : SortedMap[String,Integer] = rmap.pfilter(k => k.length == 2); Console.println(fmap); - } - def hashSet = { val set = new HashSet[String]; set + "hello" + "world" + "you" + "to"; diff --git a/src/library/scala/collection/jcl/TreeMap.scala b/src/library/scala/collection/jcl/TreeMap.scala index 06cb3fd341..6b8d1ef9bc 100644 --- a/src/library/scala/collection/jcl/TreeMap.scala +++ b/src/library/scala/collection/jcl/TreeMap.scala @@ -1,8 +1,19 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; /** A sorted map that is backed by a Java tree map. - * @author Sean McDirmid - */ + * + * @author Sean McDirmid + */ class TreeMap[K <% Ordered[K],E] extends ConcreteMapWrapper[K,E] with SortedMapWrapper[K,E] { val underlying = (new java.util.TreeMap(new Comparator[K])); } diff --git a/src/library/scala/collection/jcl/TreeSet.scala b/src/library/scala/collection/jcl/TreeSet.scala index 01cfe5036e..4374b11077 100644 --- a/src/library/scala/collection/jcl/TreeSet.scala +++ b/src/library/scala/collection/jcl/TreeSet.scala @@ -1,10 +1,20 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; /** Creates a sorted set that is backed by an underlying Java tree set. Elements - * of the sorted set are ordered with respect to the ordered view bound of A. - * - * @author Sean McDirmid - */ + * of the sorted set are ordered with respect to the ordered view bound of A. + * + * @author Sean McDirmid + */ class TreeSet[A <% Ordered[A]] extends ConcreteWrapper[A] with SortedSetWrapper[A] { val underlying = new java.util.TreeSet(new Comparator[A]); } diff --git a/src/library/scala/collection/jcl/WeakHashMap.scala b/src/library/scala/collection/jcl/WeakHashMap.scala index 726ad7407e..15494acaa8 100644 --- a/src/library/scala/collection/jcl/WeakHashMap.scala +++ b/src/library/scala/collection/jcl/WeakHashMap.scala @@ -1,11 +1,29 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection.jcl; -/** A map that is backed by a Java weak hash map, whose keys are maintained as weak references. - * Because keys are weak references, the garbage collector can collect them if they are not referred to elsewhere. - * Useful for implementing caches. +/** <p> + * A map that is backed by a Java weak hash map, whose keys are maintained + * as weak references. + * </p> + * <p> + * Because keys are weak references, the garbage collector can collect + * them if they are not referred to elsewhere. + * </p> + * <p> + * Useful for implementing caches. + * </p> * * @author Sean McDirmid */ -class WeakHashMap[K,E](override val underlying : java.util.WeakHashMap) extends ConcreteMapWrapper[K,E] { +class WeakHashMap[K,E](override val underlying: java.util.WeakHashMap) extends ConcreteMapWrapper[K,E] { def this() = this(new java.util.WeakHashMap); } |