Skip to content

style: enable MemberName in checkstyle #5193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<!-- TODO <module name="MemberName"/> -->
<module name="MemberName"/>
<module name="MethodName"/>
<module name="PackageName"/>
<!-- TODO <module name="ParameterName"/> -->
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/thealgorithms/ciphers/Blowfish.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class Blowfish {

// Initializing substitution boxes
String[][] S = {
String[][] sBox = {
{
"d1310ba6",
"98dfb5ac",
Expand Down Expand Up @@ -1047,7 +1047,7 @@ public class Blowfish {
};

// Initializing subkeys with digits of pi
String[] P = {
String[] subKeys = {
"243f6a88",
"85a308d3",
"13198a2e",
Expand Down Expand Up @@ -1154,7 +1154,7 @@ private String f(String plainText) {
for (int i = 0; i < 8; i += 2) {
// column number for S-box is a 8-bit value
long col = Long.parseUnsignedLong(hexToBin(plainText.substring(i, i + 2)), 2);
a[i / 2] = S[i / 2][(int) col];
a[i / 2] = sBox[i / 2][(int) col];
}
ans = addBin(a[0], a[1]);
ans = xor(ans, a[2]);
Expand All @@ -1165,9 +1165,9 @@ private String f(String plainText) {
// generate subkeys
private void keyGenerate(String key) {
int j = 0;
for (int i = 0; i < P.length; i++) {
for (int i = 0; i < subKeys.length; i++) {
// XOR-ing 32-bit parts of the key with initial subkeys
P[i] = xor(P[i], key.substring(j, j + 8));
subKeys[i] = xor(subKeys[i], key.substring(j, j + 8));

j = (j + 8) % key.length();
}
Expand All @@ -1179,7 +1179,7 @@ private String round(int time, String plainText) {
String right;
left = plainText.substring(0, 8);
right = plainText.substring(8, 16);
left = xor(left, P[time]);
left = xor(left, subKeys[time]);

// output from F function
String fOut = f(left);
Expand Down Expand Up @@ -1207,8 +1207,8 @@ String encrypt(String plainText, String key) {
// postprocessing
String right = plainText.substring(0, 8);
String left = plainText.substring(8, 16);
right = xor(right, P[16]);
left = xor(left, P[17]);
right = xor(right, subKeys[16]);
left = xor(left, subKeys[17]);
return left + right;
}

Expand All @@ -1229,8 +1229,8 @@ String decrypt(String cipherText, String key) {
// postprocessing
String right = cipherText.substring(0, 8);
String left = cipherText.substring(8, 16);
right = xor(right, P[1]);
left = xor(left, P[0]);
right = xor(right, subKeys[1]);
left = xor(left, subKeys[0]);
return left + right;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Hex [0-9],[A-F] -> Binary [0,1]
public class HexaDecimalToBinary {

private final int LONG_BITS = 8;
private final int longBits = 8;

public String convert(String numHex) {
// String a HexaDecimal:
Expand All @@ -15,7 +15,7 @@ public String convert(String numHex) {
}

public String completeDigits(String binNum) {
for (int i = binNum.length(); i < LONG_BITS; i++) {
for (int i = binNum.length(); i < longBits; i++) {
binNum = "0" + binNum;
}
return binNum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

class GCounter {
private final Map<Integer, Integer> P;
private final Map<Integer, Integer> counterMap;
private final int myId;
private final int n;

Expand All @@ -29,18 +29,18 @@ class GCounter {
GCounter(int myId, int n) {
this.myId = myId;
this.n = n;
this.P = new HashMap<>();
this.counterMap = new HashMap<>();

for (int i = 0; i < n; i++) {
P.put(i, 0);
counterMap.put(i, 0);
}
}

/**
* Increments the counter for the current node.
*/
public void increment() {
P.put(myId, P.get(myId) + 1);
counterMap.put(myId, counterMap.get(myId) + 1);
}

/**
Expand All @@ -50,7 +50,7 @@ public void increment() {
*/
public int value() {
int sum = 0;
for (int v : P.values()) {
for (int v : counterMap.values()) {
sum += v;
}
return sum;
Expand All @@ -64,7 +64,7 @@ public int value() {
*/
public boolean compare(GCounter other) {
for (int i = 0; i < n; i++) {
if (this.P.get(i) > other.P.get(i)) {
if (this.counterMap.get(i) > other.counterMap.get(i)) {
return false;
}
}
Expand All @@ -78,7 +78,7 @@ public boolean compare(GCounter other) {
*/
public void merge(GCounter other) {
for (int i = 0; i < n; i++) {
this.P.put(i, Math.max(this.P.get(i), other.P.get(i)));
this.counterMap.put(i, Math.max(this.counterMap.get(i), other.counterMap.get(i)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/

class PNCounter {
private final Map<Integer, Integer> P;
private final Map<Integer, Integer> N;
private final Map<Integer, Integer> pCounter;
private final Map<Integer, Integer> nCounter;
private final int myId;
private final int n;

Expand All @@ -31,27 +31,27 @@ class PNCounter {
PNCounter(int myId, int n) {
this.myId = myId;
this.n = n;
this.P = new HashMap<>();
this.N = new HashMap<>();
this.pCounter = new HashMap<>();
this.nCounter = new HashMap<>();

for (int i = 0; i < n; i++) {
P.put(i, 0);
N.put(i, 0);
pCounter.put(i, 0);
nCounter.put(i, 0);
}
}

/**
* Increments the increment counter for the current node.
*/
public void increment() {
P.put(myId, P.get(myId) + 1);
pCounter.put(myId, pCounter.get(myId) + 1);
}

/**
* Increments the decrement counter for the current node.
*/
public void decrement() {
N.put(myId, N.get(myId) + 1);
nCounter.put(myId, nCounter.get(myId) + 1);
}

/**
Expand All @@ -60,8 +60,8 @@ public void decrement() {
* @return The total value of the counter.
*/
public int value() {
int sumP = P.values().stream().mapToInt(Integer::intValue).sum();
int sumN = N.values().stream().mapToInt(Integer::intValue).sum();
int sumP = pCounter.values().stream().mapToInt(Integer::intValue).sum();
int sumN = nCounter.values().stream().mapToInt(Integer::intValue).sum();
return sumP - sumN;
}

Expand All @@ -76,7 +76,7 @@ public boolean compare(PNCounter other) {
throw new IllegalArgumentException("Cannot compare PN-Counters with different number of nodes");
}
for (int i = 0; i < n; i++) {
if (this.P.get(i) > other.P.get(i) && this.N.get(i) > other.N.get(i)) {
if (this.pCounter.get(i) > other.pCounter.get(i) && this.nCounter.get(i) > other.nCounter.get(i)) {
return false;
}
}
Expand All @@ -93,8 +93,8 @@ public void merge(PNCounter other) {
throw new IllegalArgumentException("Cannot merge PN-Counters with different number of nodes");
}
for (int i = 0; i < n; i++) {
this.P.put(i, Math.max(this.P.get(i), other.P.get(i)));
this.N.put(i, Math.max(this.N.get(i), other.N.get(i)));
this.pCounter.put(i, Math.max(this.pCounter.get(i), other.pCounter.get(i)));
this.nCounter.put(i, Math.max(this.nCounter.get(i), other.nCounter.get(i)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

public class FloydWarshall {

private int[][] DistanceMatrix;
private int[][] distanceMatrix;
private int numberofvertices; // number of vertices in the graph
public static final int INFINITY = 999;

public FloydWarshall(int numberofvertices) {
DistanceMatrix = new int[numberofvertices + 1][numberofvertices + 1]; // stores the value of distance from all the possible path form the source
distanceMatrix = new int[numberofvertices + 1][numberofvertices + 1]; // stores the value of distance from all the possible path form the source
// vertex to destination vertex
// The matrix is initialized with 0's by default
this.numberofvertices = numberofvertices;
Expand All @@ -18,17 +18,17 @@ public FloydWarshall(int numberofvertices) {
public void floydwarshall(int[][] AdjacencyMatrix) { // calculates all the distances from source to destination vertex
for (int source = 1; source <= numberofvertices; source++) {
for (int destination = 1; destination <= numberofvertices; destination++) {
DistanceMatrix[source][destination] = AdjacencyMatrix[source][destination];
distanceMatrix[source][destination] = AdjacencyMatrix[source][destination];
}
}
for (int intermediate = 1; intermediate <= numberofvertices; intermediate++) {
for (int source = 1; source <= numberofvertices; source++) {
for (int destination = 1; destination <= numberofvertices; destination++) {
if (DistanceMatrix[source][intermediate] + DistanceMatrix[intermediate][destination] < DistanceMatrix[source][destination]) { // calculated distance it get replaced as
if (distanceMatrix[source][intermediate] + distanceMatrix[intermediate][destination] < distanceMatrix[source][destination]) { // calculated distance it get replaced as
// new shortest distance // if the new
// distance calculated is less then the
// earlier shortest
DistanceMatrix[source][destination] = DistanceMatrix[source][intermediate] + DistanceMatrix[intermediate][destination];
distanceMatrix[source][destination] = distanceMatrix[source][intermediate] + distanceMatrix[intermediate][destination];
}
}
}
Expand All @@ -40,7 +40,7 @@ public void floydwarshall(int[][] AdjacencyMatrix) { // calculates all the dista
for (int source = 1; source <= numberofvertices; source++) {
System.out.print(source + "\t");
for (int destination = 1; destination <= numberofvertices; destination++) {
System.out.print(DistanceMatrix[source][destination] + "\t");
System.out.print(distanceMatrix[source][destination] + "\t");
}
System.out.println();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
public class HamiltonianCycle {

private int V;
private int vertex;
private int pathCount;
private int[] cycle;
private int[][] graph;
Expand All @@ -22,8 +22,8 @@ public class HamiltonianCycle {
* else returns 1D array with value -1.
*/
public int[] findHamiltonianCycle(int[][] graph) {
this.V = graph.length;
this.cycle = new int[this.V + 1];
this.vertex = graph.length;
this.cycle = new int[this.vertex + 1];

// Initialize path array with -1 value
for (int i = 0; i < this.cycle.length; i++) {
Expand Down Expand Up @@ -53,17 +53,17 @@ public int[] findHamiltonianCycle(int[][] graph) {
* @returns true if path is found false otherwise
*/
public boolean isPathFound(int vertex) {
boolean isLastVertexConnectedToStart = this.graph[vertex][0] == 1 && this.pathCount == this.V;
boolean isLastVertexConnectedToStart = this.graph[vertex][0] == 1 && this.pathCount == this.vertex;
if (isLastVertexConnectedToStart) {
return true;
}

/** all vertices selected but last vertex not linked to 0 **/
if (this.pathCount == this.V) {
if (this.pathCount == this.vertex) {
return false;
}

for (int v = 0; v < this.V; v++) {
for (int v = 0; v < this.vertex; v++) {
/** if connected **/
if (this.graph[vertex][v] == 1) {
/** add to path **/
Expand Down
Loading