-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
NoBrakesBuilder.scala
74 lines (65 loc) · 2.25 KB
/
NoBrakesBuilder.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Copyright (c) 2020 Simer JS Plaha (simer.j@gmail.com - @simerplaha)
*
* This file is a part of SwayDB.
*
* SwayDB is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* SwayDB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with SwayDB. If not, see <https://www.gnu.org/licenses/>.
*
* Additional permission under the GNU Affero GPL version 3 section 7:
* If you modify this Program, or any covered work, by linking or combining
* it with other code, such other code is not for that reason alone subject
* to any of the requirements of the GNU Affero GPL version 3.
*/
package swaydb.data.accelerate
class NoBrakesBuilder {
private var onMapCount: Int = _
private var increaseMapSizeBy: Int = _
private var maxMapSize: Long = _
private var level0Meter: LevelZeroMeter = _
}
object NoBrakesBuilder {
class Step0(builder: NoBrakesBuilder) {
def withOnMapCount(onMapCount: Int) = {
builder.onMapCount = onMapCount
new Step1(builder)
}
}
class Step1(builder: NoBrakesBuilder) {
def withIncreaseMapSizeBy(increaseMapSizeBy: Int) = {
builder.increaseMapSizeBy = increaseMapSizeBy
new Step2(builder)
}
}
class Step2(builder: NoBrakesBuilder) {
def withMaxMapSize(maxMapSize: Long) = {
builder.maxMapSize = maxMapSize
new Step3(builder)
}
}
class Step3(builder: NoBrakesBuilder) {
def withLevel0Meter(level0Meter: LevelZeroMeter) = {
builder.level0Meter = level0Meter
new Step4(builder)
}
}
class Step4(builder: NoBrakesBuilder) {
def build(): Accelerator =
Accelerator.noBrakes(
onMapCount = builder.onMapCount,
increaseMapSizeBy = builder.increaseMapSizeBy,
maxMapSize = builder.maxMapSize
)(builder.level0Meter)
}
def builder() = new Step0(new NoBrakesBuilder())
}