forked from prmr/DesignBook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompositeShow.java
More file actions
73 lines (65 loc) · 1.44 KB
/
CompositeShow.java
File metadata and controls
73 lines (65 loc) · 1.44 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
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
package chapter6;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.StringJoiner;
public class CompositeShow implements Show
{
private List<Show> aShows = new ArrayList<>();
public CompositeShow(Show...pShows)
{
if( pShows.length < 2 || pShows.length > 5)
{
throw new IllegalArgumentException("Arguments should be between two and five shows inclusively");
}
aShows.addAll(Arrays.asList(pShows));
}
@Override
public String description()
{
StringJoiner description = new StringJoiner("; ", "[", "]");
for( Show show : aShows )
{
description.add(show.description());
}
return description.toString();
}
@Override
public int runningTime()
{
int time = 0;
for( Show show : aShows )
{
time += show.runningTime();
}
return time;
}
@Override
public Show copy()
{
List<Show> copies = new ArrayList<>();
for( Show show : aShows )
{
copies.add(show.copy());
}
return new CompositeShow(copies.toArray(new Show[copies.size()]));
}
@Override
public int hashCode()
{
return Objects.hash(aShows);
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
CompositeShow other = (CompositeShow) obj;
return Objects.equals(aShows, other.aShows);
}
}