style: include SS_SHOULD_BE_STATIC (#5198)

This commit is contained in:
Piotr Idzik
2024-06-01 23:24:11 +02:00
committed by GitHub
parent c42b1c940c
commit 5e4db7baf1
3 changed files with 47 additions and 52 deletions

View File

@ -77,9 +77,6 @@
<Match> <Match>
<Bug pattern="UWF_UNWRITTEN_FIELD" /> <Bug pattern="UWF_UNWRITTEN_FIELD" />
</Match> </Match>
<Match>
<Bug pattern="SS_SHOULD_BE_STATIC" />
</Match>
<Match> <Match>
<Bug pattern="IT_NO_SUCH_ELEMENT" /> <Bug pattern="IT_NO_SUCH_ELEMENT" />
</Match> </Match>

View File

@ -2,9 +2,6 @@ package com.thealgorithms.conversions;
// Hex [0-9],[A-F] -> Binary [0,1] // Hex [0-9],[A-F] -> Binary [0,1]
public class HexaDecimalToBinary { public class HexaDecimalToBinary {
private final int longBits = 8;
public String convert(String numHex) { public String convert(String numHex) {
// String a HexaDecimal: // String a HexaDecimal:
int conHex = Integer.parseInt(numHex, 16); int conHex = Integer.parseInt(numHex, 16);
@ -15,6 +12,7 @@ public class HexaDecimalToBinary {
} }
public String completeDigits(String binNum) { public String completeDigits(String binNum) {
final int longBits = 8;
for (int i = binNum.length(); i < longBits; i++) { for (int i = binNum.length(); i < longBits; i++) {
binNum = "0" + binNum; binNum = "0" + binNum;
} }

View File

@ -7,13 +7,13 @@ import java.util.Scanner;
*/ */
public class RedBlackBST { public class RedBlackBST {
private final int red = 0; private static final int RED = 0;
private final int black = 1; private static final int BLACK = 1;
private class Node { private class Node {
int key = -1; int key = -1;
int color = black; int color = BLACK;
Node left = nil; Node left = nil;
Node right = nil; Node right = nil;
Node p = nil; Node p = nil;
@ -31,7 +31,7 @@ public class RedBlackBST {
return; return;
} }
printTree(node.left); printTree(node.left);
System.out.print(((node.color == red) ? " R " : " B ") + "Key: " + node.key + " Parent: " + node.p.key + "\n"); System.out.print(((node.color == RED) ? " R " : " B ") + "Key: " + node.key + " Parent: " + node.p.key + "\n");
printTree(node.right); printTree(node.right);
} }
@ -39,7 +39,7 @@ public class RedBlackBST {
if (node == nil) { if (node == nil) {
return; return;
} }
System.out.print(((node.color == red) ? " R " : " B ") + "Key: " + node.key + " Parent: " + node.p.key + "\n"); System.out.print(((node.color == RED) ? " R " : " B ") + "Key: " + node.key + " Parent: " + node.p.key + "\n");
printTreepre(node.left); printTreepre(node.left);
printTreepre(node.right); printTreepre(node.right);
} }
@ -66,10 +66,10 @@ public class RedBlackBST {
Node temp = root; Node temp = root;
if (root == nil) { if (root == nil) {
root = node; root = node;
node.color = black; node.color = BLACK;
node.p = nil; node.p = nil;
} else { } else {
node.color = red; node.color = RED;
while (true) { while (true) {
if (node.key < temp.key) { if (node.key < temp.key) {
if (temp.left == nil) { if (temp.left == nil) {
@ -94,15 +94,15 @@ public class RedBlackBST {
} }
private void fixTree(Node node) { private void fixTree(Node node) {
while (node.p.color == red) { while (node.p.color == RED) {
Node y = nil; Node y = nil;
if (node.p == node.p.p.left) { if (node.p == node.p.p.left) {
y = node.p.p.right; y = node.p.p.right;
if (y != nil && y.color == red) { if (y != nil && y.color == RED) {
node.p.color = black; node.p.color = BLACK;
y.color = black; y.color = BLACK;
node.p.p.color = red; node.p.p.color = RED;
node = node.p.p; node = node.p.p;
continue; continue;
} }
@ -110,15 +110,15 @@ public class RedBlackBST {
node = node.p; node = node.p;
rotateLeft(node); rotateLeft(node);
} }
node.p.color = black; node.p.color = BLACK;
node.p.p.color = red; node.p.p.color = RED;
rotateRight(node.p.p); rotateRight(node.p.p);
} else { } else {
y = node.p.p.left; y = node.p.p.left;
if (y != nil && y.color == red) { if (y != nil && y.color == RED) {
node.p.color = black; node.p.color = BLACK;
y.color = black; y.color = BLACK;
node.p.p.color = red; node.p.p.color = RED;
node = node.p.p; node = node.p.p;
continue; continue;
} }
@ -126,12 +126,12 @@ public class RedBlackBST {
node = node.p; node = node.p;
rotateRight(node); rotateRight(node);
} }
node.p.color = black; node.p.color = BLACK;
node.p.p.color = red; node.p.p.color = RED;
rotateLeft(node.p.p); rotateLeft(node.p.p);
} }
} }
root.color = black; root.color = BLACK;
} }
void rotateLeft(Node node) { void rotateLeft(Node node) {
@ -234,67 +234,67 @@ public class RedBlackBST {
y.left.p = y; y.left.p = y;
y.color = z.color; y.color = z.color;
} }
if (yorigcolor == black) { if (yorigcolor == BLACK) {
deleteFixup(x); deleteFixup(x);
} }
return true; return true;
} }
void deleteFixup(Node x) { void deleteFixup(Node x) {
while (x != root && x.color == black) { while (x != root && x.color == BLACK) {
if (x == x.p.left) { if (x == x.p.left) {
Node w = x.p.right; Node w = x.p.right;
if (w.color == red) { if (w.color == RED) {
w.color = black; w.color = BLACK;
x.p.color = red; x.p.color = RED;
rotateLeft(x.p); rotateLeft(x.p);
w = x.p.right; w = x.p.right;
} }
if (w.left.color == black && w.right.color == black) { if (w.left.color == BLACK && w.right.color == BLACK) {
w.color = red; w.color = RED;
x = x.p; x = x.p;
continue; continue;
} else if (w.right.color == black) { } else if (w.right.color == BLACK) {
w.left.color = black; w.left.color = BLACK;
w.color = red; w.color = RED;
rotateRight(w); rotateRight(w);
w = x.p.right; w = x.p.right;
} }
if (w.right.color == red) { if (w.right.color == RED) {
w.color = x.p.color; w.color = x.p.color;
x.p.color = black; x.p.color = BLACK;
w.right.color = black; w.right.color = BLACK;
rotateLeft(x.p); rotateLeft(x.p);
x = root; x = root;
} }
} else { } else {
Node w = x.p.left; Node w = x.p.left;
if (w.color == red) { if (w.color == RED) {
w.color = black; w.color = BLACK;
x.p.color = red; x.p.color = RED;
rotateRight(x.p); rotateRight(x.p);
w = x.p.left; w = x.p.left;
} }
if (w.right.color == black && w.left.color == black) { if (w.right.color == BLACK && w.left.color == BLACK) {
w.color = red; w.color = RED;
x = x.p; x = x.p;
continue; continue;
} else if (w.left.color == black) { } else if (w.left.color == BLACK) {
w.right.color = black; w.right.color = BLACK;
w.color = red; w.color = RED;
rotateLeft(w); rotateLeft(w);
w = x.p.left; w = x.p.left;
} }
if (w.left.color == red) { if (w.left.color == RED) {
w.color = x.p.color; w.color = x.p.color;
x.p.color = black; x.p.color = BLACK;
w.left.color = black; w.left.color = BLACK;
rotateRight(x.p); rotateRight(x.p);
x = root; x = root;
} }
} }
} }
x.color = black; x.color = BLACK;
} }
public void insertDemo() { public void insertDemo() {