-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMapOfList.java
More file actions
69 lines (61 loc) · 2.23 KB
/
MapOfList.java
File metadata and controls
69 lines (61 loc) · 2.23 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
package holding;
/**
* RUN:
* javac typeinfo/pets/*.java
* javac holding/MapOfList.java && java holding.MapOfList
* OUTPUT:
* People: [Person Marilyn, Person Luke, Person Kate, Person Isaac, Person Dawn]
* Pets: [[Pug Louie aka Louis Snorkelstein Dupree, Cat Stanfoed aka Stinky el Negro, Cat Pinkola], [Rat Fuzzy, Rat Fizzy], [Cat Elsie May, Dog Margrett], [Rat Freckly], [Cymric Molly, Mutt Spot]]
* Person Marilyn has:
* Pug Louie aka Louis Snorkelstein Dupree
* Cat Stanfoed aka Stinky el Negro
* Cat Pinkola
*
* Person Luke has:
* Rat Fuzzy
* Rat Fizzy
*
* Person Kate has:
* Cat Elsie May
* Dog Margrett
*
* Person Isaac has:
* Rat Freckly
*
* Person Dawn has:
* Cymric Molly
* Mutt Spot
*/
import java.util.*;
import typeinfo.pets.*;
public class MapOfList {
private static void print(Object obj) {
System.out.print(obj);
}
private static void println(Object obj) {
System.out.println(obj);
}
public static Map<Person, List<? extends Pet>> petPeople = new HashMap<Person, List<? extends Pet>>();
static {
petPeople.put(new Person("Dawn"), Arrays.asList(new Cymric("Molly"), new Mutt("Spot")));
petPeople.put(new Person("Kate"), Arrays.asList(new Cat("Elsie May"), new Dog("Margrett")));
petPeople.put(new Person("Marilyn"), Arrays.asList(
new Pug("Louie aka Louis Snorkelstein Dupree"),
new Cat("Stanfoed 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) {
println("People: " + petPeople.keySet());
println("Pets: " + petPeople.values());
for (Person person : petPeople.keySet()) {
println(person + " has: ");
for (Pet pet : petPeople.get(person)) {
println(" " + pet);
}
System.out.println();
}
}
}