Skip to content

Commit 5aca152

Browse files
committed
Fix some deprecated collections
- like Stream -> LazyList - JavaConverters -> CollectionConverters - some () added to method invocations - replace triple quoted unicode characters with regular doublequote - alternative ArrayBuffer1.reduceToSize1 function for 2.12 and 2.13 - replace contents, elementChildren, and children sequences with child(index) and numChildren function - update unordered sequence tests so it's easier to tell if something is broken DAFFODIL-2152
1 parent 2eb3fe8 commit 5aca152

File tree

33 files changed

+195
-137
lines changed

33 files changed

+195
-137
lines changed

daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/SequenceGrammarMixin.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717

1818
package org.apache.daffodil.core.grammar
19+
import scala.collection.compat.immutable.LazyList
20+
1921
import org.apache.daffodil.core.dsom._
2022
import org.apache.daffodil.core.grammar.primitives.OrderedSequence
2123
import org.apache.daffodil.core.grammar.primitives.UnorderedSequence
@@ -60,7 +62,7 @@ trait SequenceGrammarMixin extends GrammarMixin with SequenceTermRuntime1Mixin {
6062
}
6163

6264
private lazy val seqChildren = LV(Symbol("seqChildren")) {
63-
(groupMembers.zip(Stream.from(1))).map { case (gm, i) =>
65+
(groupMembers.zip(LazyList.from(1))).map { case (gm, i) =>
6466
sequenceChild(gm, i)
6567
}
6668
}.value

daffodil-core/src/main/scala/org/apache/daffodil/core/util/TestUtils.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import java.io.InputStream
2222
import java.nio.channels.Channels
2323
import java.nio.channels.ReadableByteChannel
2424
import java.nio.channels.WritableByteChannel
25+
import scala.collection.compat.immutable.LazyList
2526
import scala.collection.mutable.ArrayBuffer
2627
import scala.util.Try
2728
import scala.xml._
@@ -376,13 +377,13 @@ object StreamParser {
376377
}
377378
}
378379

379-
def doStreamTest(schema: Node, data: String): Stream[Result] = {
380+
def doStreamTest(schema: Node, data: String): LazyList[Result] = {
380381
val mp = new StreamParser(schema)
381382
val is: InputStream = new ByteArrayInputStream(data.getBytes("ascii"))
382383
mp.setInputStream(is)
383384
var r: StreamParser.Result = null
384385
val results = new ArrayBuffer[Result]
385-
val resStream = Stream.continually(mp.parse).takeWhile(r => !r.isProcessingError)
386+
val resStream = LazyList.continually(mp.parse).takeWhile(r => !r.isProcessingError)
386387
resStream
387388
}
388389
}

daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestSimpleTypeUnions.scala

