-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathAlbum.java
More file actions
81 lines (66 loc) · 1.91 KB
/
Copy pathAlbum.java
File metadata and controls
81 lines (66 loc) · 1.91 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
74
75
76
77
78
79
80
81
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.insightfullogic.java8.examples.chapter1;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;
import static java.util.Collections.unmodifiableList;
import static java.util.stream.Collectors.toList;
/**
*
* @author richard
*/
public final class Album implements Performance {
private final String name;
private final List<Track> tracks;
private final List<Artist> musicians;
public Album(String name, List<Track> tracks, List<Artist> musicians) {
Objects.requireNonNull(name);
Objects.requireNonNull(tracks);
Objects.requireNonNull(musicians);
this.name = name;
this.tracks = new ArrayList<>(tracks);
this.musicians = new ArrayList<>(musicians);
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @return the tracks
*/
public Stream<Track> getTracks() {
return tracks.stream();
}
/**
* Used in imperative code examples that need to iterate over a list
*/
public List<Track> getTrackList() {
return unmodifiableList(tracks);
}
/**
* @return the musicians
*/
public Stream<Artist> getMusicians() {
return musicians.stream();
}
/**
* Used in imperative code examples that need to iterate over a list
*/
public List<Artist> getMusicianList() {
return unmodifiableList(musicians);
}
public Artist getMainMusician() {
return musicians.get(0);
}
public Album copy() {
List<Track> copiesTracks = getTracks().map(Track::copy).collect(toList());
List<Artist> copiesMusicians = getMusicians().map(Artist::copy).collect(toList());
return new Album(name, copiesTracks, copiesMusicians);
}
}