Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2d797fb

Browse files
committed
Corrected code smells with raw type and dangling else block
-Generic types shouldn't be used raw (without type parameters) in variable declarations or return values. Doing so bypasses generic type checking, and defers the catch of unsafe code to runtime.https://rules.sonarsource.com/java/RSPEC-3740- The dangling else problem appears when nested if/else statements are written without curly braces. In this case, else is associated with the nearest if but that is not always obvious and sometimes the indentation can also be misleading.https://rules.sonarsource.com/java/tag/confusing/RSPEC-5261
1 parent6aecb37 commit2d797fb

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

‎src/main/java/com/datastructures/BinaryTree.java‎

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
publicclassBinaryTree<TextendsComparable> {
1010
privatefinalTdata;
11-
privateBinaryTreeright,// the upper binary tree
11+
privateBinaryTree<T>right,// the upper binary tree
1212
left;// the lower binary tree
1313

1414
publicBinaryTree(Tdata) {
@@ -21,35 +21,38 @@ public String toString() {
2121
}
2222

2323
/**
24-
* inserts a new value in it'scorrespondant place
24+
* inserts a new value in it'scorrespondent place
2525
*
2626
* @param newDataValue value of the new binary tree to add on this tree
2727
*/
2828
publicvoidinsert(TnewDataValue) {
29-
this.insert(newBinaryTree(newDataValue));
29+
this.insert(newBinaryTree<>(newDataValue));
3030
}
3131

3232
/**
33-
* inserts a new binary tree in it'scorrespondant place
33+
* inserts a new binary tree in it'scorrespondent place
3434
*
3535
* @param newData new value to add on this tree
3636
*/
37-
publicvoidinsert(BinaryTreenewData) {
37+
publicvoidinsert(BinaryTree<T>newData) {
3838

3939
intcpr =newData.data.compareTo(this.data);//new value comparission respect to actual value
4040

41-
if (cpr <0)
42-
if (this.left ==null)
41+
if (cpr <0) {
42+
if (this.left ==null) {
4343
this.setLeft(newData);
44-
else
44+
}else {
4545
this.left.insert(newData);
46-
elseif (cpr >0)
47-
if (this.right ==null)
46+
}
47+
}elseif (cpr >0) {
48+
if (this.right ==null) {
4849
this.setRight(newData);
49-
else
50+
}else {
5051
this.right.insert(newData);
51-
else
52+
}
53+
}else {
5254
System.out.println("Redundant value, not added");
55+
}
5356
}
5457

5558
/**
@@ -58,8 +61,8 @@ else if (cpr > 0)
5861
* @param data Searched value
5962
* @return Binary tree which contains the value, null if it doesn't exist
6063
*/
61-
publicBinaryTreesearch(Tdata) {
62-
intcpr =data.compareTo(this.data);//new valuecomparission respect to actual value
64+
publicBinaryTree<T>search(Tdata) {
65+
intcpr =data.compareTo(this.data);//new valuecomparison respect to actual value
6366

6467
if (cpr <0) {
6568
if (this.left ==null)
@@ -113,19 +116,19 @@ public T getData() {
113116
returndata;
114117
}
115118

116-
publicBinaryTreegetRight() {
119+
publicBinaryTree<T>getRight() {
117120
returnright;
118121
}
119122

120-
publicvoidsetRight(BinaryTreeright) {
123+
publicvoidsetRight(BinaryTree<T>right) {
121124
this.right =right;
122125
}
123126

124-
publicBinaryTreegetLeft() {
127+
publicBinaryTree<T>getLeft() {
125128
returnleft;
126129
}
127130

128-
publicvoidsetLeft(BinaryTreeleft) {
131+
publicvoidsetLeft(BinaryTree<T>left) {
129132
this.left =left;
130133
}
131134
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp