Permalink
Browse files

Zipper.unselect should only increase the update times of nodes receiv…

…ing updates.
  • Loading branch information...
1 parent 36d0978 commit 728879a8f32656d0a741fa21fda743f77404849b @josharnold52 josharnold52 committed Oct 19, 2011
@@ -194,7 +194,7 @@ class Group[+A <: Node] private[antixml] (private[antixml] val nodes: VectorCase
if (newNode eq node)
update(g, index + 1)
else
- update(g.updated(index, replacements.head), index + 1)
+ update(g.updated(index, newNode), index + 1)
} else {
build(g, replacements, index)
}
@@ -277,11 +277,7 @@ trait Zipper[+A <: Node] extends Group[A] with IndexedSeqLike[A, Zipper[A]] { se
else {
val replacements = fval.get
if (replacements.lengthCompare(1)==0) {
- val newNode = replacements.head
- if (newNode eq node)
- update(z, index + 1)
- else
- update(z.updated(index, replacements.head), index + 1)
+ update(z.updated(index, replacements.head), index + 1)
} else {
build(z, replacements, index)
}
@@ -300,8 +296,12 @@ trait Zipper[+A <: Node] extends Group[A] with IndexedSeqLike[A, Zipper[A]] { se
b += ElemsWithContext(metas(index)._1, z.time+1,currentReplacements)
for(i <- (index + 1) until nodes.length) {
val n = nodes(i)
+ val m = metas(i)
val fv = f(n,i)
- b += ElemsWithContext(metas(i)._1, z.time + 1 + i - index, fv.getOrElse(util.Vector1(n)))
+ if (fv.isDefined)
+ b += ElemsWithContext(m._1, z.time + 1 + i - index, fv.get)
+ else
+ b += ElemsWithContext(m._1, m._2, util.Vector1(n))
}
for((p,t) <- additionalHoles) {
b += ElemsWithContext(p,t,util.Vector0)
@@ -818,6 +818,44 @@ class ZipperSpecs extends SpecificationWithJUnit with ScalaCheck with XMLGenera
rc.length mustEqual 200
rc.toVectorCase mustEqual z2.toVectorCase
}
+
+ "only increase the update time of nodes being changed" in {
+ val xml = <top><a><b /></a></top>.convert
+ val z = xml \\ *
+
+ //Conflicting updates. Second node has latest update time.
+ val z1 = z.updated(0,elem("a",elem("c")))
+ val z2 = z1.updated(1,elem("b2"))
+
+ //Use CFMWI to update first node only, giving it the latest update time.
+ val z3 = z2.conditionalFlatMapWithIndex {(e,i) => i match {
+ case 0 => Some(Seq(e))
+ case _ => None
+ }}
+
+ z2.unselect mustEqual <top><a><b2 /></a></top>.convert.toGroup
+ z3.unselect mustEqual <top><a><c /></a></top>.convert.toGroup
+ }
+
+ "only increase the update time of nodes being changed 2" in {
+ val xml = <top><x /><a><b /></a></top>.convert
+ val z = xml \\ *
+
+ //Conflicting updates. Last node has latest update time.
+ val z1 = z.updated(1,elem("a",elem("c")))
+ val z2 = z1.updated(2,elem("b2"))
+
+ //Use CFMWI to delete the first node (forcing it to stop using its optimistic strategy)
+ //and then update the second node to give it the latest update time.
+ val z3 = z2.conditionalFlatMapWithIndex {(e,i) => i match {
+ case 0 => Some(Seq())
+ case 1 => Some(Seq(e))
+ case _ => None
+ }}
+
+ z2.unselect mustEqual <top><x/><a><b2 /></a></top>.convert.toGroup
+ z3.unselect mustEqual <top><a><c /></a></top>.convert.toGroup
+ }
}
"Zipper.slice" should {

0 comments on commit 728879a

Please sign in to comment.