From 8ed3f81e695af5d3a8e3ad41ecf3c8ed1ac41947 Mon Sep 17 00:00:00 2001 From: Alexander Slesarenko Date: Tue, 22 Aug 2023 18:45:10 +0200 Subject: [PATCH] minimize-modules: use fully qualified java.util. --- .../scala/scalan/util/CollectionUtil.scala | 20 +++++++++---------- .../main/scala/sigma/CollsOverArrays.scala | 4 +--- .../org/ergoplatform/ErgoBoxCandidate.scala | 2 +- .../main/scala/org/ergoplatform/Input.scala | 4 ++-- .../ergoplatform/validation/RuleStatus.scala | 4 ++-- .../scala/sigmastate/crypto/GF2_192.scala | 2 +- .../sigmastate/crypto/GF2_192_Poly.scala | 4 ++-- .../sigmastate/interpreter/Interpreter.scala | 2 +- .../sigmastate/interpreter/ProverResult.scala | 4 ++-- .../serialization/ErgoTreeSerializer.scala | 2 +- .../main/scala/sigmastate/utils/Helpers.scala | 20 +++++++++---------- .../scala/special/sigma/SigmaDslTesting.scala | 2 +- .../scala/org/ergoplatform/sdk/ErgoId.scala | 4 ++-- .../org/ergoplatform/sdk/SecretString.scala | 4 ++-- .../org/ergoplatform/sdk/Transactions.scala | 2 +- .../wallet/secrets/ExtendedPublicKey.scala | 8 ++++---- .../wallet/secrets/ExtendedSecretKey.scala | 10 +++++----- 17 files changed, 47 insertions(+), 51 deletions(-) diff --git a/common/shared/src/main/scala/scalan/util/CollectionUtil.scala b/common/shared/src/main/scala/scalan/util/CollectionUtil.scala index 0ee4030e2c..2eefc8b956 100644 --- a/common/shared/src/main/scala/scalan/util/CollectionUtil.scala +++ b/common/shared/src/main/scala/scalan/util/CollectionUtil.scala @@ -1,7 +1,5 @@ package scalan.util -import java.util - import scala.collection.{Seq, mutable, GenIterable} import scala.collection.mutable.{HashMap, ArrayBuffer} import scala.reflect.ClassTag @@ -52,15 +50,15 @@ object CollectionUtil { * @param arr the input array for which the deep hash code is to be calculated */ def deepHashCode[T](arr: Array[T]): Int = arr match { - case arr: Array[AnyRef] => util.Arrays.deepHashCode(arr) - case arr: Array[Byte] => util.Arrays.hashCode(arr) - case arr: Array[Short] => util.Arrays.hashCode(arr) - case arr: Array[Int] => util.Arrays.hashCode(arr) - case arr: Array[Long] => util.Arrays.hashCode(arr) - case arr: Array[Char] => util.Arrays.hashCode(arr) - case arr: Array[Float] => util.Arrays.hashCode(arr) - case arr: Array[Double] => util.Arrays.hashCode(arr) - case arr: Array[Boolean] => util.Arrays.hashCode(arr) + case arr: Array[AnyRef] => java.util.Arrays.deepHashCode(arr) + case arr: Array[Byte] => java.util.Arrays.hashCode(arr) + case arr: Array[Short] => java.util.Arrays.hashCode(arr) + case arr: Array[Int] => java.util.Arrays.hashCode(arr) + case arr: Array[Long] => java.util.Arrays.hashCode(arr) + case arr: Array[Char] => java.util.Arrays.hashCode(arr) + case arr: Array[Float] => java.util.Arrays.hashCode(arr) + case arr: Array[Double] => java.util.Arrays.hashCode(arr) + case arr: Array[Boolean] => java.util.Arrays.hashCode(arr) } /** Group the given sequence of pairs by first values as keys. diff --git a/common/shared/src/main/scala/sigma/CollsOverArrays.scala b/common/shared/src/main/scala/sigma/CollsOverArrays.scala index 9a756f3370..9e8b0f810d 100644 --- a/common/shared/src/main/scala/sigma/CollsOverArrays.scala +++ b/common/shared/src/main/scala/sigma/CollsOverArrays.scala @@ -1,6 +1,5 @@ package sigma -import java.util import scalan._ // required import scalan.util.CollectionUtil import scalan.RType @@ -8,7 +7,6 @@ import debox.Buffer import scalan.RType._ import sigma.util.{MaxArrayLength, safeConcatArrays_v5} import debox.cfor -import sigma.VersionContext class CollOverArray[@specialized A](val toArray: Array[A], val builder: CollBuilder) (implicit tA: RType[A]) extends Coll[A] { @@ -398,7 +396,7 @@ class PairOfCols[@specialized L, @specialized R](val ls: Coll[L], val rs: Coll[R } override def unionSet(that: Coll[(L, R)]): Coll[(L, R)] = { - val set = new util.HashSet[(L,R)](32) + val set = new java.util.HashSet[(L,R)](32) implicit val ctL = ls.tItem.classTag implicit val ctR = rs.tItem.classTag val resL = Buffer.empty[L] diff --git a/interpreter/shared/src/main/scala/org/ergoplatform/ErgoBoxCandidate.scala b/interpreter/shared/src/main/scala/org/ergoplatform/ErgoBoxCandidate.scala index e10f7907e1..13ae47b2e2 100644 --- a/interpreter/shared/src/main/scala/org/ergoplatform/ErgoBoxCandidate.scala +++ b/interpreter/shared/src/main/scala/org/ergoplatform/ErgoBoxCandidate.scala @@ -85,7 +85,7 @@ class ErgoBoxCandidate(val value: Long, override def equals(arg: Any): Boolean = { arg match { - case x: ErgoBoxCandidate => util.Arrays.equals(bytesWithNoRef, x.bytesWithNoRef) + case x: ErgoBoxCandidate => java.util.Arrays.equals(bytesWithNoRef, x.bytesWithNoRef) case _ => false } } diff --git a/interpreter/shared/src/main/scala/org/ergoplatform/Input.scala b/interpreter/shared/src/main/scala/org/ergoplatform/Input.scala index d8bd8c6d1d..e0b4830797 100644 --- a/interpreter/shared/src/main/scala/org/ergoplatform/Input.scala +++ b/interpreter/shared/src/main/scala/org/ergoplatform/Input.scala @@ -18,7 +18,7 @@ case class DataInput(boxId: BoxId) { override def toString: String = s"DataInput(${ErgoAlgos.encode(boxId)})" override def equals(obj: Any): Boolean = obj match { - case x: DataInput => util.Arrays.equals(boxId, x.boxId) + case x: DataInput => java.util.Arrays.equals(boxId, x.boxId) case _ => false } @@ -39,7 +39,7 @@ class UnsignedInput(val boxId: BoxId, val extension: ContextExtension) { // todo check whether it is correct to compare inputs (Input use the same equals) by boxId only? override def equals(obj: Any): Boolean = obj match { - case x: UnsignedInput => util.Arrays.equals(boxId, x.boxId) + case x: UnsignedInput => java.util.Arrays.equals(boxId, x.boxId) case _ => false } diff --git a/interpreter/shared/src/main/scala/org/ergoplatform/validation/RuleStatus.scala b/interpreter/shared/src/main/scala/org/ergoplatform/validation/RuleStatus.scala index f40a916701..789016abfb 100644 --- a/interpreter/shared/src/main/scala/org/ergoplatform/validation/RuleStatus.scala +++ b/interpreter/shared/src/main/scala/org/ergoplatform/validation/RuleStatus.scala @@ -45,11 +45,11 @@ case class ReplacedRule(newRuleId: Short) extends RuleStatus { case class ChangedRule(newValue: Array[Byte]) extends RuleStatus { val statusCode: Byte = RuleStatus.ChangedRuleCode - override def hashCode(): Int = util.Arrays.hashCode(newValue) + override def hashCode(): Int = java.util.Arrays.hashCode(newValue) override def canEqual(that: Any): Boolean = that.isInstanceOf[ChangedRule] override def equals(obj: Any): Boolean = (this eq obj.asInstanceOf[AnyRef]) || (obj match { - case that: ChangedRule => util.Arrays.equals(newValue, that.newValue) + case that: ChangedRule => java.util.Arrays.equals(newValue, that.newValue) }) } diff --git a/interpreter/shared/src/main/scala/sigmastate/crypto/GF2_192.scala b/interpreter/shared/src/main/scala/sigmastate/crypto/GF2_192.scala index 36e8343e2b..bb0ad60a84 100644 --- a/interpreter/shared/src/main/scala/sigmastate/crypto/GF2_192.scala +++ b/interpreter/shared/src/main/scala/sigmastate/crypto/GF2_192.scala @@ -113,7 +113,7 @@ class GF2_192 extends AnyRef { } } - override def hashCode = util.Arrays.hashCode(word) + override def hashCode = java.util.Arrays.hashCode(word) /** * diff --git a/interpreter/shared/src/main/scala/sigmastate/crypto/GF2_192_Poly.scala b/interpreter/shared/src/main/scala/sigmastate/crypto/GF2_192_Poly.scala index 344305a157..a9212fe565 100644 --- a/interpreter/shared/src/main/scala/sigmastate/crypto/GF2_192_Poly.scala +++ b/interpreter/shared/src/main/scala/sigmastate/crypto/GF2_192_Poly.scala @@ -164,14 +164,14 @@ class GF2_192_Poly { def coeff0Bytes: Array[Byte] = c(0).toByteArray override def hashCode: Int = { - 31 * util.Arrays.deepHashCode(c.asInstanceOf[Array[AnyRef]]) + deg + 31 * java.util.Arrays.deepHashCode(c.asInstanceOf[Array[AnyRef]]) + deg } override def equals(obj: Any): Boolean = { if (this eq obj.asInstanceOf[AnyRef]) return true obj match { case that: GF2_192_Poly => - util.Arrays.deepEquals(c.asInstanceOf[Array[AnyRef]], that.c.asInstanceOf[Array[AnyRef]]) && + java.util.Arrays.deepEquals(c.asInstanceOf[Array[AnyRef]], that.c.asInstanceOf[Array[AnyRef]]) && deg == that.deg case _ => false } diff --git a/interpreter/shared/src/main/scala/sigmastate/interpreter/Interpreter.scala b/interpreter/shared/src/main/scala/sigmastate/interpreter/Interpreter.scala index 45db609448..6a0142a119 100644 --- a/interpreter/shared/src/main/scala/sigmastate/interpreter/Interpreter.scala +++ b/interpreter/shared/src/main/scala/sigmastate/interpreter/Interpreter.scala @@ -385,7 +385,7 @@ trait Interpreter { * (and, if applicable, the associated data). Reject otherwise. */ val expectedChallenge = CryptoFunctions.hashFn(bytes) - util.Arrays.equals(newRoot.challenge.toArray, expectedChallenge) + java.util.Arrays.equals(newRoot.challenge.toArray, expectedChallenge) } /** diff --git a/interpreter/shared/src/main/scala/sigmastate/interpreter/ProverResult.scala b/interpreter/shared/src/main/scala/sigmastate/interpreter/ProverResult.scala index a6824a1570..45d6159d8c 100644 --- a/interpreter/shared/src/main/scala/sigmastate/interpreter/ProverResult.scala +++ b/interpreter/shared/src/main/scala/sigmastate/interpreter/ProverResult.scala @@ -13,12 +13,12 @@ import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} * @param extension - user-defined variables to be put into context */ class ProverResult(val proof: Array[Byte], val extension: ContextExtension) { - override def hashCode(): Int = util.Arrays.hashCode(proof) * 31 + extension.hashCode() + override def hashCode(): Int = java.util.Arrays.hashCode(proof) * 31 + extension.hashCode() override def equals(obj: scala.Any): Boolean = (this eq obj.asInstanceOf[AnyRef]) || (obj match { case obj: ProverResult => - util.Arrays.equals(proof, obj.proof) && extension == obj.extension + java.util.Arrays.equals(proof, obj.proof) && extension == obj.extension case _ => false }) diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/ErgoTreeSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/ErgoTreeSerializer.scala index 735b5f0595..f8c5221945 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/ErgoTreeSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/ErgoTreeSerializer.scala @@ -275,7 +275,7 @@ class ErgoTreeSerializer { // allocate array of back references: forall i: positionsBackref(i) is index in `positions` val positionsBackref = safeNewArray[Int](positionsRange) // mark all positions are not assigned - util.Arrays.fill(positionsBackref, -1) + java.util.Arrays.fill(positionsBackref, -1) cfor(0)(_ < positions.length, _ + 1) { iPos => val pos = positions(iPos) diff --git a/interpreter/shared/src/main/scala/sigmastate/utils/Helpers.scala b/interpreter/shared/src/main/scala/sigmastate/utils/Helpers.scala index 07f9f8dd30..f1c72a0475 100644 --- a/interpreter/shared/src/main/scala/sigmastate/utils/Helpers.scala +++ b/interpreter/shared/src/main/scala/sigmastate/utils/Helpers.scala @@ -80,15 +80,15 @@ object Helpers { } def deepHashCode[T](arr: Array[T]): Int = arr match { - case arr: Array[AnyRef] => util.Arrays.deepHashCode(arr) - case arr: Array[Byte] => util.Arrays.hashCode(arr) - case arr: Array[Short] => util.Arrays.hashCode(arr) - case arr: Array[Int] => util.Arrays.hashCode(arr) - case arr: Array[Long] => util.Arrays.hashCode(arr) - case arr: Array[Char] => util.Arrays.hashCode(arr) - case arr: Array[Float] => util.Arrays.hashCode(arr) - case arr: Array[Double] => util.Arrays.hashCode(arr) - case arr: Array[Boolean] => util.Arrays.hashCode(arr) + case arr: Array[AnyRef] => java.util.Arrays.deepHashCode(arr) + case arr: Array[Byte] => java.util.Arrays.hashCode(arr) + case arr: Array[Short] => java.util.Arrays.hashCode(arr) + case arr: Array[Int] => java.util.Arrays.hashCode(arr) + case arr: Array[Long] => java.util.Arrays.hashCode(arr) + case arr: Array[Char] => java.util.Arrays.hashCode(arr) + case arr: Array[Float] => java.util.Arrays.hashCode(arr) + case arr: Array[Double] => java.util.Arrays.hashCode(arr) + case arr: Array[Boolean] => java.util.Arrays.hashCode(arr) } /** Optimized hashCode for array of bytes when it represents some hash thus it have @@ -97,7 +97,7 @@ object Helpers { */ @inline final def safeIdHashCode(id: Array[Byte]): Int = if (id != null && id.length >= 4) Ints.fromBytes(id(0), id(1), id(2), id(3)) - else util.Arrays.hashCode(id) + else java.util.Arrays.hashCode(id) implicit class TryOps[+A](val source: Try[A]) extends AnyVal { def fold[B](onError: Throwable => B, onSuccess: A => B) = source match { diff --git a/sc/shared/src/test/scala/special/sigma/SigmaDslTesting.scala b/sc/shared/src/test/scala/special/sigma/SigmaDslTesting.scala index 16818c25ea..81ec1ced50 100644 --- a/sc/shared/src/test/scala/special/sigma/SigmaDslTesting.scala +++ b/sc/shared/src/test/scala/special/sigma/SigmaDslTesting.scala @@ -275,7 +275,7 @@ class SigmaDslTesting extends AnyPropSpec val txOutputCandidates = ctx.outputs.toArray.map(SigmaDsl.toErgoBox) val tx = new ErgoLikeTransaction( txInputs, txDataInputs, txOutputCandidates.toIndexedSeq) - val selfIndex = boxesToSpend.indexWhere(b => util.Arrays.equals(b.id, ctx.selfBox.id.toArray)) + val selfIndex = boxesToSpend.indexWhere(b => java.util.Arrays.equals(b.id, ctx.selfBox.id.toArray)) val extension = ContextExtension( values = ctx.vars.toArray.zipWithIndex.collect { diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/ErgoId.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/ErgoId.scala index 088b16fe77..7d56b05295 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/ErgoId.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/ErgoId.scala @@ -19,14 +19,14 @@ class ErgoId(val _idBytes: Array[Byte]) { override def hashCode = if (_idBytes != null && _idBytes.length >= 4) Ints.fromByteArray(_idBytes) - else util.Arrays.hashCode(_idBytes) + else java.util.Arrays.hashCode(_idBytes) override def equals(obj: Any): Boolean = { if (obj == null) return false if (this eq obj.asInstanceOf[AnyRef]) return true obj match { case that: ErgoId => - util.Arrays.equals(this._idBytes, that._idBytes) + java.util.Arrays.equals(this._idBytes, that._idBytes) case _ => false } } diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/SecretString.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/SecretString.scala index 4cf8e8b2c3..83ff2e0a10 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/SecretString.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/SecretString.scala @@ -67,13 +67,13 @@ final class SecretString private[sdk](val _data: Array[Char]) { * Erases secret characters stored in this instance so that they are no longer reside in memory. */ def erase(): Unit = { - util.Arrays.fill(_data, ' ') + java.util.Arrays.fill(_data, ' ') _erased = true } override def hashCode(): Int = { checkErased() - util.Arrays.hashCode(_data) + java.util.Arrays.hashCode(_data) } /** this is adapted version of java.lang.String */ diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/Transactions.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/Transactions.scala index 275814a983..8848e73c42 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/Transactions.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/Transactions.scala @@ -36,7 +36,7 @@ case class UnreducedTransaction( private def checkSameIds( xsName: String, xs: Seq[Array[Byte]], ysName: String, ys: Seq[Array[Byte]], msg: => String) = { - require(xs.zip(ys).forall { case (id1, id2) => util.Arrays.equals(id1, id2) }, { + require(xs.zip(ys).forall { case (id1, id2) => java.util.Arrays.equals(id1, id2) }, { val xsOnly = xs.diff(ys) val ysOnly = ys.diff(xs) s"""$msg: diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedPublicKey.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedPublicKey.scala index cdc7458b75..10536b20b0 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedPublicKey.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedPublicKey.scala @@ -29,15 +29,15 @@ final class ExtendedPublicKey(/*private[secrets] */val keyBytes: Array[Byte], override def equals(obj: Any): Boolean = (this eq obj.asInstanceOf[AnyRef]) || (obj match { case that: ExtendedPublicKey => - util.Arrays.equals(that.keyBytes, this.keyBytes) && - util.Arrays.equals(that.chainCode, this.chainCode) && + java.util.Arrays.equals(that.keyBytes, this.keyBytes) && + java.util.Arrays.equals(that.chainCode, this.chainCode) && that.path == this.path case _ => false }) override def hashCode(): Int = { - var h = util.Arrays.hashCode(keyBytes) - h = 31 * h + util.Arrays.hashCode(chainCode) + var h = java.util.Arrays.hashCode(keyBytes) + h = 31 * h + java.util.Arrays.hashCode(chainCode) h = 31 * h + path.hashCode() h } diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedSecretKey.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedSecretKey.scala index 2842658e66..96802217df 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedSecretKey.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedSecretKey.scala @@ -34,19 +34,19 @@ final class ExtendedSecretKey(/*private[secrets]*/ val keyBytes: Array[Byte], def isErased: Boolean = keyBytes.forall(_ == 0x00) - def zeroSecret(): Unit = util.Arrays.fill(keyBytes, 0: Byte) + def zeroSecret(): Unit = java.util.Arrays.fill(keyBytes, 0: Byte) override def equals(obj: Any): Boolean = (this eq obj.asInstanceOf[AnyRef]) || (obj match { case that: ExtendedSecretKey => - util.Arrays.equals(that.keyBytes, this.keyBytes) && - util.Arrays.equals(that.chainCode, this.chainCode) && + java.util.Arrays.equals(that.keyBytes, this.keyBytes) && + java.util.Arrays.equals(that.chainCode, this.chainCode) && that.path == this.path case _ => false }) override def hashCode(): Int = { - var h = util.Arrays.hashCode(keyBytes) - h = 31 * h + util.Arrays.hashCode(chainCode) + var h = java.util.Arrays.hashCode(keyBytes) + h = 31 * h + java.util.Arrays.hashCode(chainCode) h = 31 * h + path.hashCode() h }