Skip to content

Commit e9e1efc

Browse files
committed
implement missing methods in 2.13 buffer-wrapper; insertAt -> insert
1 parent ca1579e commit e9e1efc

File tree

5 files changed

+41
-35
lines changed

5 files changed

+41
-35
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ scalaVersionsByJvm in ThisBuild := Map(
1616
11 -> List("2.11.12", "2.12.8", "2.13.0-M5").map(_ -> false)
1717
)
1818

19-
scalaVersion in ThisBuild := "2.13.0-M5" // for testing
19+
scalaVersion in ThisBuild := "2.11.12" // for testing
2020

2121
OsgiKeys.exportPackage := Seq(s"scala.swing.*;version=${version.value}")
2222

src/main/scala-2.12/scala/swing/BufferWrapper.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,28 @@ protected[swing] abstract class BufferWrapper[A] extends mutable.Buffer[A] {
1818

1919
def addOne(elem: A): this.type
2020

21-
protected def insertAt(n: Int, a: A): Unit
21+
def insert(idx: Int, elem: A): Unit
2222

2323
// impl
2424

25-
final def +=(elem: A): this.type = addOne(elem)
25+
final override def +=(elem: A): this.type = addOne(elem)
2626

27-
def clear(): Unit = for (_ <- 0 until length) remove(0)
27+
override def clear(): Unit = for (_ <- 0 until length) remove(0)
2828

29-
def update(n: Int, a: A): Unit = {
29+
override def update(n: Int, a: A): Unit = {
3030
remove(n)
31-
insertAt(n, a)
31+
insert(n, a)
3232
}
3333

34-
def insertAll(n: Int, elems: Traversable[A]): Unit = {
34+
override def insertAll(n: Int, elems: Traversable[A]): Unit = {
3535
var i = n
3636
for (el <- elems) {
37-
insertAt(i, el)
37+
insert(i, el)
3838
i += 1
3939
}
4040
}
4141

42-
def +=:(a: A): this.type = { insertAt(0, a); this }
42+
override def +=:(a: A): this.type = { insert(0, a); this }
4343

44-
def iterator: Iterator[A] = Iterator.range(0,length).map(apply)
44+
override def iterator: Iterator[A] = Iterator.range(0,length).map(apply)
4545
}

src/main/scala-2.13.0-M5/scala/swing/BufferWrapper.scala

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,41 @@ import scala.collection.{Iterator, mutable}
1414
* Default partial implementation for buffer adapters.
1515
*/
1616
protected[swing] abstract class BufferWrapper[A] extends mutable.Buffer[A] {
17-
def clear(): Unit = for (_ <- 0 until length) remove(0)
17+
override def clear(): Unit = for (_ <- 0 until length) remove(0)
1818

19-
def update(n: Int, a: A): Unit = {
19+
override def update(n: Int, a: A): Unit = {
2020
remove(n)
21-
insertAt(n, a)
21+
insert(n, a)
2222
}
2323

24-
def insertAll(n: Int, elems: Iterable[A]): Unit = {
25-
var i = n
26-
for (el <- elems) {
27-
insertAt(i, el)
24+
override def iterator: Iterator[A] = Iterator.range(0, length).map(apply)
25+
26+
override def prepend(elem: A): this.type = { insert(0, elem); this }
27+
28+
override def insertAll(idx: Int, elems: IterableOnce[A]): Unit = {
29+
var i = idx
30+
for (el <- elems.iterator) {
31+
insert(i, el)
2832
i += 1
2933
}
3034
}
3135

32-
protected def insertAt(n: Int, a: A): Unit
33-
34-
// XXX TODO: remove
35-
// def +=:(a: A): this.type = { insertAt(0, a); this }
36-
37-
def iterator: Iterator[A] = Iterator.range(0,length).map(apply)
38-
39-
// XXX TODO
40-
def prepend(elem: A): BufferWrapper.this.type = ???
41-
42-
def insert(idx: Int, elem: A): Unit = ???
43-
44-
def insertAll(idx: Int, elems: IterableOnce[A]): Unit = ???
45-
46-
def remove(idx: Int, count: Int): Unit = ???
36+
override def remove(idx: Int, count: Int): Unit = {
37+
require(count >= 0)
38+
var n = 0
39+
while (n < count) {
40+
remove(idx + n)
41+
n += 1
42+
}
43+
}
4744

48-
def patchInPlace(from: Int, patch: collection.Seq[A], replaced: Int): BufferWrapper.this.type = ???
45+
override def patchInPlace(from: Int, patch: Seq[A], replaced: Int): this.type = {
46+
if (replaced > 0) {
47+
remove(from, replaced)
48+
}
49+
if (patch.nonEmpty) {
50+
insertAll(from, patch)
51+
}
52+
this
53+
}
4954
}

src/main/scala/scala/swing/Container.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ object Container {
3030
UIElement.cachedWrapper[Component](c)
3131
}
3232

33-
protected def insertAt(n: Int, c: Component): Unit = peer.add(c.peer, n)
33+
override def insert(n: Int, c: Component): Unit = peer.add(c.peer, n)
3434

3535
override def addOne(c: Component): this.type = { peer.add(c.peer) ; this }
3636

src/main/scala/scala/swing/TabbedPane.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ class TabbedPane extends Component with Publisher {
8585
//for(i <- n to length) apply(i)._index -= 1
8686
t
8787
}
88-
protected def insertAt(n: Int, t: Page): Unit = {
88+
89+
override def insert(n: Int, t: Page): Unit = {
8990
//for(i <- n to length) apply(i)._index += 1
9091
t.parent = TabbedPane.this
9192
peer.insertTab(t.title, null, t.content.peer, t.tip, n)

0 commit comments

Comments
 (0)