+12-12
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class TestSimpleTypeUnions {
103103
.asInstanceOf[PState]
104104
.infoset
105105
.asInstanceOf[DIDocument]
106-
.contents(0)
106+
.child(0)
107107
.asInstanceOf[DISimple]
108108
val umstrd = i.unionMemberRuntimeData.get
109109
assertEquals("int1Type", umstrd.diagnosticDebugName)
@@ -118,7 +118,7 @@ class TestSimpleTypeUnions {
118118
.asInstanceOf[PState]
119119
.infoset
120120
.asInstanceOf[DIDocument]
121-
.contents(0)
121+
.child(0)
122122
.asInstanceOf[DISimple]
123123
val umstrd = i.unionMemberRuntimeData.get
124124
assertEquals("int2Type", umstrd.diagnosticDebugName)
@@ -133,7 +133,7 @@ class TestSimpleTypeUnions {
133133
.asInstanceOf[PState]
134134
.infoset
135135
.asInstanceOf[DIDocument]
136-
.contents(0)
136+
.child(0)
137137
.asInstanceOf[DISimple]
138138
val Some(dv: java.lang.Integer) = Some(i.dataValue.getInt)
139139
assertEquals(3, dv.intValue())
@@ -226,7 +226,7 @@ class TestSimpleTypeUnions {
226226
.asInstanceOf[PState]
227227
.infoset
228228
.asInstanceOf[DIDocument]
229-
.contents(0)
229+
.child(0)
230230
.asInstanceOf[DISimple]
231231
val Some(dv: java.lang.Integer) = Some(i.dataValue.getInt)
232232
assertEquals(3, dv.intValue())
@@ -256,7 +256,7 @@ class TestSimpleTypeUnions {
256256
.asInstanceOf[PState]
257257
.infoset
258258
.asInstanceOf[DIDocument]
259-
.contents(0)
259+
.child(0)
260260
.asInstanceOf[DISimple]
261261
val umstrd = i.unionMemberRuntimeData.get
262262
assertEquals("int12Type", umstrd.diagnosticDebugName)
@@ -271,7 +271,7 @@ class TestSimpleTypeUnions {
271271
.asInstanceOf[PState]
272272
.infoset
273273
.asInstanceOf[DIDocument]
274-
.contents(0)
274+
.child(0)
275275
.asInstanceOf[DISimple]
276276
val umstrd = i.unionMemberRuntimeData.get
277277
assertEquals("int12Type", umstrd.diagnosticDebugName)
@@ -286,7 +286,7 @@ class TestSimpleTypeUnions {
286286
.asInstanceOf[PState]
287287
.infoset
288288
.asInstanceOf[DIDocument]
289-
.contents(0)
289+
.child(0)
290290
.asInstanceOf[DISimple]
291291
val umstrd = i.unionMemberRuntimeData.get
292292
assertEquals(
@@ -351,7 +351,7 @@ class TestSimpleTypeUnions {
351351
.asInstanceOf[PState]
352352
.infoset
353353
.asInstanceOf[DIDocument]
354-
.contents(0)
354+
.child(0)
355355
.asInstanceOf[DISimple]
356356
val umstrd = i.unionMemberRuntimeData.get
357357
assertEquals("ex:foo3or4bar", umstrd.diagnosticDebugName)
@@ -366,7 +366,7 @@ class TestSimpleTypeUnions {
366366
.asInstanceOf[PState]
367367
.infoset
368368
.asInstanceOf[DIDocument]
369-
.contents(0)
369+
.child(0)
370370
.asInstanceOf[DISimple]
371371
val umstrd = i.unionMemberRuntimeData.get
372372
assertEquals("foo1or2bar", umstrd.diagnosticDebugName)
@@ -381,7 +381,7 @@ class TestSimpleTypeUnions {
381381
.asInstanceOf[PState]
382382
.infoset
383383
.asInstanceOf[DIDocument]
384-
.contents(0)
384+
.child(0)
385385
.asInstanceOf[DISimple]
386386
val umstrd = i.unionMemberRuntimeData.get
387387
assertEquals("foo1or2bar", umstrd.diagnosticDebugName)
@@ -396,7 +396,7 @@ class TestSimpleTypeUnions {
396396
.asInstanceOf[PState]
397397
.infoset
398398
.asInstanceOf[DIDocument]
399-
.contents(0)
399+
.child(0)
400400
.asInstanceOf[DISimple]
401401
val Some(dv: String) = Some(i.dataValue.getString)
402402
assertEquals("foo4bar", dv)
@@ -430,7 +430,7 @@ class TestSimpleTypeUnions {
430430
.asInstanceOf[PState]
431431
.infoset
432432
.asInstanceOf[DIDocument]
433-
.contents(0)
433+
.child(0)
434434
.asInstanceOf[DISimple]
435435
val Some(dv: String) = Some(i.dataValue.getString)
436436
assertEquals("notfoo1bar", dv)

daffodil-core/src/test/scala/org/apache/daffodil/core/infoset/TestInfoset.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ object TestInfoset {
7070
val infosetRootNode = {
7171
val ustate = unparseResult.resultState.asInstanceOf[UStateMain]
7272
val diDocument: DIDocument = ustate.documentElement
73-
val rootElement = diDocument.contents(0).asInstanceOf[DIElement]
73+
val rootElement = diDocument.child(0).asInstanceOf[DIElement]
7474
Assert.invariant(rootElement ne null)
7575
rootElement
7676
}
@@ -440,7 +440,7 @@ class TestInfoset1 {
440440
}><enum>EQUAL_TO_OR_&lt;_0.0001_SQUARE_DATA_MILES</enum></root>
441441

442442
val (infoset: DIComplex, _, tunable) = testInfoset(testSchema, xmlInfoset)
443-
val enumElt: DISimple = infoset.children.head.asInstanceOf[DISimple]
443+
val enumElt: DISimple = infoset.child(0).asInstanceOf[DISimple]
444444
val value = enumElt.dataValueAsString
445445
assertEquals("EQUAL_TO_OR_<_0.0001_SQUARE_DATA_MILES", value)
446446

daffodil-core/src/test/scala/org/apache/daffodil/core/infoset/TestInfosetCursorFromReader2.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.apache.daffodil.core.infoset
1919

20-
import scala.collection.immutable.Stream.consWrapper
20+
import scala.collection.compat.immutable.LazyList
2121

2222
import org.apache.daffodil.core.compiler.Compiler
2323
import org.apache.daffodil.lib.Implicits._
@@ -60,7 +60,7 @@ class TestInfosetInputterFromReader2 {
6060
}
6161
val rootERD = u.ssrd.elementRuntimeData
6262

63-
def foos: Stream[String] = "<foo>Hello</foo>" #:: foos
63+
def foos: LazyList[String] = "<foo>Hello</foo>" #:: foos
6464
val ex = XMLUtils.EXAMPLE_NAMESPACE.toString
6565
def strings =
6666
(("<bar xmlns='" + ex + "' >") #:: foos.take(size))
@@ -72,11 +72,11 @@ class TestInfosetInputterFromReader2 {
7272
(ic, rootERD, inputter)
7373
}
7474

75-
class StreamInputStream(private var strings: Stream[String]) extends java.io.InputStream {
75+
class StreamInputStream(private var strings: LazyList[String]) extends java.io.InputStream {
7676

7777
private var bytes = {
7878
val ss = strings.flatMap { _.getBytes() } ++ "</bar>".getBytes().toStream
79-
strings = Nil.toStream
79+
strings = Nil.to(LazyList)
8080
ss
8181
}
8282

@@ -89,7 +89,7 @@ class TestInfosetInputterFromReader2 {
8989
}
9090
}
9191

92-
override def close(): Unit = { bytes = Nil.toStream }
92+
override def close(): Unit = { bytes = Nil.to(LazyList) }
9393
}
9494

9595
@Test def testStreamingBehavior1(): Unit = {

daffodil-io/src/main/scala/org/apache/daffodil/io/RegexLimitingInputStream.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import java.nio.charset.Charset
2323
import java.nio.charset.StandardCharsets
2424
import java.util.Scanner
2525
import java.util.regex.Pattern
26+
import scala.collection.compat.immutable.LazyList
2627

2728
import org.apache.daffodil.lib.exceptions.Assert
2829

@@ -134,8 +135,8 @@ class RegexLimitingInputStream(
134135
* consider that the overhead is once per chunk, so honestly the
135136
* regex match is of more concern.
136137
*/
137-
private def chunks: Stream[String] = {
138-
if (noMoreChunks) Stream()
138+
private def chunks: LazyList[String] = {
139+
if (noMoreChunks) LazyList()
139140
else {
140141
in.mark(lookAheadMax)
141142
//
@@ -168,7 +169,7 @@ class RegexLimitingInputStream(
168169
if (delimMatchLength > 0)
169170
noMoreChunks = true
170171
if (beforeMatchString.isEmpty)
171-
Stream()
172+
LazyList()
172173
else
173174
// lazy list construction. chunks will not be recursively evaluated unless demanded
174175
beforeMatchString #:: chunks

daffodil-io/src/main/scala/org/apache/daffodil/io/StringDataInputStreamForUnparse.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ final class StringDataInputStreamForUnparse extends DataInputStreamImplMixin {
8888
override def setBitLimit0b(bitLimit0b: MaybeULong): Boolean = doNotUse
8989
override def setDebugging(setting: Boolean): Unit = doNotUse
9090
override def isDefinedForLength(length: Long): Boolean = doNotUse
91-
override def hasData: Boolean = doNotUse
91+
override def hasData(): Boolean = doNotUse
9292
override def skip(nBits: Long, finfo: FormatInfo): Boolean = doNotUse
9393
override def resetBitLimit0b(savedBitLimit0b: MaybeULong): Unit = doNotUse
9494
// $COVERAGE-ON$

daffodil-io/src/main/scala/org/apache/daffodil/io/processors/charset/BitsCharset.scala

+6-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import java.nio.charset.CoderResult
2424
import java.nio.charset.CodingErrorAction
2525
import java.nio.charset.{ Charset => JavaCharset }
2626
import java.nio.charset.{ CharsetEncoder => JavaCharsetEncoder }
27-
import scala.collection.convert.ImplicitConversions.`collection AsScalaIterable`
27+
import scala.jdk.CollectionConverters._
2828

2929
import org.apache.daffodil.lib.exceptions.Assert
3030
import org.apache.daffodil.lib.schema.annotation.props.gen.BitOrder
@@ -153,9 +153,10 @@ trait BitsCharsetJava extends BitsCharset {
153153
}
154154

155155
private lazy val hasNameOrAliasContainingEBCDIC = {
156-
val allCharsetNames = (javaCharset.aliases().toSeq :+ name :+ javaCharset.name()).map {
157-
_.toUpperCase
158-
}
156+
val allCharsetNames =
157+
(javaCharset.aliases().asScala.toSeq :+ name :+ javaCharset.name()).map {
158+
_.toUpperCase
159+
}
159160
val res = allCharsetNames.exists(_.contains("EBCDIC"))
160161
res
161162
}
@@ -227,7 +228,7 @@ final class BitsCharsetWrappingJavaCharsetEncoder(
227228
isReset = true
228229
this
229230
}
230-
def isMandatoryAlignmentNeeded = isReset
231+
def isMandatoryAlignmentNeeded() = isReset
231232
def malformedInputAction() = enc.malformedInputAction()
232233
def onMalformedInput(action: CodingErrorAction) = {
233234
Assert.usage(isReset)

daffodil-io/src/main/scala/org/apache/daffodil/io/processors/charset/X_DFDL_MIL_STD.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ object BitsCharset6BitDFI264DUI001 extends BitsCharsetNonByteSize {
3636
override lazy val name = "X-DFDL-6-BIT-DFI-264-DUI-001"
3737
override lazy val bitWidthOfACodeUnit = 6
3838
override lazy val decodeString =
39-
""" 123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD0"""
39+
" 123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD0"
4040
override lazy val replacementCharCode = 0x0
4141
override lazy val requiredBitOrder = BitOrder.LeastSignificantBitFirst
4242
}
@@ -47,7 +47,7 @@ final class BitsCharset6BitDFI264DUI001Definition
4747
sealed abstract class BitsCharset6BitDFI311DUI002Base extends BitsCharsetNonByteSize {
4848
override lazy val bitWidthOfACodeUnit = 6
4949
override lazy val decodeString =
50-
"""\u00A0ABCDEFGHIJKLMNOPQRSTUVWXYZ\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD \uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD0123456789\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD"""
50+
"\u00A0ABCDEFGHIJKLMNOPQRSTUVWXYZ\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD \uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD0123456789\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD"
5151
override lazy val replacementCharCode = 0x0
5252
}
5353

@@ -126,7 +126,7 @@ object BitsCharset5BitDFI1661DUI001 extends BitsCharsetNonByteSize {
126126
override lazy val name = "X-DFDL-5-BIT-DFI-1661-DUI-001"
127127
override lazy val bitWidthOfACodeUnit = 5
128128
override lazy val decodeString =
129-
"""\u00A0ABCDEFGHIJKLMNOPQRSTUVWXYZ\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD"""
129+
"\u00A0ABCDEFGHIJKLMNOPQRSTUVWXYZ\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD"
130130
override lazy val replacementCharCode = 0x0
131131
override lazy val requiredBitOrder = BitOrder.LeastSignificantBitFirst
132132
}

daffodil-io/src/test/scala/org/apache/daffodil/io/TestDirectOrBufferedDataOutputStream.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class TestDirectOrBufferedDataOutputStream {
3434
val is = new ByteArrayInputStream(baos.getBuf)
3535
val ir = new InputStreamReader(is, "ascii")
3636
val line = IOUtils.toString(ir)
37-
val res = line.replace("""\u0000""", "")
37+
val res = line.replace("\u0000", "")
3838
res
3939
}
4040

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.daffodil.lib.util
19+
20+
import java.util
21+
import scala.collection.mutable.ArrayBuffer
22+
23+
/**
24+
* Compatibility ArrayBuffer class for 2.12 and 2.13 since reduceToSize
25+
* has been removed in 2.13. This allows us to maintain the same
26+
* functionality as 2.12 while upgraded to 2.13
27+
*/
28+
class ArrayBuffer1[T](initialSize: Int = 16) extends ArrayBuffer[T] {
29+
// Preallocate space to avoid frequent resizing
30+
this.sizeHint(initialSize)
31+
32+
def reduceToSize1(sz: Int): Unit = {
33+
if (sz >= 0 && sz <= size0) {
34+
// to ensure things are not left un-garbage collected
35+
util.Arrays.fill(array, sz, size0, null)
36+
size0 = sz
37+
} else
38+
throw new IndexOutOfBoundsException(
39+
"Invalid size: Must be between 0 and the current size of the buffer."
40+
)
41+
}
42+
}
43+
44+
object ArrayBuffer1 extends ArrayBuffer {
45+
def apply[T](ab: ArrayBuffer[T]): ArrayBuffer1[T] = {
46+
val s = ab.length
47+
val arr = new ArrayBuffer1[T](s)
48+
arr ++= ab
49+
arr
50+
}
51+
}

daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/debugger/InteractiveDebugger.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,7 @@ class InteractiveDebugger(
18071807
}
18081808

18091809
node match {
1810-
case d: DIDocument if d.contents.size == 0 => {
1810+
case d: DIDocument if d.numChildren == 0 => {
18111811
debugPrintln("No Infoset", " ")
18121812
}
18131813
case _ => {

0 commit comments

Comments
 (0)