1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.tck.testmodels.fruit; |
12 | |
|
13 | |
import java.util.Collections; |
14 | |
import java.util.HashMap; |
15 | |
import java.util.Iterator; |
16 | |
import java.util.List; |
17 | |
import java.util.Map; |
18 | |
|
19 | |
import org.apache.commons.logging.Log; |
20 | |
import org.apache.commons.logging.LogFactory; |
21 | |
|
22 | |
public class FruitBowl |
23 | |
{ |
24 | |
|
25 | |
|
26 | |
|
27 | 0 | private static final Log logger = LogFactory.getLog(FruitBowl.class); |
28 | |
|
29 | 0 | private final Map bowl = Collections.synchronizedMap(new HashMap()); |
30 | |
|
31 | |
public FruitBowl() |
32 | |
{ |
33 | 0 | super(); |
34 | 0 | } |
35 | |
|
36 | |
public FruitBowl(Fruit fruit[]) |
37 | 0 | { |
38 | 0 | for (int i = 0; i < fruit.length; i++) |
39 | |
{ |
40 | 0 | bowl.put(fruit[i].getClass(), fruit[i]); |
41 | |
} |
42 | 0 | } |
43 | |
|
44 | |
public FruitBowl(Apple apple, Banana banana) |
45 | 0 | { |
46 | 0 | bowl.put(Apple.class, apple); |
47 | 0 | bowl.put(Banana.class, banana); |
48 | 0 | } |
49 | |
|
50 | |
public boolean hasApple() |
51 | |
{ |
52 | 0 | return bowl.get(Apple.class) != null; |
53 | |
} |
54 | |
|
55 | |
public boolean hasBanana() |
56 | |
{ |
57 | 0 | return bowl.get(Banana.class) != null; |
58 | |
} |
59 | |
|
60 | |
public Object consumeFruit(FruitLover fruitlover) |
61 | |
{ |
62 | 0 | logger.debug("Got a fruit lover who says: " + fruitlover.speak()); |
63 | 0 | for (Iterator iter = bowl.values().iterator(); iter.hasNext();) |
64 | |
{ |
65 | 0 | ((Fruit) iter.next()).bite(); |
66 | |
} |
67 | 0 | return fruitlover; |
68 | |
} |
69 | |
|
70 | |
public void setFruit(Fruit[] fruit) |
71 | |
{ |
72 | 0 | for (int i = 0; i < fruit.length; i++) |
73 | |
{ |
74 | 0 | bowl.put(fruit[i].getClass(), fruit[i]); |
75 | |
} |
76 | 0 | } |
77 | |
|
78 | |
public void setFruit(List fruit) |
79 | |
{ |
80 | 0 | this.setFruit((Fruit[]) fruit.toArray(new Fruit[fruit.size()])); |
81 | 0 | } |
82 | |
|
83 | |
public Apple getApple() |
84 | |
{ |
85 | 0 | return (Apple) bowl.get(Apple.class); |
86 | |
} |
87 | |
|
88 | |
public void setApple(Apple apple) |
89 | |
{ |
90 | 0 | bowl.put(Apple.class, apple); |
91 | 0 | } |
92 | |
|
93 | |
public Banana getBanana() |
94 | |
{ |
95 | 0 | return (Banana) bowl.get(Banana.class); |
96 | |
} |
97 | |
|
98 | |
public void setBanana(Banana banana) |
99 | |
{ |
100 | 0 | bowl.put(Banana.class, banana); |
101 | 0 | } |
102 | |
|
103 | |
} |