Skip to content

Commit a38d13c

Browse files
rjmunroPete West
authored andcommitted
Add some more example functions
1 parent 81e04b4 commit a38d13c

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

main-module/src/main/java/com/diffblue/javatest/StringStuff.java

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,102 @@
11
package com.diffblue.javatest;
22

3+
import java.util.Locale;
4+
35
public class StringStuff {
46

7+
public static StringBuilder stringBuilderAppendZExample(Boolean x) {
8+
StringBuilder sb = new StringBuilder();
9+
if (x)
10+
sb.append(x);
11+
else
12+
sb.append(x);
13+
return sb;
14+
}
15+
16+
public static StringBuilder stringBuilderInitExample(int i) {
17+
StringBuilder sb = new StringBuilder();
18+
return sb;
19+
}
20+
21+
public static int stringBuilderLengthExample(StringBuilder s) {
22+
if (s.length() == 0)
23+
return 0;
24+
if (s.length() == 1)
25+
return 1;
26+
return s.length() + 1;
27+
}
28+
29+
public static int stringBuilderToStringExample(StringBuilder sb) {
30+
String s = sb.toString();
31+
if (s.equals("case1"))
32+
return 1;
33+
else
34+
return 2;
35+
}
36+
37+
public static char stringCharAtExample(String s) {
38+
if (s.length() <= 3)
39+
return '0';
40+
if (s.charAt(1) == 'a')
41+
return 'A';
42+
else if (s.charAt(2) == 'b')
43+
return 'B';
44+
else
45+
return s.charAt(0);
46+
}
47+
48+
public static int stringContainsExample(String s) {
49+
if (s.contains("hello"))
50+
return 0;
51+
else if (s.contains("he"))
52+
return 1;
53+
return 2;
54+
}
55+
56+
public static int stringEndsWithExample(String s) {
57+
if (s.endsWith("hello")) {
58+
if (s.length() == 10)
59+
return 0;
60+
else
61+
return 1;
62+
}
63+
if (s.endsWith("hel"))
64+
return 2;
65+
else
66+
return 3;
67+
}
68+
69+
public static int stringEqualsExample(String s) {
70+
Object x = new String("x");
71+
if (s.equals(x))
72+
return 1;
73+
else
74+
return 2;
75+
}
76+
77+
static int stringEqualsIgnoreCaseExample(String s) {
78+
String a = new String(s);
79+
if (a.equals("ABccDe"))
80+
return 0;
81+
if (a.equalsIgnoreCase("ABccDe"))
82+
return 1;
83+
return 2;
84+
}
85+
86+
public static String stringFormatLocaleExample(String s) {
87+
assert (s.length() >= 2);
88+
String r = String.format(Locale.US, "Hello %s !", s);
89+
return r;
90+
}
91+
92+
public static Boolean stringHashCodeExample(String s) {
93+
String t = "hello";
94+
if (s.hashCode() == t.hashCode())
95+
return true;
96+
else
97+
return false;
98+
}
99+
5100
public static int stringIndexOfExample(String s) {
6101
int i = s.indexOf("hello");
7102
if (i == 0)

0 commit comments

Comments
 (0)