1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.ini4j.test;
17
18 import org.ini4j.sample.Dwarf;
19 import org.ini4j.sample.Dwarfs;
20
21 import java.beans.PropertyChangeListener;
22 import java.beans.PropertyVetoException;
23 import java.beans.VetoableChangeListener;
24
25 import java.net.URI;
26
27 public final class DwarfsData implements Dwarfs
28 {
29 public static final DwarfData bashful;
30 public static final DwarfData doc;
31 public static final DwarfData dopey;
32 public static final DwarfData grumpy;
33 public static final DwarfData happy;
34 public static final DwarfData sleepy;
35 public static final DwarfData sneezy;
36 public static final Dwarfs dwarfs;
37 public static final String[] dwarfNames;
38 public static final String INI_DOPEY_WEIGHT = "${bashful/weight}";
39 public static final String INI_DOPEY_HEIGHT = "${doc/height}";
40 public static final String INI_GRUMPY_HEIGHT = "${dopey/height}";
41 public static final String INI_SLEEPY_HEIGHT = "${doc/height}8";
42 public static final String INI_SNEEZY_HOME_PAGE = "${happy/homePage}/~sneezy";
43 public static final String OPT_DOPEY_WEIGHT = "${bashful.weight}";
44 public static final String OPT_DOPEY_HEIGHT = "${doc.height}";
45 public static final String OPT_GRUMPY_HEIGHT = "${dopey.height}";
46 public static final String OPT_SLEEPY_HEIGHT = "${doc.height}8";
47 public static final String OPT_SNEEZY_HOME_PAGE = "${happy.homePage}/~sneezy";
48
49 static
50 {
51
52
53 bashful = new DwarfData(PROP_BASHFUL, 67, null, 98.8, "/home/bashful", "http://snowwhite.tale/~bashful", 45.7);
54 doc = new DwarfData(PROP_DOC, 63, null, 87.7, "c:Documents and Settingsdoc", "http://doc.dwarfs", 49.5);
55 dopey = new DwarfData(PROP_DOPEY, 23, new int[] { 11, 33, 55 }, doc.height, "c:\\Documents and Settings\\dopey", "http://dopey.snowwhite.tale/", bashful.weight);
56 grumpy = new DwarfData(PROP_GRUMPY, 76, null, dopey.height, "/home/grumpy", "http://snowwhite.tale/~grumpy/", 65.3);
57 happy = new DwarfData(PROP_HAPPY, 99, null, 77.66, "/home/happy", "http://happy.smurf", 56.4);
58 sleepy = new DwarfData(PROP_SLEEPY, 121, new int[] { 99 }, doc.height + 0.08, "/home/sleepy", "http://snowwhite.tale/~sleepy", 76.11);
59 sneezy = new DwarfData(PROP_SNEEZY, 64, new int[] { 11, 22, 33, 44 }, 76.88, "/home/sneezy", happy.homePage.toString() + "/~sneezy", 69.7);
60 dwarfs = new DwarfsData();
61 dwarfNames = new String[] { bashful.name, doc.name, dopey.name, grumpy.name, happy.name, sleepy.name, sneezy.name };
62 }
63
64 @SuppressWarnings("empty-statement")
65 private DwarfsData()
66 {
67 ;
68 }
69
70 public Dwarf getBashful()
71 {
72 return bashful;
73 }
74
75 public Dwarf getDoc()
76 {
77 return doc;
78 }
79
80 public Dwarf getDopey()
81 {
82 return dopey;
83 }
84
85 public Dwarf getGrumpy()
86 {
87 return grumpy;
88 }
89
90 public Dwarf getHappy()
91 {
92 return happy;
93 }
94
95 public Dwarf getSleepy()
96 {
97 return sleepy;
98 }
99
100 public Dwarf getSneezy()
101 {
102 return sneezy;
103 }
104
105 public static class DwarfData implements Dwarf
106 {
107 private static final String READ_ONLY_INSTANCE = "Read only instance";
108 public final int age;
109 public final int[] fortuneNumber;
110 public final double height;
111 public final String homeDir;
112 public final URI homePage;
113 public final String name;
114 public final double weight;
115
116 public DwarfData(String name, int age, int[] fortuneNumber, double height, String homeDir, String homePage, double weight)
117 {
118 this.name = name;
119 this.age = age;
120 this.fortuneNumber = fortuneNumber;
121 this.height = height;
122 this.homeDir = homeDir;
123 this.homePage = URI.create(homePage);
124 this.weight = weight;
125 }
126
127 public int getAge()
128 {
129 return age;
130 }
131
132 public void setAge(int age)
133 {
134 throw new UnsupportedOperationException(READ_ONLY_INSTANCE);
135 }
136
137 public int[] getFortuneNumber()
138 {
139 return fortuneNumber;
140 }
141
142 public void setFortuneNumber(int[] value)
143 {
144 throw new UnsupportedOperationException(READ_ONLY_INSTANCE);
145 }
146
147 public double getHeight()
148 {
149 return height;
150 }
151
152 public void setHeight(double height) throws PropertyVetoException
153 {
154 throw new UnsupportedOperationException(READ_ONLY_INSTANCE);
155 }
156
157 public String getHomeDir()
158 {
159 return homeDir;
160 }
161
162 public void setHomeDir(String dir)
163 {
164 throw new UnsupportedOperationException(READ_ONLY_INSTANCE);
165 }
166
167 public URI getHomePage()
168 {
169 return homePage;
170 }
171
172 public void setHomePage(URI location)
173 {
174 throw new UnsupportedOperationException(READ_ONLY_INSTANCE);
175 }
176
177 public double getWeight()
178 {
179 return weight;
180 }
181
182 public void setWeight(double weight)
183 {
184 throw new UnsupportedOperationException(READ_ONLY_INSTANCE);
185 }
186
187 public void addPropertyChangeListener(String property, PropertyChangeListener listener)
188 {
189 throw new UnsupportedOperationException(READ_ONLY_INSTANCE);
190 }
191
192 public void addVetoableChangeListener(String property, VetoableChangeListener listener)
193 {
194 throw new UnsupportedOperationException(READ_ONLY_INSTANCE);
195 }
196
197 public boolean hasAge()
198 {
199 return age != 0;
200 }
201
202 public boolean hasHeight()
203 {
204 return height != 0.0;
205 }
206
207 public boolean hasHomePage()
208 {
209 return homePage != null;
210 }
211
212 public boolean hasWeight()
213 {
214 return weight != 0.0;
215 }
216
217 public void removePropertyChangeListener(String property, PropertyChangeListener listener)
218 {
219 throw new UnsupportedOperationException(READ_ONLY_INSTANCE);
220 }
221
222 public void removeVetoableChangeListener(String property, VetoableChangeListener listener)
223 {
224 throw new UnsupportedOperationException(READ_ONLY_INSTANCE);
225 }
226 }
227 }