KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > util > ManyMethods


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.util.ManyMethods
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derbyTesting.functionTests.util;
23
24 import java.sql.Date JavaDoc;
25 import java.sql.Time JavaDoc;
26 import java.sql.Timestamp JavaDoc;
27
28 import java.math.BigDecimal JavaDoc;
29
30 import java.io.Serializable JavaDoc;
31
32 /**
33  * This class is for testing method calls on user-defined types. It has
34  * many different methods for testing different cases.
35  */

36
37 public class ManyMethods implements Serializable JavaDoc
38 {
39
40     int value;
41     protected int protectedValue;
42     private int privateValue;
43     public int publicValue;
44     public short publicshort;
45     public Short JavaDoc publicShort;
46     public byte publicbyte;
47     public Byte JavaDoc publicByte;
48     public int publicint;
49     public Integer JavaDoc publicInteger;
50     public long publiclong;
51     public Long JavaDoc publicLong;
52     public boolean publicboolean;
53     public Boolean JavaDoc publicBoolean;
54     public float publicfloat;
55     public Float JavaDoc publicFloat;
56     public double publicdouble;
57     public Double JavaDoc publicDouble;
58     public String JavaDoc publicString;
59     public Date JavaDoc publicDate;
60     public Time JavaDoc publicTime;
61     public Timestamp JavaDoc publicTimestamp;
62     public ManyMethods myself;
63
64     public static int NONOVERLOADED_INTSTATIC = 1;
65     public static int OVERLOADED_INTSTATIC = 1;
66     public static int OVEROVERLOADED_INTSTATIC = 1;
67
68     public ManyMethods(int value)
69     {
70         this.value = value;
71         this.myself = this;
72         protectedValue = value;
73         privateValue = value;
74         publicValue = value;
75         publicint = value;
76         publicInteger = new Integer JavaDoc(value);
77         publicshort = (short) value;
78         publicShort = new Short JavaDoc((short) value);
79         publicbyte = (byte) value;
80         publicByte = new Byte JavaDoc((byte) value);
81         publiclong = (long) value;
82         publicLong = new Long JavaDoc((long) value);
83         publicboolean = booleanMethod();
84         publicBoolean = BooleanMethod();
85         publicfloat = floatMethod();
86         publicFloat = FloatMethod();
87         publicdouble = doubleMethod();
88         publicDouble = DoubleMethod();
89         publicString = StringMethod();
90         publicDate = DateMethod();
91         publicTime = TimeMethod();
92         publicTimestamp = TimestampMethod();
93     }
94
95     /*
96     ** The following methods are for testing signature matching. Each method
97     ** takes a single parameter. The parameter types vary by method. All
98     ** of the Java primitive types are covered as well as their wrapper classes.
99     ** All of the Java classes corresponding to the currently supported SQL
100     ** types are covered.
101     */

102
103     public String JavaDoc parmType(byte value)
104     {
105         return "byte parameter";
106     }
107
108     public String JavaDoc parmType(byte[][][] value)
109     {
110         return "byte[][][] parameter";
111     }
112
113     public String JavaDoc parmType(Byte JavaDoc value)
114     {
115         return "java.lang.Byte parameter";
116     }
117
118     public String JavaDoc parmType(char value)
119     {
120         return "char parameter";
121     }
122
123     public String JavaDoc parmType(Character JavaDoc value)
124     {
125         return "java.lang.Character parameter";
126     }
127
128     public String JavaDoc parmType(double value)
129     {
130         return "double parameter";
131     }
132
133     public String JavaDoc parmType(Double JavaDoc value)
134     {
135         return "java.lang.Double parameter";
136     }
137
138     public String JavaDoc parmType(BigDecimal JavaDoc value)
139     {
140         return "java.math.BigDecimal parameter";
141     }
142
143     public String JavaDoc parmType(float value)
144     {
145         return "float parameter";
146     }
147
148     public String JavaDoc parmType(Float JavaDoc value)
149     {
150         return "java.lang.Float parameter";
151     }
152
153     public String JavaDoc parmType(int value)
154     {
155         return "int parameter";
156     }
157
158     public String JavaDoc parmType(Integer JavaDoc value)
159     {
160         return "java.lang.Integer parameter";
161     }
162
163     public String JavaDoc parmType(long value)
164     {
165         return "long parameter";
166     }
167
168     public String JavaDoc parmType(Long JavaDoc value)
169     {
170         return "java.lang.Long parameter";
171     }
172
173     public String JavaDoc parmType(short value)
174     {
175         return "short parameter";
176     }
177
178     public String JavaDoc parmType(Short JavaDoc value)
179     {
180         return "java.lang.Short parameter";
181     }
182
183     public String JavaDoc parmType(boolean value)
184     {
185         return "boolean parameter";
186     }
187
188     public String JavaDoc parmType(Boolean JavaDoc value)
189     {
190         return "java.lang.Boolean parameter";
191     }
192
193     public String JavaDoc parmType(String JavaDoc value)
194     {
195         return "java.lang.String parameter";
196     }
197
198     public String JavaDoc parmType(Date JavaDoc value)
199     {
200         return "java.sql.Date parameter";
201     }
202
203     public String JavaDoc parmType(Time JavaDoc value)
204     {
205         return "java.sql.Time parameter";
206     }
207
208     public String JavaDoc parmType(Timestamp JavaDoc value)
209     {
210         return "java.sql.Timestamp parameter";
211     }
212
213     /*
214     ** The following methods return all of the java primitive types and
215     ** their wrapper classes, plus all of the types corresponding to the
216     ** built-in SQL types.
217     */

218     public byte byteMethod()
219     {
220         return 1;
221     }
222
223     public byte[][][] byteArrayArrayArrayMethod()
224     {
225         return new byte[3][][];
226     }
227
228     public Byte JavaDoc ByteMethod()
229     {
230         return new Byte JavaDoc((byte) 1);
231     }
232
233     public char charMethod()
234     {
235         return 'a';
236     }
237
238     public Character JavaDoc CharacterMethod()
239     {
240         return new Character JavaDoc('a');
241     }
242
243     public double doubleMethod()
244     {
245         return 1.5;
246     }
247
248     public Double JavaDoc DoubleMethod()
249     {
250         return new Double JavaDoc(1.5);
251     }
252
253     public BigDecimal JavaDoc BigDecimalMethod()
254     {
255         return new BigDecimal JavaDoc(1.4d);
256     }
257
258     public float floatMethod()
259     {
260         return 2.5F;
261     }
262
263     public Float JavaDoc FloatMethod()
264     {
265         return new Float JavaDoc(2.5F);
266     }
267
268     public int intMethod()
269     {
270         return 2;
271     }
272
273     public Integer JavaDoc IntegerMethod()
274     {
275         return new Integer JavaDoc(2);
276     }
277
278     public long longMethod()
279     {
280         return 3L;
281     }
282
283     public Long JavaDoc LongMethod()
284     {
285         return new Long JavaDoc(3L);
286     }
287
288     public short shortMethod()
289     {
290         return (short) 4;
291     }
292
293     public Short JavaDoc ShortMethod()
294     {
295         return new Short JavaDoc((short) 4);
296     }
297
298     public boolean booleanMethod()
299     {
300         return true;
301     }
302
303     public Boolean JavaDoc BooleanMethod()
304     {
305         return new Boolean JavaDoc(true);
306     }
307
308     public String JavaDoc StringMethod()
309     {
310         return "A String";
311     }
312
313     public Date JavaDoc DateMethod()
314     {
315         /* July 2, 1997 */
316         // deprecated...note, that it was actually august, not july.
317
// return new Date(97, 7, 2);
318
return new Date JavaDoc(870505200000L);
319     }
320
321     public Time JavaDoc TimeMethod()
322     {
323         /* 10:58:33 AM */
324         // deprecated...
325
// return new Time(10, 58, 33);
326
return new Time JavaDoc(68313000L);
327     }
328
329     public Timestamp JavaDoc TimestampMethod()
330     {
331         /* July 2, 1997 10:59:15.0 AM */
332         // deprecated...note, actually August, not July, 1997
333
// return new Timestamp(97, 7, 2, 10, 59, 15, 0);
334
return new Timestamp JavaDoc(870544755000L);
335     }
336
337     public ManyMethods ManyMethodsMethod()
338     {
339         return this;
340     }
341
342     /*
343     ** The following methods are for testing null arguments. These methods
344     ** return Strings with the names of the parameter types, so we can be
345     ** sure the right method was called.
346     */

347     public String JavaDoc isNull(Boolean JavaDoc value)
348     {
349         if (value == null)
350             return "Boolean is null";
351         else
352             return "Boolean is not null";
353     }
354
355     public String JavaDoc isNull(String JavaDoc value)
356     {
357         if (value == null)
358             return "String is null";
359         else
360             return "String is not null";
361     }
362
363     public String JavaDoc isNull(Double JavaDoc value)
364     {
365         if (value == null)
366             return "Double is null";
367         else
368             return "Double is not null";
369     }
370
371     public String JavaDoc isNull(BigDecimal JavaDoc value)
372     {
373         if (value == null)
374             return "BigDecimal is null";
375         else
376             return "BigDecimal is not null";
377     }
378
379     public String JavaDoc isNull(Integer JavaDoc value)
380     {
381         if (value == null)
382             return "Integer is null";
383         else
384             return "Integer is not null";
385     }
386
387     public String JavaDoc isNull(Float JavaDoc value)
388     {
389         if (value == null)
390             return "Float is null";
391         else
392             return "Float is not null";
393     }
394
395     public String JavaDoc isNull(Short JavaDoc value)
396     {
397         if (value == null)
398             return "Short is null";
399         else
400             return "Short is not null";
401     }
402
403     public String JavaDoc isNull(Date JavaDoc value)
404     {
405         if (value == null)
406             return "Date is null";
407         else
408             return "Date is not null";
409     }
410
411     public String JavaDoc isNull(Time JavaDoc value)
412     {
413         if (value == null)
414             return "Time is null";
415         else
416             return "Time is not null";
417     }
418
419     public String JavaDoc isNull(Timestamp JavaDoc value)
420     {
421         if (value == null)
422             return "Timestamp is null";
423         else
424             return "Timestamp is not null";
425     }
426
427     /* Methods with more than one parameter */
428     public String JavaDoc integerFloatDouble(Integer JavaDoc parm1, Float JavaDoc parm2, Double JavaDoc parm3)
429     {
430         return "integerFloatDouble method";
431     }
432
433     public String JavaDoc stringDateTimeTimestamp(String JavaDoc parm1, Date JavaDoc parm2, Time JavaDoc parm3,
434                                             Timestamp JavaDoc parm4)
435     {
436         return "stringDateTimeTimestamp method";
437     }
438
439     /* Static methods */
440     public static int staticMethod()
441     {
442         return 1;
443     }
444
445     public static int overloadedStaticMethod()
446     {
447         return 1;
448     }
449
450     public static int overOverloadedStaticMethod()
451     {
452         return 1;
453     }
454
455     public static Byte JavaDoc staticByteMethod()
456     {
457         return new Byte JavaDoc((byte) 1);
458     }
459
460     public static Character JavaDoc staticCharacterMethod()
461     {
462         return new Character JavaDoc('a');
463     }
464
465     public static Double JavaDoc staticDoubleMethod()
466     {
467         return new Double JavaDoc(1.5);
468     }
469
470     public static BigDecimal JavaDoc staticBigDecimalMethod()
471     {
472         return new BigDecimal JavaDoc(1.1d);
473     }
474
475     public static Float JavaDoc staticFloatMethod()
476     {
477         return new Float JavaDoc(2.5F);
478     }
479
480     public static Long JavaDoc staticLongMethod()
481     {
482         return new Long JavaDoc(3L);
483     }
484
485     public static Short JavaDoc staticShortMethod()
486     {
487         return new Short JavaDoc((short) 4);
488     }
489
490     public static Integer JavaDoc staticIntegerMethod()
491     {
492         return new Integer JavaDoc(2);
493     }
494
495     public static Boolean JavaDoc staticBooleanMethod()
496     {
497         return new Boolean JavaDoc(true);
498     }
499
500     public static String JavaDoc staticStringMethod()
501     {
502         return "A String";
503     }
504
505     public static Date JavaDoc staticDateMethod()
506     {
507         /* July 2, 1997 */
508         return new Date JavaDoc(97, 7, 2);
509     }
510
511     public static Time JavaDoc staticTimeMethod()
512     {
513         /* 10:58:33 AM */
514         return new Time JavaDoc(10, 58, 33);
515     }
516
517     public static Timestamp JavaDoc staticTimestampMethod()
518     {
519         /* July 2, 1997 10:59:15.0 AM */
520         return new Timestamp JavaDoc(97, 7, 2, 10, 59, 15, 0);
521     }
522
523     public static ManyMethods staticManyMethods(Integer JavaDoc value)
524     {
525         return new ManyMethods(value.intValue());
526     }
527
528     /* "Cast to sub class" */
529     public SubClass subClass()
530     {
531         if (this instanceof SubClass)
532         {
533             return (SubClass) this;
534         }
535         else
536         {
537             return null;
538         }
539     }
540
541     public int[] getIntArray() {
542         return new int[0];
543     }
544
545     public Object JavaDoc[] getObjectArray() {
546         return new String JavaDoc[0];
547     }
548
549     /* Methods for negative testing */
550     protected int protectedMethod()
551     {
552         return 1;
553     }
554
555     private int privateMethod()
556     {
557         return 1;
558     }
559
560     int packageMethod()
561     {
562         return 1;
563     }
564
565     public int exceptionMethod() throws Throwable JavaDoc
566     {
567         throw new Throwable JavaDoc("This exception should be caught by the runtime system.");
568     }
569
570     /*
571     ** Some methods for testing interface resolution
572     */

573
574     public static NoMethodInterface getNoMethodInterface() {
575         return new SubInterfaceClass(67);
576     }
577     public static Runnable JavaDoc getRunnable() {
578         return new SubInterfaceClass(89);
579     }
580     public static ExtendingInterface getExtendingInterface() {
581         return new SubInterfaceClass(235);
582     }
583 }
584
Popular Tags