1 |
package com.instantiations.example.miscellaneous; |
2 |
|
3 |
/** |
4 |
* The class <code>Samples</code> defines several sample methods. |
5 |
* @author Donna Devon |
6 |
*/ |
7 |
public class Samples |
8 |
{ |
9 |
public static final String ABCD = "ABCD"; |
10 |
|
11 |
public static final int XYZ = 37; |
12 |
|
13 |
public static int foo(int arg) |
14 |
{ |
15 |
if (arg == 5) { |
16 |
return 17; |
17 |
} |
18 |
if (arg == -3) { |
19 |
return 3; |
20 |
} |
21 |
return 9; |
22 |
} |
23 |
|
24 |
public static String bar(String arg) |
25 |
{ |
26 |
arg = new String(arg); |
27 |
if (arg.equals("xyz")) { |
28 |
return "abc"; |
29 |
} |
30 |
if (arg == "123") { |
31 |
return "456"; |
32 |
} else if (arg.equals(ABCD)) { |
33 |
return ABCD; |
34 |
} |
35 |
return "foo"; |
36 |
} |
37 |
|
38 |
public static String xyz(int arg) |
39 |
{ |
40 |
if (arg == 5) { |
41 |
return "abc"; |
42 |
} |
43 |
if (arg == 123) { |
44 |
return "456"; |
45 |
} else if (arg == XYZ) { |
46 |
return ABCD; |
47 |
} |
48 |
return "foo"; |
49 |
} |
50 |
|
51 |
public static int abc(int x, int y) |
52 |
{ |
53 |
if (x == 3 && y == 5) { |
54 |
return 17; |
55 |
} |
56 |
if (x == 5) { |
57 |
if (y == 7) { |
58 |
return 19; |
59 |
} else { |
60 |
return 21; |
61 |
} |
62 |
} else if (x == 7) { |
63 |
if (y == 7) { |
64 |
return 23; |
65 |
} else { |
66 |
return 25; |
67 |
} |
68 |
} |
69 |
return -1; |
70 |
} |
71 |
|
72 |
public static int map(int index) |
73 |
{ |
74 |
switch (index) { |
75 |
case 0: |
76 |
case10: |
77 |
return -1; |
78 |
case 2: |
79 |
case 20: |
80 |
break; |
81 |
default: |
82 |
return -2; |
83 |
} |
84 |
return 0; |
85 |
} |
86 |
|
87 |
public int testStrings(String p1, String p2) |
88 |
{ |
89 |
if (p1 == null) { |
90 |
return 0; |
91 |
} else if (p2 == null) { |
92 |
return 1; |
93 |
} |
94 |
if (p1.compareTo("TOMCAT")== 0) { |
95 |
return 2; |
96 |
} |
97 |
return 65000; |
98 |
} |
99 |
|
100 |
public static boolean startsWith(String str, String match) |
101 |
{ |
102 |
for (int i = 0; i < match.length(); ++i) { |
103 |
if (str.charAt(i) != match.charAt(i)) { |
104 |
return false; |
105 |
} |
106 |
} |
107 |
return true; |
108 |
} |
109 |
|
110 |
/** |
111 |
* After generating tests for this class, change the "+" to a "-" to see |
112 |
* that the tests are adequate. |
113 |
*/ |
114 |
public static int add(int i1, int i2) |
115 |
{ |
116 |
return i1 + i2; |
117 |
} |
118 |
|
119 |
/** |
120 |
* Demonstrates how empty methods are handled. (There is a preference |
121 |
* setting that will cause empty methods to be ignored.) |
122 |
*/ |
123 |
public static void emptyMethod(int input) |
124 |
{ |
125 |
// This method intentionally left blank. |
126 |
} |
127 |
} |