Skip to content

Commit bd83cb1

Browse files
committed
ETCM-463: Prevent using copy.
1 parent 4e065d7 commit bd83cb1

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/main/scala/io/iohk/ethereum/network/TimeSlotStats.scala

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import cats._
44
import cats.implicits._
55
import scala.concurrent.duration.{Duration, FiniteDuration}
66

7-
/** Track statistics over time. */
7+
/** Track statistics over time a fixed size timewindow. */
88
case class TimeSlotStats[K, V: Monoid] private (
99
// Time resolution.
1010
slotDuration: FiniteDuration,
@@ -18,8 +18,8 @@ case class TimeSlotStats[K, V: Monoid] private (
1818
) {
1919
import TimeSlotStats._
2020

21-
private def succ(idx: Int): Int = (idx + 1) % slotCount
22-
private def pred(idx: Int): Int = (idx - 1) % slotCount
21+
/** Overall length of the timewindow. */
22+
def duration = slotDuration * slotCount
2323

2424
/** Merge new stats for a given key in the current timestamp. */
2525
def add(key: K, stat: V, timestamp: Timestamp = System.currentTimeMillis): TimeSlotStats[K, V] = {
@@ -87,6 +87,19 @@ case class TimeSlotStats[K, V: Monoid] private (
8787
val startSlot = slotId(timestamp - slotDuration.toMillis * slotCount)
8888
startSlot -> endSlot
8989
}
90+
91+
private def succ(idx: Int): Int = (idx + 1) % slotCount
92+
private def pred(idx: Int): Int = (idx - 1) % slotCount
93+
94+
private def copy(statSlots: IndexedSeq[Map[K, V]]): TimeSlotStats[K, V] =
95+
copy(lastIdx, timeSlots, statSlots)
96+
97+
private def copy(
98+
lastIdx: Int,
99+
timeSlots: IndexedSeq[Timestamp],
100+
statSlots: IndexedSeq[Map[K, V]]
101+
): TimeSlotStats[K, V] =
102+
new TimeSlotStats[K, V](slotDuration, slotCount, lastIdx, timeSlots, statSlots)
90103
}
91104

92105
object TimeSlotStats {

0 commit comments

Comments
 (0)