diff options
author | Paul Phillips <paulp@improving.org> | 2010-01-19 18:24:29 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-01-19 18:24:29 +0000 |
commit | 4ed1910b1d36e6a2b4707a26374124d8faecc53e (patch) | |
tree | 0af1b8ccb3982cc3e4e1f79d6a62ca7e58213732 | |
parent | e077a9d6ae1c6f49bd7521bd8e86ff850c87d28b (diff) | |
download | scala-4ed1910b1d36e6a2b4707a26374124d8faecc53e.tar.gz scala-4ed1910b1d36e6a2b4707a26374124d8faecc53e.tar.bz2 scala-4ed1910b1d36e6a2b4707a26374124d8faecc53e.zip |
Iterators created with duplicate compare equal ...
Iterators created with duplicate compare equal if they are positioned at
the same element. Review by community.
-rw-r--r-- | src/library/scala/collection/Iterator.scala | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala index de0ec5275f..32525d59a6 100644 --- a/src/library/scala/collection/Iterator.scala +++ b/src/library/scala/collection/Iterator.scala @@ -994,7 +994,8 @@ trait Iterator[+A] { self => } /** Creates two new iterators that both iterate over the same elements - * as this iterator (in the same order). + * as this iterator (in the same order). The duplicate iterators are + * considered equal if they are positioned at the same element. * * @return a pair of iterators */ @@ -1013,6 +1014,14 @@ trait Iterator[+A] { self => e } else gap.dequeue } + // to verify partnerhood we use reference equality on gap because + // type testing does not discriminate based on origin. + private def compareGap(queue: scala.collection.mutable.Queue[A]) = gap eq queue + override def hashCode = gap.hashCode + override def equals(other: Any) = other match { + case x: Partner => x.compareGap(gap) && gap.isEmpty + case _ => super.equals(other) + } } (new Partner, new Partner) } |