Removed code smells and followed naming convention
- Local variable names in java must be with the default regular expression ^[a-z][a-zA-Z0-9]*$ https://rules.sonarsource.com/java/tag/convention/RSPEC-117 - The diamond operator ("<>") should be used when the type of the maps are already defined https://rules.sonarsource.com/java/RSPEC-2293 - Package names being camel cased is a code smell
This commit is contained in:
parent
56a527aa26
commit
7fbf8f221c
@ -75,8 +75,8 @@ class LFUCache<T> {
|
|||||||
public LFUCache(int capacity) {
|
public LFUCache(int capacity) {
|
||||||
this.capacity = capacity;
|
this.capacity = capacity;
|
||||||
size = 0;
|
size = 0;
|
||||||
freq = new TreeMap<Integer, DLL>();
|
freq = new TreeMap<>();
|
||||||
map = new HashMap<Integer, Node>();
|
map = new HashMap<>();
|
||||||
System.out.println("LFUCache initialised with capacity: " + capacity);
|
System.out.println("LFUCache initialised with capacity: " + capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,8 +145,8 @@ class LFUCache<T> {
|
|||||||
dll.deleteNode(dll.tail.pre);
|
dll.deleteNode(dll.tail.pre);
|
||||||
if (dll.len == 0 && lowest != 1)
|
if (dll.len == 0 && lowest != 1)
|
||||||
freq.remove(lowest);
|
freq.remove(lowest);
|
||||||
DLL freq_one = freq.computeIfAbsent(1, k -> new DLL());
|
DLL freqOne = freq.computeIfAbsent(1, k -> new DLL());
|
||||||
freq_one.addToHead(node);
|
freqOne.addToHead(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,25 +5,25 @@ public class CaesarBruteForce {
|
|||||||
/**
|
/**
|
||||||
* Recursively Brute forces a parsed encrypted text, trying out all shifting keys from 1-26, printing out all decryption attempts
|
* Recursively Brute forces a parsed encrypted text, trying out all shifting keys from 1-26, printing out all decryption attempts
|
||||||
* @param message (String) The encrypted text.
|
* @param message (String) The encrypted text.
|
||||||
* @param Key (int) The key used to decrypt the encrypted text and is increment upon a recursive call.
|
* @param key (int) The key used to decrypt the encrypted text and is increment upon a recursive call.
|
||||||
* @return (String) Concatenated string of all decryption attempts (For unit testing purposes).
|
* @return (String) Concatenated string of all decryption attempts (For unit testing purposes).
|
||||||
*/
|
*/
|
||||||
public String decrypt(String message, int Key) {
|
public String decrypt(String message, int key) {
|
||||||
final String LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
final String LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
if (Key > 26){ System.out.println(); return null; }
|
if (key > 26){ System.out.println(); return null; }
|
||||||
|
|
||||||
StringBuilder plainText = new StringBuilder();
|
StringBuilder plainText = new StringBuilder();
|
||||||
for (char character : message.toUpperCase().toCharArray()) {
|
for (char character : message.toUpperCase().toCharArray()) {
|
||||||
int index = LETTERS.indexOf(character);
|
int index = LETTERS.indexOf(character);
|
||||||
|
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
index -= Key;
|
index -= key;
|
||||||
//Wrap around index value range[1-26]
|
//Wrap around index value range[1-26]
|
||||||
if (index < 0) { index += LETTERS.length(); }
|
if (index < 0) { index += LETTERS.length(); }
|
||||||
plainText.append(LETTERS.toCharArray()[index]);
|
plainText.append(LETTERS.toCharArray()[index]);
|
||||||
} else { plainText.append(character); }
|
} else { plainText.append(character); }
|
||||||
}
|
}
|
||||||
System.out.println(String.format("Current Decryption Key %d : %s", Key, plainText));
|
System.out.println(String.format("Current Decryption Key %d : %s", key, plainText));
|
||||||
return plainText.append(decrypt(message, Key+1)).toString();
|
return plainText.append(decrypt(message, key+1)).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ public class HexadecimalToBinary {
|
|||||||
public String hexToBin (String hexStr) {
|
public String hexToBin (String hexStr) {
|
||||||
|
|
||||||
String binaryString = "", hexaNumbers = "0123456789ABCDEF",
|
String binaryString = "", hexaNumbers = "0123456789ABCDEF",
|
||||||
DecimalStr ="", binaryStringBefore ="" , binaryStringAfter = "";
|
decimalStr ="", binaryStringBefore ="" , binaryStringAfter = "";
|
||||||
int indexOfHex, decimalNumber = 0, k = 1, n =1, z=1, decimalNumberBefore = 0
|
int indexOfHex, decimalNumber = 0, k = 1, n =1, z=1, decimalNumberBefore = 0
|
||||||
, decimalNumberAfter = 0;
|
, decimalNumberAfter = 0;
|
||||||
char letter;
|
char letter;
|
||||||
@ -48,12 +48,12 @@ public class HexadecimalToBinary {
|
|||||||
|
|
||||||
String decimalNumberAfterStr = String.valueOf(decimalNumberAfter);
|
String decimalNumberAfterStr = String.valueOf(decimalNumberAfter);
|
||||||
|
|
||||||
DecimalStr = decimalNumberBeforeStr + '.' + decimalNumberAfterStr;
|
decimalStr = decimalNumberBeforeStr + '.' + decimalNumberAfterStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int pointPositionDec = DecimalStr.indexOf(".");
|
int pointPositionDec = decimalStr.indexOf(".");
|
||||||
/**
|
/**
|
||||||
* Check whether the result contains a floating point or not
|
* Check whether the result contains a floating point or not
|
||||||
*/
|
*/
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.dataStructures;
|
package com.datastructures;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Binary tree for general value type, without redundancy
|
* Binary tree for general value type, without redundancy
|
@ -1,4 +1,4 @@
|
|||||||
package com.dataStructures;
|
package com.datastructures;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.*;
|
import java.util.*;
|
@ -1,4 +1,4 @@
|
|||||||
package com.dataStructures;
|
package com.datastructures;
|
||||||
|
|
||||||
import com.types.Queue;
|
import com.types.Queue;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.dataStructures;
|
package com.datastructures;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This file contains an implementation of an integer only queue which is extremely quick and
|
* This file contains an implementation of an integer only queue which is extremely quick and
|
@ -1,4 +1,4 @@
|
|||||||
package com.dataStructures;
|
package com.datastructures;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.dataStructures;
|
package com.datastructures;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.EmptyStackException;
|
import java.util.EmptyStackException;
|
@ -1,4 +1,4 @@
|
|||||||
package com.matchings.stableMatching;
|
package com.matchings.stablematching;
|
||||||
|
|
||||||
public class GaleShapley {
|
public class GaleShapley {
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.dataStructures;
|
package com.datastructures;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
@ -1,4 +1,4 @@
|
|||||||
package com.dataStructures;
|
package com.datastructures;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
@ -1,4 +1,4 @@
|
|||||||
package com.dataStructures;
|
package com.datastructures;
|
||||||
|
|
||||||
|
|
||||||
import com.types.Queue;
|
import com.types.Queue;
|
@ -1,4 +1,4 @@
|
|||||||
package com.dataStructures;
|
package com.datastructures;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.dataStructures;
|
package com.datastructures;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
@ -1,4 +1,4 @@
|
|||||||
package com.dataStructures;
|
package com.datastructures;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
@ -1,4 +1,4 @@
|
|||||||
package com.matchings.stableMatching;
|
package com.matchings.stablematching;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
Loading…
Reference in New Issue
Block a user