Skip to content

Commit 5e47501

Browse files
committed
introducing PositiveInt as a transfer value
1 parent f0cf194 commit 5e47501

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/main/java/User.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import com.google.common.base.Preconditions;
12
import lombok.Value;
23

34
/**
@@ -8,11 +9,25 @@ class User {
89
int id;
910
int balance;
1011

11-
User income(int value) {
12-
return new User(id, balance + value);
12+
User income(PositiveInt value) {
13+
return new User(id, balance + value.amount);
1314
}
1415

15-
User outcome(int value) {
16-
return new User(id, balance - value);
16+
User outcome(PositiveInt value) {
17+
return new User(id, balance - value.amount);
18+
}
19+
}
20+
21+
class PositiveInt {
22+
final int amount;
23+
24+
private PositiveInt(int amount) {
25+
this.amount = amount;
26+
}
27+
28+
static PositiveInt of(int amount) {
29+
Preconditions.checkArgument(amount > 0);
30+
31+
return new PositiveInt(amount);
1732
}
1833
}

src/test/java/XXXTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void transfer() {
2323
LockExecutor executor = new LockExecutor(lock);
2424

2525
executor.write(() -> {
26-
int transfer = 15;
26+
var transfer = PositiveInt.of(15);
2727
userMap.replace(1, userMap.get(1).outcome(transfer));
2828
userMap.replace(2, userMap.get(2).income(transfer));
2929
});

0 commit comments

Comments
 (0)