All Downloads are FREE. Search and download functionalities are using the official Maven repository.

coursier.cache.loggers.RefreshInfo.scala Maven / Gradle / Ivy

There is a newer version: 2.1.13
Show newest version
package coursier.cache.loggers

import dataclass.data

sealed abstract class RefreshInfo extends Product with Serializable {
  def fraction: Option[Double]
  def watching: Boolean
}

object RefreshInfo {

  @data class DownloadInfo(
    downloaded: Long,
    previouslyDownloaded: Long,
    length: Option[Long],
    startTime: Long,
    updateCheck: Boolean,
    watching: Boolean
  ) extends RefreshInfo {

    /** 0.0 to 1.0 */
    def fraction: Option[Double] = length.map(downloaded.toDouble / _)

    /** Byte / s */
    def rate(): Option[Double] = {
      val currentTime = System.currentTimeMillis()
      if (currentTime > startTime)
        Some(
          (downloaded - previouslyDownloaded).toDouble / (System.currentTimeMillis() - startTime) * 1000.0
        )
      else
        None
    }
  }

  @data class CheckUpdateInfo(
    currentTimeOpt: Option[Long],
    remoteTimeOpt: Option[Long],
    isDone: Boolean
  ) extends RefreshInfo {
    def watching = false
    def fraction = None
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy