1 | /**
|
---|
2 | *
|
---|
3 | */
|
---|
4 | package bargainingchips;
|
---|
5 |
|
---|
6 | import java.util.Collections;
|
---|
7 | import java.util.HashMap;
|
---|
8 | import java.util.Iterator;
|
---|
9 | import java.util.Map;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * This class contains useful functions in dealing with values related to {@link Chip},
|
---|
13 | * i.e., issue values.
|
---|
14 | * For example, BreakEvenPrices, Deviation of Quantities, etc. are defined of this type.
|
---|
15 | *
|
---|
16 | * @author Faria Nassiri-Mofakham
|
---|
17 | *
|
---|
18 | */
|
---|
19 | public class ChipIssueValue<T> implements Iterable<Chip>
|
---|
20 | {
|
---|
21 | protected Map<Chip, T> i;
|
---|
22 |
|
---|
23 | public ChipIssueValue()
|
---|
24 | {
|
---|
25 | i = new HashMap<Chip, T>();
|
---|
26 | }
|
---|
27 |
|
---|
28 | public ChipIssueValue(Map<Chip, T> values)
|
---|
29 | {
|
---|
30 | Map<Chip, T> tmpListOfHolding = new HashMap<Chip,T>();
|
---|
31 | tmpListOfHolding.putAll(values);
|
---|
32 | this.i = Collections.unmodifiableMap(tmpListOfHolding);
|
---|
33 | }
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * @return the issue value of Chip, in type T
|
---|
37 | */
|
---|
38 | public T getUnitValue(Chip c)
|
---|
39 | {
|
---|
40 | return i.get(c);
|
---|
41 | }
|
---|
42 |
|
---|
43 |
|
---|
44 | // private String writeT<T[]>()
|
---|
45 | // {
|
---|
46 | // String s = "";
|
---|
47 | // T[] j;
|
---|
48 | // for (Chip c: t.keySet())
|
---|
49 | // {
|
---|
50 | // j= t.get(c);
|
---|
51 | // System.out.println("j: "+j);
|
---|
52 | // for (int k=0; k<j.length; k++)
|
---|
53 | // s += j[k].toString();
|
---|
54 | // }
|
---|
55 | // return s;
|
---|
56 | // }
|
---|
57 |
|
---|
58 | // private String writeT(ChipIssueValue<T[]> t)
|
---|
59 | // {
|
---|
60 | // String s = "";
|
---|
61 | // T[] j;
|
---|
62 | // for (Chip c: t)
|
---|
63 | // {
|
---|
64 | // j= t.getUnitValue(c);
|
---|
65 | // //System.out.println("j: "+j);
|
---|
66 | // for (int k=0; k<j.length; k++)
|
---|
67 | // s += j[k].toString()+" ";
|
---|
68 | // }
|
---|
69 | // return s;
|
---|
70 | // }
|
---|
71 |
|
---|
72 |
|
---|
73 | @Override
|
---|
74 | public Iterator<Chip> iterator()
|
---|
75 | {
|
---|
76 | return i.keySet().iterator();
|
---|
77 | }
|
---|
78 |
|
---|
79 | @Override
|
---|
80 | public String toString()
|
---|
81 | {
|
---|
82 | return i.toString();
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 | public static <Int> void main(String[] args)
|
---|
87 | {
|
---|
88 | ChipIssueValue<Double> priceDev = new ChipIssueValueBuilder()
|
---|
89 | .addIssue("Red", 7.0)
|
---|
90 | .addIssue("Green", 3.0)
|
---|
91 | .addIssue("Purple", 2.0)
|
---|
92 | .build();
|
---|
93 |
|
---|
94 | ChipIssueValue<Int> qtyDev = new ChipIssueValueBuilder()
|
---|
95 | .addIssue("Red", 3)
|
---|
96 | .addIssue("Yellow", 1)
|
---|
97 | .addIssue("Green", 1)
|
---|
98 | .build();
|
---|
99 |
|
---|
100 | System.out.println("`Double' Standard deviation of Chips prices are: "+priceDev);
|
---|
101 | System.out.println("`Int' Standard deviation of Chips quantities are: "+qtyDev);
|
---|
102 | }
|
---|
103 |
|
---|
104 |
|
---|
105 | }
|
---|
106 |
|
---|
107 |
|
---|