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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
|
/*
Derby - Class org.apache.derbyTesting.functionTests.util.ManyMethods
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.apache.derbyTesting.functionTests.util;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.math.BigDecimal;
import java.io.Serializable;
import java.util.Calendar;
/**
* This class is for testing method calls on user-defined types. It has
* many different methods for testing different cases.
*/
public class ManyMethods implements Serializable
{
int value;
protected int protectedValue;
private int privateValue;
public int publicValue;
public short publicshort;
public Short publicShort;
public byte publicbyte;
public Byte publicByte;
public int publicint;
public Integer publicInteger;
public long publiclong;
public Long publicLong;
public boolean publicboolean;
public Boolean publicBoolean;
public float publicfloat;
public Float publicFloat;
public double publicdouble;
public Double publicDouble;
public String publicString;
public Date publicDate;
public Time publicTime;
public Timestamp publicTimestamp;
public ManyMethods myself;
public static int NONOVERLOADED_INTSTATIC = 1;
public static int OVERLOADED_INTSTATIC = 1;
public static int OVEROVERLOADED_INTSTATIC = 1;
public ManyMethods(int value)
{
this.value = value;
this.myself = this;
protectedValue = value;
privateValue = value;
publicValue = value;
publicint = value;
publicInteger = value;
publicshort = (short) value;
publicShort = (short) value;
publicbyte = (byte) value;
publicByte = (byte) value;
publiclong = (long) value;
publicLong = (long) value;
publicboolean = booleanMethod();
publicBoolean = BooleanMethod();
publicfloat = floatMethod();
publicFloat = FloatMethod();
publicdouble = doubleMethod();
publicDouble = DoubleMethod();
publicString = StringMethod();
publicDate = DateMethod();
publicTime = TimeMethod();
publicTimestamp = TimestampMethod();
}
/*
** The following methods are for testing signature matching. Each method
** takes a single parameter. The parameter types vary by method. All
** of the Java primitive types are covered as well as their wrapper classes.
** All of the Java classes corresponding to the currently supported SQL
** types are covered.
*/
public String parmType(byte value)
{
return "byte parameter";
}
public String parmType(byte[][][] value)
{
return "byte[][][] parameter";
}
public String parmType(Byte value)
{
return "java.lang.Byte parameter";
}
public String parmType(char value)
{
return "char parameter";
}
public String parmType(Character value)
{
return "java.lang.Character parameter";
}
public String parmType(double value)
{
return "double parameter";
}
public String parmType(Double value)
{
return "java.lang.Double parameter";
}
public String parmType(BigDecimal value)
{
return "java.math.BigDecimal parameter";
}
public String parmType(float value)
{
return "float parameter";
}
public String parmType(Float value)
{
return "java.lang.Float parameter";
}
public String parmType(int value)
{
return "int parameter";
}
public String parmType(Integer value)
{
return "java.lang.Integer parameter";
}
public String parmType(long value)
{
return "long parameter";
}
public String parmType(Long value)
{
return "java.lang.Long parameter";
}
public String parmType(short value)
{
return "short parameter";
}
public String parmType(Short value)
{
return "java.lang.Short parameter";
}
public String parmType(boolean value)
{
return "boolean parameter";
}
public String parmType(Boolean value)
{
return "java.lang.Boolean parameter";
}
public String parmType(String value)
{
return "java.lang.String parameter";
}
public String parmType(Date value)
{
return "java.sql.Date parameter";
}
public String parmType(Time value)
{
return "java.sql.Time parameter";
}
public String parmType(Timestamp value)
{
return "java.sql.Timestamp parameter";
}
/*
** The following methods return all of the java primitive types and
** their wrapper classes, plus all of the types corresponding to the
** built-in SQL types.
*/
public byte byteMethod()
{
return 1;
}
public byte[][][] byteArrayArrayArrayMethod()
{
return new byte[3][][];
}
public Byte ByteMethod()
{
return (byte) 1;
}
public char charMethod()
{
return 'a';
}
public Character CharacterMethod()
{
return 'a';
}
public double doubleMethod()
{
return 1.5;
}
public Double DoubleMethod()
{
return 1.5;
}
public BigDecimal BigDecimalMethod()
{
return new BigDecimal(1.4d);
}
public float floatMethod()
{
return 2.5F;
}
public Float FloatMethod()
{
return 2.5F;
}
public int intMethod()
{
return 2;
}
public Integer IntegerMethod()
{
return 2;
}
public long longMethod()
{
return 3L;
}
public Long LongMethod()
{
return 3L;
}
public short shortMethod()
{
return (short) 4;
}
public Short ShortMethod()
{
return (short) 4;
}
public boolean booleanMethod()
{
return true;
}
public Boolean BooleanMethod()
{
return true;
}
public String StringMethod()
{
return "A String";
}
public Date DateMethod()
{
/* July 2, 1997 */
// deprecated...note, that it was actually august, not july.
// return new Date(97, 7, 2);
return new Date(870505200000L);
}
public Time TimeMethod()
{
/* 10:58:33 AM */
// deprecated...
// return new Time(10, 58, 33);
return new Time(68313000L);
}
public Timestamp TimestampMethod()
{
/* July 2, 1997 10:59:15.0 AM */
// deprecated...note, actually August, not July, 1997
// return new Timestamp(97, 7, 2, 10, 59, 15, 0);
return new Timestamp(870544755000L);
}
public ManyMethods ManyMethodsMethod()
{
return this;
}
/*
** The following methods are for testing null arguments. These methods
** return Strings with the names of the parameter types, so we can be
** sure the right method was called.
*/
public String isNull(Boolean value)
{
if (value == null)
return "Boolean is null";
else
return "Boolean is not null";
}
public String isNull(String value)
{
if (value == null)
return "String is null";
else
return "String is not null";
}
public String isNull(Double value)
{
if (value == null)
return "Double is null";
else
return "Double is not null";
}
public String isNull(BigDecimal value)
{
if (value == null)
return "BigDecimal is null";
else
return "BigDecimal is not null";
}
public String isNull(Integer value)
{
if (value == null)
return "Integer is null";
else
return "Integer is not null";
}
public String isNull(Float value)
{
if (value == null)
return "Float is null";
else
return "Float is not null";
}
public String isNull(Short value)
{
if (value == null)
return "Short is null";
else
return "Short is not null";
}
public String isNull(Date value)
{
if (value == null)
return "Date is null";
else
return "Date is not null";
}
public String isNull(Time value)
{
if (value == null)
return "Time is null";
else
return "Time is not null";
}
public String isNull(Timestamp value)
{
if (value == null)
return "Timestamp is null";
else
return "Timestamp is not null";
}
/* Methods with more than one parameter */
public String integerFloatDouble(Integer parm1, Float parm2, Double parm3)
{
return "integerFloatDouble method";
}
public String stringDateTimeTimestamp(String parm1, Date parm2, Time parm3,
Timestamp parm4)
{
return "stringDateTimeTimestamp method";
}
/* Static methods */
public static int staticMethod()
{
return 1;
}
public static int overloadedStaticMethod()
{
return 1;
}
public static int overOverloadedStaticMethod()
{
return 1;
}
public static Byte staticByteMethod()
{
return (byte) 1;
}
public static Character staticCharacterMethod()
{
return 'a';
}
public static Double staticDoubleMethod()
{
return 1.5;
}
public static BigDecimal staticBigDecimalMethod()
{
return new BigDecimal(1.1d);
}
public static Float staticFloatMethod()
{
return 2.5F;
}
public static Long staticLongMethod()
{
return 3L;
}
public static Short staticShortMethod()
{
return (short) 4;
}
public static Integer staticIntegerMethod()
{
return 2;
}
public static Boolean staticBooleanMethod()
{
return true;
}
public static String staticStringMethod()
{
return "A String";
}
public static Date staticDateMethod()
{
/* August 2, 1997 */
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(1997, Calendar.AUGUST, 2, 0, 0, 0);
return new Date(cal.getTimeInMillis());
}
public static Time staticTimeMethod()
{
/* 10:58:33 AM */
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(1970, Calendar.JANUARY, 1, 10, 58, 33);
return new Time(cal.getTimeInMillis());
}
public static Timestamp staticTimestampMethod()
{
/* August 2, 1997 10:59:15.0 AM */
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(1997, Calendar.AUGUST, 2, 10, 59, 15);
return new Timestamp(cal.getTimeInMillis());
}
public static ManyMethods staticManyMethods(Integer value)
{
return new ManyMethods(value.intValue());
}
/* "Cast to sub class" */
public SubClass subClass()
{
if (this instanceof SubClass)
{
return (SubClass) this;
}
else
{
return null;
}
}
public int[] getIntArray() {
return new int[0];
}
public Object[] getObjectArray() {
return new String[0];
}
/* Methods for negative testing */
protected int protectedMethod()
{
return 1;
}
private int privateMethod()
{
return 1;
}
int packageMethod()
{
return 1;
}
public int exceptionMethod() throws Throwable
{
throw new Throwable("This exception should be caught by the runtime system.");
}
/*
** Some methods for testing interface resolution
*/
public static NoMethodInterface getNoMethodInterface() {
return new SubInterfaceClass(67);
}
public static Runnable getRunnable() {
return new SubInterfaceClass(89);
}
public static ExtendingInterface getExtendingInterface() {
return new SubInterfaceClass(235);
}
}
|