回答編集履歴
10
誤字
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
テーブルの枠に合わせて予定を探し、無かったら空の td 、有って開始時間が枠と同じなら時
|
1
|
+
テーブルの枠に合わせて予定を探し、無かったら空の td 、有って開始時間が枠と同じなら時間数分の rowspan の td を書き、枠と違うなら何も書かないようにします。
|
2
2
|
```jsp
|
3
3
|
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
|
4
4
|
<%@page import="entity.Facility"%>
|
9
不要メソッド削除
test
CHANGED
@@ -76,17 +76,6 @@
|
|
76
76
|
this.name = name;
|
77
77
|
}
|
78
78
|
|
79
|
-
@Override
|
80
|
-
public int hashCode() {
|
81
|
-
return Objects.hash(id, name);
|
82
|
-
}
|
83
|
-
@Override
|
84
|
-
public boolean equals(Object obj) {
|
85
|
-
if(this == obj) return true;
|
86
|
-
if(obj == null || getClass() != obj.getClass()) return false;
|
87
|
-
Facility other = (Facility)obj;
|
88
|
-
return id == other.id && Objects.equals(name, other.name);
|
89
|
-
}
|
90
79
|
@Override
|
91
80
|
public String toString() {
|
92
81
|
return "Facility [id=" + id + ", name=" + name + "]";
|
8
ファイル名間違い
test
CHANGED
@@ -47,7 +47,7 @@
|
|
47
47
|
</body>
|
48
48
|
</html>
|
49
49
|
```
|
50
|
-
entity/Facility.
|
50
|
+
entity/Facility.java ( FacilityInfo クラスを不変・マスタ化, フィールド名変更 等 )
|
51
51
|
```java
|
52
52
|
package entity;
|
53
53
|
|
7
コード修正
test
CHANGED
@@ -108,8 +108,8 @@
|
|
108
108
|
public final LocalTime start, endExclusive;
|
109
109
|
|
110
110
|
public Reservation(int id, int facilityId, LocalTime start, LocalTime endExclusive) {
|
111
|
-
if(start.getMinute()%
|
111
|
+
if(start.getMinute()%TIME_UNIT != 0) throw new IllegalArgumentException("start=" + start);
|
112
|
-
if(endExclusive.getMinute()%
|
112
|
+
if(endExclusive.getMinute()%TIME_UNIT != 0) throw new IllegalArgumentException("endExclusive=" + endExclusive);
|
113
113
|
if(!start.isBefore(endExclusive)) throw new IllegalArgumentException("start=" + start + ", endExclusive=" + endExclusive);
|
114
114
|
|
115
115
|
this.id = id;
|
6
jsp の表示時間範囲(start~endExclusive)を変えても正常に表示されるようにコード修正
test
CHANGED
@@ -5,51 +5,73 @@
|
|
5
5
|
<%@page import="entity.Reservation"%>
|
6
6
|
<%@page import="entity.TableReader"%>
|
7
7
|
<%@page import="java.time.LocalTime"%>
|
8
|
+
<%@page import="java.time.temporal.ChronoUnit"%>
|
8
9
|
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
9
10
|
<!DOCTYPE html>
|
10
11
|
<html>
|
11
12
|
<head>
|
12
13
|
<meta charset="UTF-8">
|
13
14
|
<link rel="stylesheet" type="text/css" href="calendar.css" />
|
14
|
-
<title>予約
|
15
|
+
<title>予約テーブル</title>
|
15
16
|
</head>
|
16
17
|
<body>
|
17
18
|
<table>
|
18
19
|
<%TableReader reader = new TableReader(); %>
|
19
20
|
<tr>
|
20
21
|
<th></th>
|
21
|
-
<%for(Facility facility:
|
22
|
+
<%for(Facility facility: Facility.getList()) { %>
|
22
23
|
<th><%=facility.name %></th>
|
23
24
|
<%} %>
|
24
25
|
</tr>
|
25
|
-
<%
|
26
|
+
<%LocalTime start = LocalTime.of(9,0); %>
|
27
|
+
<%LocalTime endExclusive = LocalTime.of(18,0); %>
|
28
|
+
<%for(LocalTime time=start; time.isBefore(endExclusive); time=time.plusMinutes(Reservation.TIME_UNIT)) { %>
|
26
29
|
<tr>
|
27
30
|
<td><%=time %></td>
|
28
|
-
<%for(Facility facility:
|
31
|
+
<%for(Facility facility: Facility.getList()) {
|
29
32
|
Reservation reservation = reader.findReservation(time, facility.id);
|
30
33
|
if(reservation == null) { %>
|
31
34
|
<td bgcolor="#dddddd"></td>
|
32
|
-
<%} else if(reservation.start
|
35
|
+
<%} else if(reservation.start.equals(time) || time == start) {
|
36
|
+
long max = time.until(endExclusive, ChronoUnit.MINUTES) / Reservation.TIME_UNIT;
|
37
|
+
long rowspan = Math.min(time.until(reservation.endExclusive, ChronoUnit.MINUTES) / Reservation.TIME_UNIT, max); %>
|
33
|
-
<td bgcolor="#aaaaaa" rowspan="<%=r
|
38
|
+
<td bgcolor="#aaaaaa" rowspan="<%=rowspan %>"><%=reservation.id %></td>
|
34
39
|
<%} %>
|
35
40
|
<%} %>
|
36
41
|
</tr>
|
37
42
|
<%} %>
|
43
|
+
<tr>
|
44
|
+
<td><%=endExclusive %></td>
|
45
|
+
</tr>
|
38
46
|
</table>
|
39
47
|
</body>
|
40
48
|
</html>
|
41
49
|
```
|
42
|
-
entity/Facility.class ( FacilityInfo クラスを不変化, フィールド名変更 )
|
50
|
+
entity/Facility.class ( FacilityInfo クラスを不変・マスタ化, フィールド名変更 等 )
|
43
51
|
```java
|
44
52
|
package entity;
|
45
53
|
|
46
|
-
import java.util.
|
54
|
+
import java.util.*;
|
47
55
|
|
48
56
|
public class Facility {
|
57
|
+
private static List<Facility> list;
|
58
|
+
|
59
|
+
public static List<Facility> getList() {
|
60
|
+
if(list == null) {
|
61
|
+
list = Collections.unmodifiableList(Arrays.asList(
|
62
|
+
new Facility(1,"会議室1"),
|
63
|
+
new Facility(2,"会議室2"),
|
64
|
+
new Facility(3,"会議室3"),
|
65
|
+
new Facility(4,"会議室4")
|
66
|
+
));
|
67
|
+
}
|
68
|
+
return list;
|
69
|
+
}
|
70
|
+
|
49
71
|
public final int id;
|
50
72
|
public final String name;
|
51
73
|
|
52
|
-
p
|
74
|
+
private Facility(int id, String name) {
|
53
75
|
this.id = id;
|
54
76
|
this.name = name;
|
55
77
|
}
|
@@ -61,53 +83,61 @@
|
|
61
83
|
@Override
|
62
84
|
public boolean equals(Object obj) {
|
63
85
|
if(this == obj) return true;
|
64
|
-
if(obj == null) return false;
|
65
|
-
if(getClass() != obj.getClass()) return false;
|
86
|
+
if(obj == null || getClass() != obj.getClass()) return false;
|
66
87
|
Facility other = (Facility)obj;
|
67
|
-
return Objects.equals(name, other.name)
|
88
|
+
return id == other.id && Objects.equals(name, other.name);
|
89
|
+
}
|
90
|
+
@Override
|
91
|
+
public String toString() {
|
92
|
+
return "Facility [id=" + id + ", name=" + name + "]";
|
68
93
|
}
|
69
94
|
}
|
70
95
|
```
|
71
|
-
entity/Reservation.java ( ReservationInfo クラスを不変化, メソッド追加 )
|
96
|
+
entity/Reservation.java ( ReservationInfo クラスを不変化, 定数・メソッド追加 等)
|
72
97
|
```java
|
73
98
|
package entity;
|
74
99
|
|
75
100
|
import java.time.LocalTime;
|
76
|
-
import java.time.temporal.ChronoUnit;
|
77
101
|
import java.util.Objects;
|
78
102
|
|
79
103
|
public class Reservation {
|
104
|
+
public static final int TIME_UNIT = 15; //[minute]
|
105
|
+
|
80
106
|
public final int id;
|
81
107
|
public final int facilityId;
|
82
|
-
public final LocalTime start
|
108
|
+
public final LocalTime start, endExclusive;
|
83
|
-
public final LocalTime endTime; //exclude
|
84
|
-
public final long utilizationTime; //[minute]
|
85
109
|
|
86
|
-
public Reservation(int id, int facilityId, LocalTime start
|
110
|
+
public Reservation(int id, int facilityId, LocalTime start, LocalTime endExclusive) {
|
111
|
+
if(start.getMinute()%Reservation.TIME_UNIT != 0) throw new IllegalArgumentException("start=" + start);
|
112
|
+
if(endExclusive.getMinute()%Reservation.TIME_UNIT != 0) throw new IllegalArgumentException("endExclusive=" + endExclusive);
|
113
|
+
if(!start.isBefore(endExclusive)) throw new IllegalArgumentException("start=" + start + ", endExclusive=" + endExclusive);
|
114
|
+
|
87
115
|
this.id = id;
|
88
116
|
this.facilityId = facilityId;
|
89
|
-
this.start
|
117
|
+
this.start = start;
|
90
|
-
this.end
|
118
|
+
this.endExclusive = endExclusive;
|
91
|
-
utilizationTime = startTime.until(endTime, ChronoUnit.MINUTES);
|
92
119
|
}
|
93
120
|
|
94
121
|
public boolean inTimeRange(LocalTime time) {
|
95
|
-
return start
|
122
|
+
return start.equals(time) || (start.isBefore(time) && endExclusive.isAfter(time));
|
96
123
|
}
|
97
124
|
|
98
125
|
@Override
|
99
126
|
public int hashCode() {
|
100
|
-
return Objects.hash(
|
127
|
+
return Objects.hash(id, facilityId, start, endExclusive);
|
101
128
|
}
|
102
|
-
|
103
129
|
@Override
|
104
130
|
public boolean equals(Object obj) {
|
105
131
|
if(this == obj) return true;
|
106
|
-
if(obj == null) return false;
|
107
|
-
if(getClass() != obj.getClass()) return false;
|
132
|
+
if(obj == null || getClass() != obj.getClass()) return false;
|
108
|
-
Reservation other = (Reservation)
|
133
|
+
Reservation other = (Reservation)obj;
|
109
|
-
return
|
134
|
+
return id == other.id && facilityId == other.facilityId
|
110
|
-
&& Objects.equals(start
|
135
|
+
&& Objects.equals(start, other.start) && Objects.equals(endExclusive, other.endExclusive);
|
136
|
+
}
|
137
|
+
@Override
|
138
|
+
public String toString() {
|
139
|
+
return "Reservation [id=" + id + ", facilityId=" + facilityId
|
140
|
+
+ ", start=" + start + ", endExclusive=" + endExclusive + "]";
|
111
141
|
}
|
112
142
|
}
|
113
143
|
```
|
@@ -119,28 +149,16 @@
|
|
119
149
|
import java.util.*;
|
120
150
|
|
121
151
|
public class TableReader {
|
122
|
-
private List<LocalTime> timeList;
|
123
|
-
private List<Facility> facilityList;
|
124
152
|
private List<Reservation> reservationList;
|
125
153
|
|
126
154
|
public TableReader() {
|
127
|
-
List<LocalTime> timeList = new ArrayList<>();
|
128
|
-
for(LocalTime time=LocalTime.of(9,0), end=LocalTime.of(18,0); time.isBefore(end)||time.equals(end); time=time.plusMinutes(15)) timeList.add(time);
|
129
|
-
this.timeList = Collections.unmodifiableList(timeList);
|
130
|
-
|
131
|
-
|
155
|
+
//テストデータ
|
132
|
-
for(int i=1; i<=4; i++) facilityList.add(new Facility(i, "会議室" + i));
|
133
|
-
this.facilityList = Collections.unmodifiableList(facilityList);
|
134
|
-
|
135
156
|
reservationList = new ArrayList<>();
|
136
157
|
reservationList.add(new Reservation(1, 1, LocalTime.of( 9, 0), LocalTime.of(12, 0)));
|
137
158
|
reservationList.add(new Reservation(2, 1, LocalTime.of(15, 0), LocalTime.of(17, 0)));
|
138
159
|
reservationList.add(new Reservation(3, 2, LocalTime.of(10, 0), LocalTime.of(12, 0)));
|
139
160
|
reservationList.add(new Reservation(4, 4, LocalTime.of(10, 0), LocalTime.of(12, 0)));
|
140
161
|
}
|
141
|
-
|
142
|
-
public List<LocalTime> getTimeList() { return timeList; }
|
143
|
-
public List<Facility> getFacilityList() { return facilityList; }
|
144
162
|
|
145
163
|
public Reservation findReservation(LocalTime time, int facilityId) {
|
146
164
|
for(Reservation reservation : reservationList) {
|
5
コード修正
test
CHANGED
@@ -16,27 +16,28 @@
|
|
16
16
|
<body>
|
17
17
|
<table>
|
18
18
|
<%TableReader reader = new TableReader(); %>
|
19
|
-
|
19
|
+
<tr>
|
20
|
-
|
20
|
+
<th></th>
|
21
|
-
|
21
|
+
<%for(Facility facility: reader.getFacilityList()) { %>
|
22
|
-
|
22
|
+
<th><%=facility.name %></th>
|
23
|
-
|
23
|
+
<%} %>
|
24
|
-
|
24
|
+
</tr>
|
25
|
-
|
25
|
+
<%for(LocalTime time: reader.getTimeList()) { %>
|
26
|
-
|
26
|
+
<tr>
|
27
|
-
|
27
|
+
<td><%=time %></td>
|
28
|
-
|
28
|
+
<%for(Facility facility: reader.getFacilityList()) {
|
29
29
|
Reservation reservation = reader.findReservation(time, facility.id);
|
30
30
|
if(reservation == null) { %>
|
31
31
|
<td bgcolor="#dddddd"></td>
|
32
|
-
|
32
|
+
<%} else if(reservation.startTime.equals(time)) { %>
|
33
|
-
<td bgcolor="#aaaaaa" rowspan="<%=reservation.
|
33
|
+
<td bgcolor="#aaaaaa" rowspan="<%=reservation.utilizationTime/15 %>"><%=reservation.id %></td>
|
34
34
|
<%} %>
|
35
35
|
<%} %>
|
36
|
-
|
36
|
+
</tr>
|
37
37
|
<%} %>
|
38
38
|
</table>
|
39
39
|
</body>
|
40
|
+
</html>
|
40
41
|
```
|
41
42
|
entity/Facility.class ( FacilityInfo クラスを不変化, フィールド名変更 )
|
42
43
|
```java
|
@@ -78,17 +79,18 @@
|
|
78
79
|
public class Reservation {
|
79
80
|
public final int id;
|
80
81
|
public final int facilityId;
|
81
|
-
public final LocalTime startTime;
|
82
|
+
public final LocalTime startTime; //include
|
82
|
-
public final LocalTime endTime;
|
83
|
+
public final LocalTime endTime; //exclude
|
84
|
+
public final long utilizationTime; //[minute]
|
83
85
|
|
84
86
|
public Reservation(int id, int facilityId, LocalTime startTime, LocalTime endTime) {
|
85
87
|
this.id = id;
|
86
88
|
this.facilityId = facilityId;
|
87
89
|
this.startTime = startTime;
|
88
90
|
this.endTime = endTime;
|
91
|
+
utilizationTime = startTime.until(endTime, ChronoUnit.MINUTES);
|
89
92
|
}
|
90
93
|
|
91
|
-
public long getUtilizationTime() { return startTime.until(endTime, ChronoUnit.MINUTES); }
|
92
94
|
public boolean inTimeRange(LocalTime time) {
|
93
95
|
return startTime.equals(time) || (startTime.isBefore(time) && endTime.isAfter(time));
|
94
96
|
}
|
4
フォルダ名修正
test
CHANGED
@@ -38,7 +38,7 @@
|
|
38
38
|
</table>
|
39
39
|
</body>
|
40
40
|
```
|
41
|
-
ent
|
41
|
+
entity/Facility.class ( FacilityInfo クラスを不変化, フィールド名変更 )
|
42
42
|
```java
|
43
43
|
package entity;
|
44
44
|
|
@@ -67,7 +67,7 @@
|
|
67
67
|
}
|
68
68
|
}
|
69
69
|
```
|
70
|
-
ent
|
70
|
+
entity/Reservation.java ( ReservationInfo クラスを不変化, メソッド追加 )
|
71
71
|
```java
|
72
72
|
package entity;
|
73
73
|
|
@@ -109,7 +109,7 @@
|
|
109
109
|
}
|
110
110
|
}
|
111
111
|
```
|
112
|
-
ent
|
112
|
+
entity/TableReader.java ( 新規, オリジナル jsp にあった処理を移動等 )
|
113
113
|
```java
|
114
114
|
package entity;
|
115
115
|
|
3
修正
test
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
テーブルの枠に合わせて予定を探し、無かったら
|
2
|
-
空の td 、有って開始と同じなら時関数分の rowspan の td を書き、
|
1
|
+
テーブルの枠に合わせて予定を探し、無かったら空の td 、有って開始時間が枠と同じなら時関数分の rowspan の td を書き、枠と違うなら何も書かないようにします。
|
3
2
|
```jsp
|
4
3
|
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
|
5
4
|
<%@page import="entity.Facility"%>
|
2
修正
test
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
+
テーブルの枠に合わせて予定を探し、無かったら
|
1
|
-
|
2
|
+
空の td 、有って開始と同じなら時関数分の rowspan の td を書き、開始以外なら何も書かないようにします。
|
2
3
|
```jsp
|
3
4
|
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
|
4
5
|
<%@page import="entity.Facility"%>
|
1
修正
test
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
予定
|
1
|
+
予定の枠に合わせてテーブルを設定するのでは無く、テーブルの枠に合わせて予定を探すほうが簡単なようです。
|
2
|
-
|
3
2
|
```jsp
|
4
3
|
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
|
5
4
|
<%@page import="entity.Facility"%>
|