Skip to content

Commit e0bf41e

Browse files
committed
clean code
1 parent f26c5f4 commit e0bf41e

11 files changed

Lines changed: 417 additions & 458 deletions

File tree

jdk_8_maven/cs/rpc/thrift/artificial/thrift-scs/src/main/java/org/thrift/scs/imp/Calc.java

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,45 +15,35 @@
1515

1616
package org.thrift.scs.imp;
1717

18-
public class Calc
19-
{
20-
public static String subject(String op, double arg1 , double arg2 )
21-
{
22-
op = op.toLowerCase();
23-
double result = 0.0;
24-
if ("pi".equals(op)) { //CONSTANT OPERATOR
25-
result = Math.PI;
26-
}
27-
else if ("e".equals(op)) {
28-
result = Math.E;
29-
} //UNARY OPERATOR
30-
else if ("sqrt".equals(op)) {
31-
result = Math.sqrt(arg1);
32-
}
33-
else if ("log".equals(op)) {
34-
result = Math.log(arg1);
35-
}
36-
else if ("sine".equals(op)) {
37-
result = Math.sin(arg1);
38-
}
39-
else if ("cosine".equals(op)) {
40-
result = Math.cos(arg1);
41-
}
42-
else if ("tangent".equals(op)) {
43-
result = Math.tan(arg1);
44-
} //BINARY OPERATOR
45-
else if ("plus".equals(op)) {
46-
result = arg1 + arg2;
47-
}
48-
else if ("subtract".equals(op)) {
49-
result = arg1 - arg2;
50-
}
51-
else if ("multiply".equals(op)) {
52-
result = arg1 * arg2;
53-
}
54-
else if ("divide".equals(op)) {
55-
result = arg1 / arg2;
56-
}
57-
return "" + result;
58-
}
18+
public class Calc {
19+
public static String subject(String op, double arg1, double arg2) {
20+
op = op.toLowerCase();
21+
double result = 0.0;
22+
if ("pi".equals(op)) { //CONSTANT OPERATOR
23+
result = Math.PI;
24+
} else if ("e".equals(op)) {
25+
result = Math.E;
26+
} //UNARY OPERATOR
27+
else if ("sqrt".equals(op)) {
28+
result = Math.sqrt(arg1);
29+
} else if ("log".equals(op)) {
30+
result = Math.log(arg1);
31+
} else if ("sine".equals(op)) {
32+
result = Math.sin(arg1);
33+
} else if ("cosine".equals(op)) {
34+
result = Math.cos(arg1);
35+
} else if ("tangent".equals(op)) {
36+
result = Math.tan(arg1);
37+
} //BINARY OPERATOR
38+
else if ("plus".equals(op)) {
39+
result = arg1 + arg2;
40+
} else if ("subtract".equals(op)) {
41+
result = arg1 - arg2;
42+
} else if ("multiply".equals(op)) {
43+
result = arg1 * arg2;
44+
} else if ("divide".equals(op)) {
45+
result = arg1 / arg2;
46+
}
47+
return "" + result;
48+
}
5949
}

jdk_8_maven/cs/rpc/thrift/artificial/thrift-scs/src/main/java/org/thrift/scs/imp/Cookie.java

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,25 @@
1414

1515
package org.thrift.scs.imp;
1616

17-
public class Cookie
18-
{
19-
public static String subject(String name, String val, String site)
20-
{
21-
name = name.toLowerCase();
22-
val = val.toLowerCase();
23-
site = site.toLowerCase();
24-
int result = 0;
25-
if ("userid".equals(name)) {
26-
if (val.length() > 6) {
27-
if ("user".equals(val.substring(0, 4))) {
28-
result = 1;
29-
}
30-
}
31-
}
32-
else if ("session".equals(name)) {
33-
if ("am".equals(val) && "abc.com".equals(site)) {
34-
result = 1;
35-
}
36-
else {
37-
result = 2;
38-
}
39-
}
40-
return "" + result;
41-
}
17+
public class Cookie {
18+
public static String subject(String name, String val, String site) {
19+
name = name.toLowerCase();
20+
val = val.toLowerCase();
21+
site = site.toLowerCase();
22+
int result = 0;
23+
if ("userid".equals(name)) {
24+
if (val.length() > 6) {
25+
if ("user".equals(val.substring(0, 4))) {
26+
result = 1;
27+
}
28+
}
29+
} else if ("session".equals(name)) {
30+
if ("am".equals(val) && "abc.com".equals(site)) {
31+
result = 1;
32+
} else {
33+
result = 2;
34+
}
35+
}
36+
return "" + result;
37+
}
4238
}

jdk_8_maven/cs/rpc/thrift/artificial/thrift-scs/src/main/java/org/thrift/scs/imp/Costfuns.java

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,57 +14,54 @@
1414
//! name = costfuns //NAME OF EXPT, NOT COMPUTATIONALLY SIGNIFICANT
1515

1616

17-
1817
package org.thrift.scs.imp;
1918

20-
public class Costfuns
21-
{
22-
public static String subject(int i, String s)
23-
{
24-
int result = 0;
19+
public class Costfuns {
20+
public static String subject(int i, String s) {
21+
int result = 0;
2522

26-
//TEST COST FUNCTIONS
27-
String s1 = "ba";
28-
String s2 = "ab";
29-
if (i == 5) { //i0
30-
result = 1;
31-
}
32-
if (i < -444) { //i1
33-
result = 2;
34-
}
35-
if (i <= -333) { //i2
36-
result = 3;
37-
}
38-
if (i > 666) { //i3
39-
result = 4;
40-
}
41-
if (i >= 555) { //i4
42-
result = 5;
43-
}
44-
if (i != -4) { //i5
45-
result = 6;
46-
}
47-
if (s.equals( s1 + s2)) { //i6
48-
result = 7;
49-
}
50-
//THOSE operations are not defined in Java...
23+
//TEST COST FUNCTIONS
24+
String s1 = "ba";
25+
String s2 = "ab";
26+
if (i == 5) { //i0
27+
result = 1;
28+
}
29+
if (i < -444) { //i1
30+
result = 2;
31+
}
32+
if (i <= -333) { //i2
33+
result = 3;
34+
}
35+
if (i > 666) { //i3
36+
result = 4;
37+
}
38+
if (i >= 555) { //i4
39+
result = 5;
40+
}
41+
if (i != -4) { //i5
42+
result = 6;
43+
}
44+
if (s.equals(s1 + s2)) { //i6
45+
result = 7;
46+
}
47+
//THOSE operations are not defined in Java...
5148
/*
5249
if (s <= s1..Remove(0, 1)) { //i7
5350
}
5451
if (s < s1.Remove(1, 1)) { //i8
5552
}
5653
*/
57-
if (s.compareTo(s2 + s2 + s1)>0) { //i9
58-
result = 8;
59-
}
60-
if (s.compareTo(s2 + s2 + s1) >= 0) { //i10
61-
result = 9;
62-
}
63-
if (s != s2 + s2) { //i11
64-
result = 10;
65-
}
66-
67-
return "" + result;
68-
}
54+
if (s.compareTo(s2 + s2 + s1) > 0) { //i9
55+
result = 8;
56+
}
57+
if (s.compareTo(s2 + s2 + s1) >= 0) { //i10
58+
result = 9;
59+
}
60+
if (s != s2 + s2) { //i11
61+
result = 10;
62+
}
63+
64+
return "" + result;
65+
}
6966
}
7067

jdk_8_maven/cs/rpc/thrift/artificial/thrift-scs/src/main/java/org/thrift/scs/imp/DateParse.java

Lines changed: 53 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -15,62 +15,60 @@
1515

1616
package org.thrift.scs.imp;
1717

18-
public class DateParse
19-
{
20-
public static String subject(String dayname , String monthname)
21-
{
22-
int result = 0;
23-
//int month = -1;
24-
dayname = dayname.toLowerCase();
25-
monthname = monthname.toLowerCase();
18+
public class DateParse {
19+
public static String subject(String dayname, String monthname) {
20+
int result = 0;
21+
//int month = -1;
22+
dayname = dayname.toLowerCase();
23+
monthname = monthname.toLowerCase();
2624

27-
if ("mon".equals(dayname) ||
28-
"tue".equals(dayname) ||
29-
"wed".equals(dayname) ||
30-
"thur".equals(dayname) ||
31-
"fri".equals(dayname) ||
32-
"sat".equals(dayname) ||
33-
"sun".equals(dayname)) {
34-
result = 1;
35-
}
36-
if ("jan".equals(monthname)) {
37-
result += 1;
38-
}
39-
if ("feb".equals(monthname)) {
40-
result += 2;
41-
}
42-
if ("mar".equals(monthname)) {
43-
result += 3;
44-
}
45-
if ("apr".equals(monthname)) {
46-
result += 4;
47-
}
48-
if ("may".equals(monthname)) {
49-
result += 5;
50-
}
51-
if ("jun".equals(monthname)) {
52-
result += 6;
53-
}
54-
if ("jul".equals(monthname)) {
55-
result += 7;
56-
}
57-
if ("aug".equals(monthname)) {
58-
result += 8;
59-
}
60-
if ("sep".equals(monthname)) {
61-
result += 9;
62-
}
63-
if ("oct".equals(monthname)) {
64-
result += 10;
65-
}
66-
if ("nov".equals(monthname)) {
67-
result += 11;
68-
}
69-
if ("dec".equals(monthname)) {
70-
result += 12;
71-
}
25+
if ("mon".equals(dayname) ||
26+
"tue".equals(dayname) ||
27+
"wed".equals(dayname) ||
28+
"thur".equals(dayname) ||
29+
"fri".equals(dayname) ||
30+
"sat".equals(dayname) ||
31+
"sun".equals(dayname)) {
32+
result = 1;
33+
}
34+
if ("jan".equals(monthname)) {
35+
result += 1;
36+
}
37+
if ("feb".equals(monthname)) {
38+
result += 2;
39+
}
40+
if ("mar".equals(monthname)) {
41+
result += 3;
42+
}
43+
if ("apr".equals(monthname)) {
44+
result += 4;
45+
}
46+
if ("may".equals(monthname)) {
47+
result += 5;
48+
}
49+
if ("jun".equals(monthname)) {
50+
result += 6;
51+
}
52+
if ("jul".equals(monthname)) {
53+
result += 7;
54+
}
55+
if ("aug".equals(monthname)) {
56+
result += 8;
57+
}
58+
if ("sep".equals(monthname)) {
59+
result += 9;
60+
}
61+
if ("oct".equals(monthname)) {
62+
result += 10;
63+
}
64+
if ("nov".equals(monthname)) {
65+
result += 11;
66+
}
67+
if ("dec".equals(monthname)) {
68+
result += 12;
69+
}
7270

73-
return "" + result;
74-
}
71+
return "" + result;
72+
}
7573

7674
}

0 commit comments

Comments
 (0)