Skip to content

Commit

Permalink
Remove deprecated foldSyntax and use compat for xs.to[C]
Browse files Browse the repository at this point in the history
ran

scalafix scala:fix.CrossCompat
test:scalafix scala:fix.CrossCompat

with

scala/scala-collection-compat#100
  • Loading branch information
MasseGuillaume committed Jul 17, 2018
1 parent eff7a3c commit 8ee5c15
Show file tree
Hide file tree
Showing 28 changed files with 73 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ByteStringSpec extends WordSpec with Matchers with Checkers {
for {
chunks Gen.choose(0, s)
bytes Gen.listOfN(chunks, genSimpleByteString(1, 1 max (s / (chunks max 1))))
} yield (ByteString.empty /: bytes)(_ ++ _)
} yield bytes.foldLeft(ByteString.empty)(_ ++ _)
}
}

Expand Down
2 changes: 1 addition & 1 deletion akka-actor/src/main/scala/akka/actor/ActorPath.scala
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ sealed trait ActorPath extends Comparable[ActorPath] with Serializable {
/**
* Recursively create a descendant’s path by appending all child names.
*/
def /(child: Iterable[String]): ActorPath = (this /: child)((path, elem) if (elem.isEmpty) path else path / elem)
def /(child: Iterable[String]): ActorPath = child.foldLeft(this)((path, elem) if (elem.isEmpty) path else path / elem)

/**
* Java API: Recursively create a descendant’s path by appending all child names.
Expand Down
5 changes: 3 additions & 2 deletions akka-actor/src/main/scala/akka/actor/FaultHandling.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import akka.event.Logging.LogEvent
import akka.event.Logging.Error
import akka.event.Logging.Warning
import scala.util.control.NonFatal
import scala.collection.compat._

/**
* INTERNAL API
Expand Down Expand Up @@ -229,13 +230,13 @@ object SupervisorStrategy extends SupervisorStrategyLowPriorityImplicits {
* INTERNAL API
*/
private[akka] def sort(in: Iterable[CauseDirective]): immutable.Seq[CauseDirective] =
(new ArrayBuffer[CauseDirective](in.size) /: in) { (buf, ca)
in.foldLeft(new ArrayBuffer[CauseDirective](in.size)) { (buf, ca)
buf.indexWhere(_._1 isAssignableFrom ca._1) match {
case -1 buf append ca
case x buf insert (x, ca)
}
buf
}.to[immutable.IndexedSeq]
}.to(immutable.IndexedSeq)

private[akka] def withinTimeRangeOption(withinTimeRange: Duration): Option[Duration] =
if (withinTimeRange.isFinite && withinTimeRange >= Duration.Zero) Some(withinTimeRange) else None
Expand Down
4 changes: 2 additions & 2 deletions akka-actor/src/main/scala/akka/event/EventBus.scala
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ trait SubchannelClassification { this: EventBus ⇒
cache.values exists { _ contains subscriber }

private def removeFromCache(changes: immutable.Seq[(Classifier, Set[Subscriber])]): Unit =
cache = (cache /: changes) {
cache = changes.foldLeft(cache) {
case (m, (c, cs)) m.updated(c, m.getOrElse(c, Set.empty[Subscriber]) diff cs)
}

private def addToCache(changes: immutable.Seq[(Classifier, Set[Subscriber])]): Unit =
cache = (cache /: changes) {
cache = changes.foldLeft(cache) {
case (m, (c, cs)) m.updated(c, m.getOrElse(c, Set.empty[Subscriber]) union cs)
}

Expand Down
4 changes: 3 additions & 1 deletion akka-actor/src/main/scala/akka/io/UdpConnected.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import akka.io.Udp.UdpSettings
import akka.util.ByteString
import akka.actor._

import scala.collection.compat._

/**
* UDP Extension for Akka’s IO layer.
*
Expand Down Expand Up @@ -248,6 +250,6 @@ object UdpConnectedMessage {

implicit private def fromJava[T](coll: JIterable[T]): immutable.Traversable[T] = {
import scala.collection.JavaConverters._
coll.asScala.to[immutable.Traversable]
coll.asScala.to(immutable.Traversable)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import java.util.concurrent.atomic.AtomicReference
import scala.annotation.tailrec
import java.util.NoSuchElementException
import akka.annotation.InternalApi
import scala.collection.compat._

object Serialization {

Expand Down Expand Up @@ -441,20 +442,20 @@ class Serialization(val system: ExtendedActorSystem) extends Extension {
* obeying any order between unrelated subtypes (insert sort).
*/
private def sort(in: Iterable[ClassSerializer]): immutable.Seq[ClassSerializer] =
((new ArrayBuffer[ClassSerializer](in.size) /: in) { (buf, ca)
(in.foldLeft(new ArrayBuffer[ClassSerializer](in.size)) { (buf, ca)
buf.indexWhere(_._1 isAssignableFrom ca._1) match {
case -1 buf append ca
case x buf insert (x, ca)
}
buf
}).to[immutable.Seq]
}).to(immutable.Seq)

/**
* serializerMap is a Map whose keys is the class that is serializable and values is the serializer
* to be used for that class.
*/
private val serializerMap: ConcurrentHashMap[Class[_], Serializer] =
(new ConcurrentHashMap[Class[_], Serializer] /: bindings) { case (map, (c, s)) map.put(c, s); map }
bindings.foldLeft(new ConcurrentHashMap[Class[_], Serializer]) { case (map, (c, s)) map.put(c, s); map }

/**
* Maps from a Serializer Identity (Int) to a Serializer instance (optimization)
Expand Down
2 changes: 1 addition & 1 deletion akka-actor/src/main/scala/akka/util/ByteString.scala
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ object ByteString {
}

private[akka] object ByteStrings extends Companion {
def apply(bytestrings: Vector[ByteString1]): ByteString = new ByteStrings(bytestrings, (0 /: bytestrings)(_ + _.length))
def apply(bytestrings: Vector[ByteString1]): ByteString = new ByteStrings(bytestrings, bytestrings.foldLeft(0)(_ + _.length))

def apply(bytestrings: Vector[ByteString1], length: Int): ByteString = new ByteStrings(bytestrings, length)

Expand Down
10 changes: 6 additions & 4 deletions akka-actor/src/main/scala/akka/util/SubclassifiedIndex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package akka.util

import scala.collection.immutable

import scala.collection.compat._

/**
* Typeclass which describes a classification hierarchy. Observe the contract between `isEqual` and `isSubclass`!
*/
Expand Down Expand Up @@ -172,7 +174,7 @@ private[akka] class SubclassifiedIndex[K, V] private (protected var values: Set[
*/
protected final def findValues(key: K): Set[V] = root.innerFindValues(key)
protected def innerFindValues(key: K): Set[V] =
(Set.empty[V] /: subkeys) { (s, n)
subkeys.foldLeft(Set.empty[V]) { (s, n)
if (sc.isSubclass(key, n.key))
s ++ n.innerFindValues(key)
else
Expand All @@ -184,7 +186,7 @@ private[akka] class SubclassifiedIndex[K, V] private (protected var values: Set[
*/
protected final def findSubKeysExcept(key: K, except: Vector[Nonroot[K, V]]): Set[K] = root.innerFindSubKeys(key, except)
protected def innerFindSubKeys(key: K, except: Vector[Nonroot[K, V]]): Set[K] =
(Set.empty[K] /: subkeys) { (s, n)
subkeys.foldLeft(Set.empty[K]) { (s, n)
if (sc.isEqual(key, n.key)) s
else n.innerFindSubKeys(key, except) ++ {
if (sc.isSubclass(n.key, key) && !except.exists(e sc.isEqual(key, e.key)))
Expand All @@ -209,7 +211,7 @@ private[akka] class SubclassifiedIndex[K, V] private (protected var values: Set[
}

private def mergeChangesByKey(changes: Changes): Changes =
(emptyMergeMap[K, V] /: changes) {
changes.foldLeft(emptyMergeMap[K, V]) {
case (m, (k, s)) m.updated(k, m(k) ++ s)
}.to[immutable.Seq]
}.to(immutable.Seq)
}
2 changes: 1 addition & 1 deletion akka-camel/src/main/scala/akka/camel/Camel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class CamelSettings private[camel] (config: Config, dynamicAccess: DynamicAccess
val section = config.getConfig("akka.camel.conversions")
section.entrySet.asScala.map(e (e.getKey, section.getString(e.getKey)))
}
val conversions = (Map[String, Class[_ <: AnyRef]]() /: specifiedConversions) {
val conversions = specifiedConversions.foldLeft(Map[String, Class[_ <: AnyRef]]()) {
case (m, (key, fqcn))
m.updated(key, dynamicAccess.getClassFor[AnyRef](fqcn).recover {
case e throw new ConfigurationException("Could not find/load Camel Converter class [" + fqcn + "]", e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import akka.remote.DeadlineFailureDetector
import akka.dispatch.Dispatchers
import akka.util.MessageBuffer
import scala.collection.immutable.{ HashMap, HashSet }
import scala.collection.compat._

object ClusterClientSettings {
/**
Expand Down Expand Up @@ -332,7 +333,7 @@ final class ClusterClient(settings: ClusterClientSettings) extends Actor with Ac
val failureDetector = new DeadlineFailureDetector(acceptableHeartbeatPause, heartbeatInterval)

var contactPaths: HashSet[ActorPath] =
initialContacts.to[HashSet]
initialContacts.to(HashSet)
val initialContactsSel =
contactPaths.map(context.actorSelection)
var contacts = initialContactsSel
Expand Down Expand Up @@ -373,7 +374,7 @@ final class ClusterClient(settings: ClusterClientSettings) extends Actor with Ac
{
case Contacts(contactPoints)
if (contactPoints.nonEmpty) {
contactPaths = contactPoints.map(ActorPath.fromString).to[HashSet]
contactPaths = contactPoints.map(ActorPath.fromString).to(HashSet)
contacts = contactPaths.map(context.actorSelection)
contacts foreach { _ ! Identify(Array.emptyByteArray) }
}
Expand Down Expand Up @@ -423,7 +424,7 @@ final class ClusterClient(settings: ClusterClientSettings) extends Actor with Ac
case Contacts(contactPoints)
// refresh of contacts
if (contactPoints.nonEmpty) {
contactPaths = contactPoints.map(ActorPath.fromString).to[HashSet]
contactPaths = contactPoints.map(ActorPath.fromString).to(HashSet)
contacts = contactPaths.map(context.actorSelection)
}
publishContactPoints()
Expand Down Expand Up @@ -992,7 +993,7 @@ final class ClusterReceptionist(pubSubMediator: ActorRef, settings: ClusterRecep

case SubscribeClusterClients
val subscriber = sender()
subscriber ! ClusterClients(clientInteractions.keySet.to[HashSet])
subscriber ! ClusterClients(clientInteractions.keySet.to(HashSet))
subscribers :+= subscriber
context.watch(subscriber)

Expand All @@ -1004,7 +1005,7 @@ final class ClusterReceptionist(pubSubMediator: ActorRef, settings: ClusterRecep
self.tell(UnsubscribeClusterClients, subscriber)

case GetClusterClients
sender() ! ClusterClients(clientInteractions.keySet.to[HashSet])
sender() ! ClusterClients(clientInteractions.keySet.to(HashSet))

case CheckDeadlines
clientInteractions = clientInteractions.filter {
Expand All @@ -1025,11 +1026,11 @@ final class ClusterReceptionist(pubSubMediator: ActorRef, settings: ClusterRecep
log.debug("Received new contact from [{}]", client.path)
val clusterClientUp = ClusterClientUp(client)
subscribers.foreach(_ ! clusterClientUp)
clientsPublished = clientInteractions.keySet.to[HashSet]
clientsPublished = clientInteractions.keySet.to(HashSet)
}

def publishClientsUnreachable(): Unit = {
val publishableClients = clientInteractions.keySet.to[HashSet]
val publishableClients = clientInteractions.keySet.to(HashSet)
for (c clientsPublished if !publishableClients.contains(c)) {
log.debug("Lost contact with [{}]", c.path)
val clusterClientUnreachable = ClusterClientUnreachable(c)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.typesafe.config.{ Config, ConfigFactory, ConfigValue }

import scala.collection.JavaConverters._
import scala.collection.{ immutable im }
import scala.collection.compat._

abstract class JoinConfigCompatChecker {

Expand Down Expand Up @@ -48,7 +49,7 @@ object JoinConfigCompatChecker {
}

if (result.isEmpty) Valid
else Invalid(result.to[im.Seq])
else Invalid(result.to(im.Seq))
}

/**
Expand Down Expand Up @@ -78,7 +79,7 @@ object JoinConfigCompatChecker {
}

if (incompatibleKeys.isEmpty) Valid
else Invalid(incompatibleKeys.to[im.Seq])
else Invalid(incompatibleKeys.to(im.Seq))
}

exists(requiredKeys, toCheck) ++ checkEquality
Expand Down Expand Up @@ -123,7 +124,7 @@ object JoinConfigCompatChecker {
*/
@InternalApi
private[cluster] def removeSensitiveKeys(config: Config, clusterSettings: ClusterSettings): im.Seq[String] = {
val existingKeys = config.entrySet().asScala.map(_.getKey).to[im.Seq]
val existingKeys = config.entrySet().asScala.map(_.getKey).to(im.Seq)
removeSensitiveKeys(existingKeys, clusterSettings)
}

Expand All @@ -145,7 +146,7 @@ object JoinConfigCompatChecker {

// composite checker
new JoinConfigCompatChecker {
override val requiredKeys: im.Seq[String] = checkers.flatMap(_.requiredKeys).to[im.Seq]
override val requiredKeys: im.Seq[String] = checkers.flatMap(_.requiredKeys).to(im.Seq)
override def check(toValidate: Config, clusterConfig: Config): ConfigValidation =
checkers.foldLeft(Valid: ConfigValidation) { (acc, checker)
acc ++ checker.check(toValidate, clusterConfig)
Expand Down
3 changes: 2 additions & 1 deletion akka-cluster/src/main/scala/akka/cluster/Reachability.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import akka.annotation.InternalApi

import scala.collection.immutable
import scala.collection.breakOut
import scala.collection.compat._

/**
* INTERNAL API
Expand Down Expand Up @@ -195,7 +196,7 @@ private[cluster] class Reachability private (
}

def remove(nodes: Iterable[UniqueAddress]): Reachability = {
val nodesSet = nodes.to[immutable.HashSet]
val nodesSet = nodes.to(immutable.HashSet)
val newRecords = records.filterNot(r nodesSet(r.observer) || nodesSet(r.subject))
val newVersions = versions -- nodes
Reachability(newRecords, newVersions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import akka.cluster.InternalClusterAction._
import akka.cluster.routing.{ ClusterRouterPool, ClusterRouterPoolSettings }
import akka.routing.Pool
import com.typesafe.config.{ Config, ConfigFactory, ConfigRenderOptions }
import scala.collection.compat._

/**
* INTERNAL API
Expand Down Expand Up @@ -358,9 +359,9 @@ final class ClusterMessageSerializer(val system: ExtendedActorSystem) extends Se
val allMembers = gossip.members.toVector
val allAddresses: Vector[UniqueAddress] = allMembers.map(_.uniqueAddress) ++ gossip.tombstones.keys
val addressMapping = allAddresses.zipWithIndex.toMap
val allRoles = allMembers.foldLeft(Set.empty[String])((acc, m) acc union m.roles).to[Vector]
val allRoles = allMembers.foldLeft(Set.empty[String])((acc, m) acc union m.roles).to(Vector)
val roleMapping = allRoles.zipWithIndex.toMap
val allHashes = gossip.version.versions.keys.to[Vector]
val allHashes = gossip.version.versions.keys.to(Vector)
val hashMapping = allHashes.zipWithIndex.toMap

def mapUniqueAddress(uniqueAddress: UniqueAddress): Integer = mapWithErrorMessage(addressMapping, uniqueAddress, "address")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ClusterDomainEventSpec extends WordSpec with Matchers {
val selfDummyAddress = UniqueAddress(Address("akka.tcp", "sys", "selfDummy", 2552), 17L)

private[cluster] def converge(gossip: Gossip): (Gossip, Set[UniqueAddress]) =
((gossip, Set.empty[UniqueAddress]) /: gossip.members) { case ((gs, as), m) (gs.seen(m.uniqueAddress), as + m.uniqueAddress) }
gossip.members.foldLeft((gossip, Set.empty[UniqueAddress])) { case ((gs, as), m) (gs.seen(m.uniqueAddress), as + m.uniqueAddress) }

private def state(g: Gossip): MembershipState =
state(g, selfDummyAddress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ReachabilityPerfSpec extends WordSpec with Matchers {
val node = Address("akka.tcp", "sys", "a", 2552)

private def createReachabilityOfSize(base: Reachability, size: Int): Reachability =
(base /: (1 to size)) {
(1 to size).foldLeft(base) {
case (r, i)
val observer = UniqueAddress(address.copy(host = Some("node-" + i)), i.toLong)
val j = if (i == size) 1 else i + 1
Expand All @@ -29,9 +29,9 @@ class ReachabilityPerfSpec extends WordSpec with Matchers {
private def addUnreachable(base: Reachability, count: Int): Reachability = {
val observers = base.allObservers.take(count)
val subjects = Stream.continually(base.allObservers).flatten.iterator
(base /: observers) {
observers.foldLeft(base) {
case (r, o)
(r /: (1 to 5)) { case (r, _) r.unreachable(o, subjects.next()) }
(1 to 5).foldLeft(r) { case (r, _) r.unreachable(o, subjects.next()) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ object VectorClockPerfSpec {
import VectorClock._

def createVectorClockOfSize(size: Int): (VectorClock, SortedSet[Node]) =
((VectorClock(), SortedSet.empty[Node]) /: (1 to size)) {
(1 to size).foldLeft((VectorClock(), SortedSet.empty[Node])) {
case ((vc, nodes), i)
val node = Node(i.toString)
(vc :+ node, nodes + node)
}

def copyVectorClock(vc: VectorClock): VectorClock = {
val versions = (TreeMap.empty[Node, Long] /: vc.versions) {
val versions = vc.versions.foldLeft(TreeMap.empty[Node, Long]) {
case (versions, (n, t)) versions.updated(Node.fromHash(n), t)
}
vc.copy(versions = versions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import akka.event.{ LoggingAdapter, Logging }
import java.net.{ InetSocketAddress, ConnectException }
import akka.remote.transport.ThrottlerTransportAdapter.{ SetThrottle, TokenBucket, Blackhole, Unthrottled }
import akka.dispatch.{ UnboundedMessageQueueSemantics, RequiresMessageQueue }
import scala.collection.compat._

object Player {

Expand Down Expand Up @@ -85,7 +86,7 @@ trait Player { this: TestConductorExt ⇒
* Enter the named barriers, one after the other, in the order given. Will
* throw an exception in case of timeouts or other errors.
*/
def enter(name: String*): Unit = enter(Settings.BarrierTimeout, name.to[immutable.Seq])
def enter(name: String*): Unit = enter(Settings.BarrierTimeout, name.to(immutable.Seq))

/**
* Enter the named barriers, one after the other, in the order given. Will
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import akka.actor.RootActorPath
import akka.event.{ Logging, LoggingAdapter }
import akka.remote.RemoteTransportException
import org.jboss.netty.channel.ChannelException
import scala.collection.compat._

/**
* Configure the role names and participants of the test, including configuration settings.
Expand Down Expand Up @@ -383,7 +384,7 @@ abstract class MultiNodeSpec(val myself: RoleName, _system: ActorSystem, _roles:
def enterBarrier(name: String*): Unit =
testConductor.enter(
Timeout.durationToTimeout(remainingOr(testConductor.Settings.BarrierTimeout.duration)),
name.to[immutable.Seq])
name.to(immutable.Seq))

/**
* Query the controller for the transport address of the given node (by role name) and
Expand Down Expand Up @@ -434,7 +435,7 @@ abstract class MultiNodeSpec(val myself: RoleName, _system: ActorSystem, _roles:
protected def injectDeployments(sys: ActorSystem, role: RoleName): Unit = {
val deployer = sys.asInstanceOf[ExtendedActorSystem].provider.deployer
deployments(role) foreach { str
val deployString = (str /: replacements) {
val deployString = replacements.foldLeft(str) {
case (base, r @ Replacement(tag, _))
base.indexOf(tag) match {
case -1 base
Expand Down
Loading

0 comments on commit 8ee5c15

Please sign in to comment.