Skip to content

Revert "Revert "Fixed code smells after running sonarqube on the project"" #1434

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 1 commit into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions src/main/java/com/caching/LFUCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public void deleteNode(Node node) {
public LFUCache(int capacity) {
this.capacity = capacity;
size = 0;
freq = new TreeMap<Integer, DLL>();
map = new HashMap<Integer, Node>();
freq = new TreeMap<>();
map = new HashMap<>();
System.out.println("LFUCache initialised with capacity: " + capacity);
}

Expand Down Expand Up @@ -145,8 +145,8 @@ public void put(int key, T value) {
dll.deleteNode(dll.tail.pre);
if (dll.len == 0 && lowest != 1)
freq.remove(lowest);
DLL freq_one = freq.computeIfAbsent(1, k -> new DLL());
freq_one.addToHead(node);
DLL freqOne = freq.computeIfAbsent(1, k -> new DLL());
freqOne.addToHead(node);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/caching/LRUCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public void put(int key, T value) {
System.out.println("Cache set to 0 capacity. No elements will be cached");
}

T currentValue = cache.get(key);
if (!cache.containsKey(key)) {
cache.put(key, value);
System.out.println("Adding new key:" + key + " to cache");
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/ciphers/CaesarBruteForce.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
* @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).
*/
public String decrypt(String message, int Key) {
public String decrypt(String message, int key) {
final String LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if (Key > 26){ System.out.println(); return null; }
if (key > 26){ System.out.println(); return null; }

StringBuilder plainText = new StringBuilder();
for (char character : message.toUpperCase().toCharArray()) {
int index = LETTERS.indexOf(character);

if (index != -1) {
index -= Key;
index -= key;
//Wrap around index value range[1-26]
if (index < 0) { index += LETTERS.length(); }
plainText.append(LETTERS.toCharArray()[index]);
} else { plainText.append(character); }
}
System.out.println(String.format("Current Decryption Key %d : %s", Key, plainText));
return plainText.append(decrypt(message, Key+1)).toString();
System.out.println(String.format("Current Decryption Key %d : %s", key, plainText));
return plainText.append(decrypt(message, key+1)).toString();
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/conversions/HexadecimalToBinary.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class HexadecimalToBinary {
public String hexToBin (String hexStr) {

String binaryString = "", hexaNumbers = "0123456789ABCDEF",
DecimalStr ="", binaryStringBefore ="" , binaryStringAfter = "";
decimalStr ="", binaryStringBefore ="" , binaryStringAfter = "";
int indexOfHex, decimalNumber = 0, k = 1, n =1, z=1, decimalNumberBefore = 0
, decimalNumberAfter = 0;
char letter;
Expand Down Expand Up @@ -48,12 +48,12 @@ public String hexToBin (String hexStr) {

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
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dataStructures;
package com.datastructures;

/**
* Binary tree for general value type, without redundancy
Expand All @@ -8,7 +8,7 @@

public class BinaryTree<T extends Comparable> {
private final T data;
private BinaryTree right, // the upper binary tree
private BinaryTree<T> right, // the upper binary tree
left; // the lower binary tree

public BinaryTree(T data) {
Expand All @@ -21,35 +21,38 @@ public String toString() {
}

/**
* inserts a new value in it's correspondant place
* inserts a new value in it's correspondent place
*
* @param newDataValue value of the new binary tree to add on this tree
*/
public void insert(T newDataValue) {
this.insert(new BinaryTree(newDataValue));
this.insert(new BinaryTree<>(newDataValue));
}

/**
* inserts a new binary tree in it's correspondant place
* inserts a new binary tree in it's correspondent place
*
* @param newData new value to add on this tree
*/
public void insert(BinaryTree newData) {
public void insert(BinaryTree<T> newData) {

int cpr = newData.data.compareTo(this.data); //new value comparission respect to actual value

if (cpr < 0)
if (this.left == null)
if (cpr < 0) {
if (this.left == null) {
this.setLeft(newData);
else
} else {
this.left.insert(newData);
else if (cpr > 0)
if (this.right == null)
}
} else if (cpr > 0) {
if (this.right == null) {
this.setRight(newData);
else
} else {
this.right.insert(newData);
else
}
} else {
System.out.println("Redundant value, not added");
}
}

/**
Expand All @@ -58,8 +61,8 @@ else if (cpr > 0)
* @param data Searched value
* @return Binary tree which contains the value, null if it doesn't exist
*/
public BinaryTree search(T data) {
int cpr = data.compareTo(this.data); //new value comparission respect to actual value
public BinaryTree<T> search(T data) {
int cpr = data.compareTo(this.data); //new value comparison respect to actual value

if (cpr < 0) {
if (this.left == null)
Expand Down Expand Up @@ -113,19 +116,19 @@ public T getData() {
return data;
}

public BinaryTree getRight() {
public BinaryTree<T> getRight() {
return right;
}

public void setRight(BinaryTree right) {
public void setRight(BinaryTree<T> right) {
this.right = right;
}

public BinaryTree getLeft() {
public BinaryTree<T> getLeft() {
return left;
}

public void setLeft(BinaryTree left) {
public void setLeft(BinaryTree<T> left) {
this.left = left;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dataStructures;
package com.datastructures;

import java.io.Serializable;
import java.util.*;
Expand All @@ -18,14 +18,15 @@
*/
public class DisjointSet<T> implements Serializable {
private static final long serialVersionUID = 3134700471905625636L;
private static final String elementKey = "element";

private Map<T, Node<T>> nodeMap = new HashMap<>();
private final Map<T, Node<T>> nodeMap = new HashMap<>();

/**
* Add an element to the disjoint-set forests as a set.
*/
public void makeSet(T element) {
checkNotNull(element, "element");
checkNotNull(element, elementKey);
nodeMap.putIfAbsent(element, new Node<>());
}

Expand All @@ -36,8 +37,8 @@ public void makeSet(T element) {
* Rank is an upper bound on the height of node.
*/
public void union(T left, T right) {
checkNotNull(left, "element");
checkNotNull(right, "element");
checkNotNull(left, elementKey);
checkNotNull(right, elementKey);

Node<T> leftNode = nodeMap.get(left),
rightNode = nodeMap.get(right);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dataStructures;
package com.datastructures;

import com.types.Queue;

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dataStructures;
package com.datastructures;



Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dataStructures;
package com.datastructures;

import java.io.Serializable;
import java.util.EmptyStackException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.matchings.stableMatching;
package com.matchings.stablematching;

public class GaleShapley {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dataStructures;
package com.datastructures;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dataStructures;
package com.datastructures;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dataStructures;
package com.datastructures;


import com.types.Queue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dataStructures;
package com.datastructures;

import static org.junit.Assert.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dataStructures;
package com.datastructures;

import org.junit.Test;
import org.junit.jupiter.api.Assertions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dataStructures;
package com.datastructures;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.matchings.stableMatching;
package com.matchings.stablematching;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand Down