-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConcat.java
78 lines (66 loc) · 1.71 KB
/
Concat.java
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
74
75
76
77
78
package music;
/**
* Concat represents two pieces of music played one after the other.
*/
public class Concat implements Music {
private final Music first;
private final Music second;
private void checkRep() {
assert first != null;
assert second != null;
}
/**
* Make a Music sequence that plays m1 followed by m2.
* @param m1 music to play first
* @param m2 music to play second
*/
public Concat(Music m1, Music m2) {
this.first = m1;
this.second = m2;
checkRep();
}
/**
* @return first piece in this concatenation
*/
public Music first() {
return first;
}
/**
* @return second piece in this concatenation
*/
public Music second() {
return second;
}
/**
* @return duration of this concatenation
*/
@Override
public double duration() {
return first.duration() + second.duration();
}
/**
* Play this concatenation.
*/
@Override
public void play(SequencePlayer player, double atBeat) {
first.play(player, atBeat);
second.play(player, atBeat + first.duration());
}
@Override
public int hashCode() {
final int prime = 31;
return first.hashCode() + prime * second.hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
final Concat other = (Concat) obj;
return first.equals(other.first) && second.equals(other.second);
}
@Override
public String toString() {
return first + " " + second;
}
}