Collection
Map
Iterable
List
Queue
Set
HashMap
HashSet
ArrayList
LinkedList
...
closely related
Map<String, Instructor>
Map<K, V>
values: instructor objects
keys: names
Map<String, Instructor> instructors;
instructors = new HashMap<String, Instructor>();
instructors.put("Felix", new Instructor());
instructors.put("Steve", new Instructor());
instructors.put("Meghan", new Instructor());
Instructor felix = instructors.get("Felix");
Instructor steve = instructors.get("Steve");
Instructor meghan = instructors.get("Meghan");
"Felix"
"Steve"
"Meghan"
Also preserves order.
HashSet
ArrayList
LinkedList
HashMap
public class Section {
private Collection<Topic> topics;
public Section(Collection<Topic> topics) {
this.topics = topics;
}
}
public class Topic {
private Text text;
private Video video;
public Topic(Text text, Video video) {
this.text = text;
this.video = video;
}
}
We're not going to run the code today. Instead:
Map<Course, Set<Course>>
representing those recommendations. (Create all the objects and their associations.)Map
above and why we might choose each of a Set
(as above) or a List
instead.Sample call to Course
constructor:
new Course("CPSC", 210)
Recommendations:
Map<Course, Set<Course>> recs = new HashMap<>();
Course c103 = new Course("CPSC",103), c107 = new Course("CPSC",107),
c203 = new Course("CPSC",203), c210 = new Course("CPSC",210), c213 = new Course("CPSC",213),
c221 = new Course("CPSC",221), c310 = new Course("CPSC",310);
// We show two ways to establish a recommendation set for learning..
// but consistency would be better in reality :)
Set<Course> courses = new HashSet<>();
courses.add(c213);
courses.add(c221);
courses.add(c310);
recs.put(c210, courses);
recs.put(c103, new HashSet<>());
recs.get(c103).add(c107);
recs.get(c103).add(c203);
Map
gets us easily from a taken to its recommended follow-upsSet
ensures the follow-ups for a given course are uniqueList
would let us preserve order (like for ranked recommendations).