-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTableRepository.java
More file actions
33 lines (27 loc) · 1.06 KB
/
TableRepository.java
File metadata and controls
33 lines (27 loc) · 1.06 KB
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
package repository;
import domain.Table;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
public class TableRepository {
private static final List<Table> tables = new ArrayList<>();
static {
tables.add(new Table(1));
tables.add(new Table(2));
tables.add(new Table(3));
tables.add(new Table(5));
tables.add(new Table(6));
tables.add(new Table(8));
}
//nubmer에 해당하는 Table을 return한다.
public static Optional<Table> findByNumber(int number){
return Optional.ofNullable(tables.stream()
.filter(table -> table.isEqualNumber(number))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException(number+"번 테이블은 존재하지 않는 테이블입니다.")));//Optional로 감싸줌으로써, Null이더라도 반환해서 클라이언트 단에서 처리해줄 수 있도록
}
public static List<Table> tables() {
return Collections.unmodifiableList(tables);
}
}