Skip to content

Commit 9d8dd4c

Browse files
committed
style: include SS_SHOULD_BE_STATIC
1 parent c42b1c9 commit 9d8dd4c

File tree

3 files changed

+47
-52
lines changed

3 files changed

+47
-52
lines changed

spotbugs-exclude.xml

-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@
7777
<Match>
7878
<Bug pattern="UWF_UNWRITTEN_FIELD" />
7979
</Match>
80-
<Match>
81-
<Bug pattern="SS_SHOULD_BE_STATIC" />
82-
</Match>
8380
<Match>
8481
<Bug pattern="IT_NO_SUCH_ELEMENT" />
8582
</Match>

src/main/java/com/thealgorithms/conversions/HexaDecimalToBinary.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
// Hex [0-9],[A-F] -> Binary [0,1]
44
public class HexaDecimalToBinary {
5-
6-
private final int longBits = 8;
7-
85
public String convert(String numHex) {
96
// String a HexaDecimal:
107
int conHex = Integer.parseInt(numHex, 16);
@@ -15,6 +12,7 @@ public String convert(String numHex) {
1512
}
1613

1714
public String completeDigits(String binNum) {
15+
final int longBits = 8;
1816
for (int i = binNum.length(); i < longBits; i++) {
1917
binNum = "0" + binNum;
2018
}

src/main/java/com/thealgorithms/datastructures/trees/RedBlackBST.java

+46-46
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
*/
88
public class RedBlackBST {
99

10-
private final int red = 0;
11-
private final int black = 1;
10+
private static final int RED = 0;
11+
private static final int BLACK = 1;
1212

1313
private class Node {
1414

1515
int key = -1;
16-
int color = black;
16+
int color = BLACK;
1717
Node left = nil;
1818
Node right = nil;
1919
Node p = nil;
@@ -31,15 +31,15 @@ public void printTree(Node node) {
3131
return;
3232
}
3333
printTree(node.left);
34-
System.out.print(((node.color == red) ? " R " : " B ") + "Key: " + node.key + " Parent: " + node.p.key + "\n");
34+
System.out.print(((node.color == RED) ? " R " : " B ") + "Key: " + node.key + " Parent: " + node.p.key + "\n");
3535
printTree(node.right);
3636
}
3737

3838
public void printTreepre(Node node) {
3939
if (node == nil) {
4040
return;
4141
}
42-
System.out.print(((node.color == red) ? " R " : " B ") + "Key: " + node.key + " Parent: " + node.p.key + "\n");
42+
System.out.print(((node.color == RED) ? " R " : " B ") + "Key: " + node.key + " Parent: " + node.p.key + "\n");
4343
printTreepre(node.left);
4444
printTreepre(node.right);
4545
}
@@ -66,10 +66,10 @@ private void insert(Node node) {
6666
Node temp = root;
6767
if (root == nil) {
6868
root = node;
69-
node.color = black;
69+
node.color = BLACK;
7070
node.p = nil;
7171
} else {
72-
node.color = red;
72+
node.color = RED;
7373
while (true) {
7474
if (node.key < temp.key) {
7575
if (temp.left == nil) {
@@ -94,44 +94,44 @@ private void insert(Node node) {
9494
}
9595

9696
private void fixTree(Node node) {
97-
while (node.p.color == red) {
97+
while (node.p.color == RED) {
9898
Node y = nil;
9999
if (node.p == node.p.p.left) {
100100
y = node.p.p.right;
101101

102-
if (y != nil && y.color == red) {
103-
node.p.color = black;
104-
y.color = black;
105-
node.p.p.color = red;
102+
if (y != nil && y.color == RED) {
103+
node.p.color = BLACK;
104+
y.color = BLACK;
105+
node.p.p.color = RED;
106106
node = node.p.p;
107107
continue;
108108
}
109109
if (node == node.p.right) {
110110
node = node.p;
111111
rotateLeft(node);
112112
}
113-
node.p.color = black;
114-
node.p.p.color = red;
113+
node.p.color = BLACK;
114+
node.p.p.color = RED;
115115
rotateRight(node.p.p);
116116
} else {
117117
y = node.p.p.left;
118-
if (y != nil && y.color == red) {
119-
node.p.color = black;
120-
y.color = black;
121-
node.p.p.color = red;
118+
if (y != nil && y.color == RED) {
119+
node.p.color = BLACK;
120+
y.color = BLACK;
121+
node.p.p.color = RED;
122122
node = node.p.p;
123123
continue;
124124
}
125125
if (node == node.p.left) {
126126
node = node.p;
127127
rotateRight(node);
128128
}
129-
node.p.color = black;
130-
node.p.p.color = red;
129+
node.p.color = BLACK;
130+
node.p.p.color = RED;
131131
rotateLeft(node.p.p);
132132
}
133133
}
134-
root.color = black;
134+
root.color = BLACK;
135135
}
136136

137137
void rotateLeft(Node node) {
@@ -234,67 +234,67 @@ boolean delete(Node z) {
234234
y.left.p = y;
235235
y.color = z.color;
236236
}
237-
if (yorigcolor == black) {
237+
if (yorigcolor == BLACK) {
238238
deleteFixup(x);
239239
}
240240
return true;
241241
}
242242

243243
void deleteFixup(Node x) {
244-
while (x != root && x.color == black) {
244+
while (x != root && x.color == BLACK) {
245245
if (x == x.p.left) {
246246
Node w = x.p.right;
247-
if (w.color == red) {
248-
w.color = black;
249-
x.p.color = red;
247+
if (w.color == RED) {
248+
w.color = BLACK;
249+
x.p.color = RED;
250250
rotateLeft(x.p);
251251
w = x.p.right;
252252
}
253-
if (w.left.color == black && w.right.color == black) {
254-
w.color = red;
253+
if (w.left.color == BLACK && w.right.color == BLACK) {
254+
w.color = RED;
255255
x = x.p;
256256
continue;
257-
} else if (w.right.color == black) {
258-
w.left.color = black;
259-
w.color = red;
257+
} else if (w.right.color == BLACK) {
258+
w.left.color = BLACK;
259+
w.color = RED;
260260
rotateRight(w);
261261
w = x.p.right;
262262
}
263-
if (w.right.color == red) {
263+
if (w.right.color == RED) {
264264
w.color = x.p.color;
265-
x.p.color = black;
266-
w.right.color = black;
265+
x.p.color = BLACK;
266+
w.right.color = BLACK;
267267
rotateLeft(x.p);
268268
x = root;
269269
}
270270
} else {
271271
Node w = x.p.left;
272-
if (w.color == red) {
273-
w.color = black;
274-
x.p.color = red;
272+
if (w.color == RED) {
273+
w.color = BLACK;
274+
x.p.color = RED;
275275
rotateRight(x.p);
276276
w = x.p.left;
277277
}
278-
if (w.right.color == black && w.left.color == black) {
279-
w.color = red;
278+
if (w.right.color == BLACK && w.left.color == BLACK) {
279+
w.color = RED;
280280
x = x.p;
281281
continue;
282-
} else if (w.left.color == black) {
283-
w.right.color = black;
284-
w.color = red;
282+
} else if (w.left.color == BLACK) {
283+
w.right.color = BLACK;
284+
w.color = RED;
285285
rotateLeft(w);
286286
w = x.p.left;
287287
}
288-
if (w.left.color == red) {
288+
if (w.left.color == RED) {
289289
w.color = x.p.color;
290-
x.p.color = black;
291-
w.left.color = black;
290+
x.p.color = BLACK;
291+
w.left.color = BLACK;
292292
rotateRight(x.p);
293293
x = root;
294294
}
295295
}
296296
}
297-
x.color = black;
297+
x.color = BLACK;
298298
}
299299

300300
public void insertDemo() {

0 commit comments

Comments
 (0)