-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMapOfList.java
More file actions
44 lines (39 loc) · 1.47 KB
/
MapOfList.java
File metadata and controls
44 lines (39 loc) · 1.47 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
package thinkinginjava.holding;
import static thinkinginjava.util.Print.print;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import thinkinginjava.typeinfo.pets.Cat;
import thinkinginjava.typeinfo.pets.Cymric;
import thinkinginjava.typeinfo.pets.Dog;
import thinkinginjava.typeinfo.pets.Mutt;
import thinkinginjava.typeinfo.pets.Person;
import thinkinginjava.typeinfo.pets.Pet;
import thinkinginjava.typeinfo.pets.Pug;
import thinkinginjava.typeinfo.pets.Rat;
public class MapOfList {
public static Map<Person, List<? extends Pet>> petPeople = new HashMap<Person, List<? extends Pet>>();
// static chunk
static {
petPeople.put(new Person("Dawn"),
Arrays.asList(new Cymric("Molly"), new Mutt("Spot")));
petPeople.put(new Person("Kate"), Arrays.asList(new Cat("Shackleton"),
new Cat("Elsie May"), new Dog("Margrett")));
petPeople.put(new Person("Marilyn"), Arrays.asList(new Pug(
"Louie aka Louis Snorkelstein Dupree"), new Cat(
"Stanford aka Stinky el Negro"), new Cat("Pinkola")));
petPeople.put(new Person("Luke"),
Arrays.asList(new Rat("Fuzzy"), new Rat("Fizzy")));
petPeople.put(new Person("Isaac"), Arrays.asList(new Rat("Freckly")));
}
public static void main(String[] args) {
print("People: " + petPeople.keySet());
print("Pets: " + petPeople.values());
for (Person person : petPeople.keySet()) {
print(person + " has:");
for (Pet pet : petPeople.get(person))
print(" " + pet);
}
}
}