Skip to content

Commit

Permalink
minimize-modules: use fully qualified java.util.
Browse files Browse the repository at this point in the history
  • Loading branch information
aslesarenko committed Aug 22, 2023
1 parent 3fce4d7 commit 8ed3f81
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 51 deletions.
20 changes: 9 additions & 11 deletions common/shared/src/main/scala/scalan/util/CollectionUtil.scala
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions common/shared/src/main/scala/sigma/CollsOverArrays.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package sigma

import java.util
import scalan._ // required
import scalan.util.CollectionUtil
import scalan.RType
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] {
Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class GF2_192 extends AnyRef {
}
}

override def hashCode = util.Arrays.hashCode(word)
override def hashCode = java.util.Arrays.hashCode(word)

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions interpreter/shared/src/main/scala/sigmastate/utils/Helpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions sdk/shared/src/main/scala/org/ergoplatform/sdk/ErgoId.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 8ed3f81

Please sign in to comment.