-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathProduct.java
More file actions
31 lines (25 loc) · 844 Bytes
/
Product.java
File metadata and controls
31 lines (25 loc) · 844 Bytes
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
package shop;
import java.math.BigDecimal;
import java.util.Objects;
public final class Product {
private final String id;
private final String name;
private final BigDecimal unitPrice;
public Product(String id, String name, BigDecimal unitPrice) {
if (id == null || id.isBlank()) throw new IllegalArgumentException("id");
if (name == null || name.isBlank()) throw new IllegalArgumentException("name");
this.id = id;
this.name = name;
this.unitPrice = Objects.requireNonNull(unitPrice, "unitPrice");
if (unitPrice.signum() < 0) throw new IllegalArgumentException("unitPrice måste vara >= 0");
}
public String id() {
return id;
}
public String name() {
return name;
}
public BigDecimal unitPrice() {
return unitPrice;
}
}