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 package com.mjh.switchrmi.protocol.xmlrpc.validator;
27
28 import java.util.*;
29
30 public class IValidatorImpl implements IValidator
31 {
32 public IValidatorImpl()
33 {
34 }
35
36 public int arrayOfStructsTest(List list)
37 {
38 int result = 0;
39 Iterator elements = list.iterator();
40
41 while (elements.hasNext())
42 {
43 Map map = (Map) elements.next();
44 Number number = (Number) map.get("curly");
45
46 if (number != null)
47 {
48 result += number.intValue();
49 }
50 }
51
52 return result;
53 }
54
55 public Map countTheEntities(String string)
56 {
57 int ctLeftAngle = 0;
58 int ctRightAngle = 0;
59 int ctAmpersands = 0;
60 int ctApostrophes = 0;
61 int ctQuotes = 0;
62
63 char[] array = string.toCharArray();
64
65 for (int i = 0; i < array.length; i++)
66 {
67 char c = array[i];
68
69 if (c == '<')
70 {
71 ctLeftAngle++;
72 }
73
74 if (c == '>')
75 {
76 ctRightAngle++;
77 }
78
79 if (c == '&')
80 {
81 ctAmpersands++;
82 }
83
84 if (c == '\'')
85 {
86 ctApostrophes++;
87 }
88
89 if (c == '"')
90 {
91 ctQuotes++;
92 }
93 }
94
95 HashMap map = new HashMap();
96
97 map.put("ctLeftAngleBrackets", new Integer(ctLeftAngle));
98 map.put("ctRightAngleBrackets", new Integer(ctRightAngle));
99 map.put("ctAmpersands", new Integer(ctAmpersands));
100 map.put("ctApostrophes", new Integer(ctApostrophes));
101 map.put("ctQuotes", new Integer(ctQuotes));
102
103
111 return map;
112 }
113
114 public int easyStructTest(Map map)
115 {
116 int result = 0;
117 Set keySet = map.keySet();
118 Iterator keys = keySet.iterator();
119
120 while (keys.hasNext())
121 {
122 String key = (String) keys.next();
123
124 if (key.equals("moe") || key.equals("larry") || key.equals("curly"))
125 {
126 Number number = (Number) map.get(key);
127
128 result += number.intValue();
129 }
130 }
131
132 return result;
133 }
134
135 public Map echoStructTest(Map map)
136 {
137 return map;
138 }
139
140 public List manyTypesTest(int number, boolean bool, String string,
141 double dbl, Date date, byte[] base64)
142 {
143 ArrayList list = new ArrayList();
144
145 list.add(new Integer(number));
146 list.add(new Boolean(bool));
147 list.add(string);
148 list.add(new Double(dbl));
149 list.add(date);
150 list.add(base64);
151
152 return list;
153 }
154
155 public String moderateSizeArrayCheck(List list)
156 {
157 String first = (String) list.get(0);
158 String last = (String) list.get(list.size() - 1);
159
160 return first + last;
161 }
162
163 public int nestedStructTest(Map map)
164 {
165 map = (Map) map.get("2000");
166 map = (Map) map.get("04");
167 map = (Map) map.get("01");
168
169 Number moe = (Number) map.get("moe");
170
171 Number larry = (Number) map.get("larry");
172 Number curly = (Number) map.get("curly");
173
174 return larry.intValue() + moe.intValue() + curly.intValue();
175 }
176
177 public Map simpleStructReturnTest(int number)
178 {
179 HashMap map = new HashMap();
180
181 map.put("times10", new Integer(number * 10));
182 map.put("times100", new Integer(number * 100));
183 map.put("times1000", new Integer(number * 1000));
184
185 return map;
186 }
187 }