Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdd3b2d2

Browse files
committed
Fixed code smells detected by SonarQube - PR#1429
TheAlgorithms#1429
1 parent32b02af commitdd3b2d2

File tree

18 files changed

+53
-50
lines changed

18 files changed

+53
-50
lines changed

‎src/main/java/com/caching/LFUCache.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public void deleteNode(Node node) {
7575
publicLFUCache(intcapacity) {
7676
this.capacity =capacity;
7777
size =0;
78-
freq =newTreeMap<Integer,DLL>();
79-
map =newHashMap<Integer,Node>();
78+
freq =newTreeMap<>();
79+
map =newHashMap<>();
8080
System.out.println("LFUCache initialised with capacity: " +capacity);
8181
}
8282

@@ -145,8 +145,8 @@ public void put(int key, T value) {
145145
dll.deleteNode(dll.tail.pre);
146146
if (dll.len ==0 &&lowest !=1)
147147
freq.remove(lowest);
148-
DLLfreq_one =freq.computeIfAbsent(1,k ->newDLL());
149-
freq_one.addToHead(node);
148+
DLLfreqOne =freq.computeIfAbsent(1,k ->newDLL());
149+
freqOne.addToHead(node);
150150
}
151151
}
152152

‎src/main/java/com/caching/LRUCache.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public void put(int key, T value) {
6363
System.out.println("Cache set to 0 capacity. No elements will be cached");
6464
}
6565

66-
TcurrentValue =cache.get(key);
6766
if (!cache.containsKey(key)) {
6867
cache.put(key,value);
6968
System.out.println("Adding new key:" +key +" to cache");

‎src/main/java/com/ciphers/CaesarBruteForce.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ public class CaesarBruteForce {
55
/**
66
* Recursively Brute forces a parsed encrypted text, trying out all shifting keys from 1-26, printing out all decryption attempts
77
* @param message (String) The encrypted text.
8-
* @paramKey (int) The key used to decrypt the encrypted text and is increment upon a recursive call.
8+
* @paramkey (int) The key used to decrypt the encrypted text and is increment upon a recursive call.
99
* @return (String) Concatenated string of all decryption attempts (For unit testing purposes).
1010
*/
11-
publicStringdecrypt(Stringmessage,intKey) {
11+
publicStringdecrypt(Stringmessage,intkey) {
1212
finalStringLETTERS ="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
13-
if (Key >26){System.out.println();returnnull; }
13+
if (key >26){System.out.println();returnnull; }
1414

1515
StringBuilderplainText =newStringBuilder();
1616
for (charcharacter :message.toUpperCase().toCharArray()) {
1717
intindex =LETTERS.indexOf(character);
1818

1919
if (index != -1) {
20-
index -=Key;
20+
index -=key;
2121
//Wrap around index value range[1-26]
2222
if (index <0) {index +=LETTERS.length(); }
2323
plainText.append(LETTERS.toCharArray()[index]);
2424
}else {plainText.append(character); }
2525
}
26-
System.out.println(String.format("Current Decryption Key %d : %s",Key,plainText));
27-
returnplainText.append(decrypt(message,Key+1)).toString();
26+
System.out.println(String.format("Current Decryption Key %d : %s",key,plainText));
27+
returnplainText.append(decrypt(message,key+1)).toString();
2828
}
2929
}

‎src/main/java/com/conversions/HexadecimalToBinary.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class HexadecimalToBinary {
1212
publicStringhexToBin (StringhexStr) {
1313

1414
StringbinaryString ="",hexaNumbers ="0123456789ABCDEF",
15-
DecimalStr ="",binaryStringBefore ="" ,binaryStringAfter ="";
15+
decimalStr ="",binaryStringBefore ="" ,binaryStringAfter ="";
1616
intindexOfHex,decimalNumber =0,k =1,n =1,z=1,decimalNumberBefore =0
1717
,decimalNumberAfter =0;
1818
charletter;
@@ -48,12 +48,12 @@ public String hexToBin (String hexStr) {
4848

4949
StringdecimalNumberAfterStr =String.valueOf(decimalNumberAfter);
5050

51-
DecimalStr =decimalNumberBeforeStr +'.' +decimalNumberAfterStr;
51+
decimalStr =decimalNumberBeforeStr +'.' +decimalNumberAfterStr;
5252
}
5353

5454

5555

56-
intpointPositionDec =DecimalStr.indexOf(".");
56+
intpointPositionDec =decimalStr.indexOf(".");
5757
/**
5858
* Check whether the result contains a floating point or not
5959
*/

‎src/main/java/com/datastructures/BinaryTree.java‎

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packagecom.dataStructures;
1+
packagecom.datastructures;
22

33
/**
44
* Binary tree for general value type, without redundancy
@@ -8,7 +8,7 @@
88

99
publicclassBinaryTree<TextendsComparable> {
1010
privatefinalTdata;
11-
privateBinaryTreeright,// the upper binary tree
11+
privateBinaryTree<T>right,// the upper binary tree
1212
left;// the lower binary tree
1313

1414
publicBinaryTree(Tdata) {
@@ -21,35 +21,38 @@ public String toString() {
2121
}
2222

2323
/**
24-
* inserts a new value in it'scorrespondant place
24+
* inserts a new value in it'scorrespondent place
2525
*
2626
* @param newDataValue value of the new binary tree to add on this tree
2727
*/
2828
publicvoidinsert(TnewDataValue) {
29-
this.insert(newBinaryTree(newDataValue));
29+
this.insert(newBinaryTree<>(newDataValue));
3030
}
3131

3232
/**
33-
* inserts a new binary tree in it'scorrespondant place
33+
* inserts a new binary tree in it'scorrespondent place
3434
*
3535
* @param newData new value to add on this tree
3636
*/
37-
publicvoidinsert(BinaryTreenewData) {
37+
publicvoidinsert(BinaryTree<T>newData) {
3838

3939
intcpr =newData.data.compareTo(this.data);//new value comparission respect to actual value
4040

41-
if (cpr <0)
42-
if (this.left ==null)
41+
if (cpr <0) {
42+
if (this.left ==null) {
4343
this.setLeft(newData);
44-
else
44+
}else {
4545
this.left.insert(newData);
46-
elseif (cpr >0)
47-
if (this.right ==null)
46+
}
47+
}elseif (cpr >0) {
48+
if (this.right ==null) {
4849
this.setRight(newData);
49-
else
50+
}else {
5051
this.right.insert(newData);
51-
else
52+
}
53+
}else {
5254
System.out.println("Redundant value, not added");
55+
}
5356
}
5457

5558
/**
@@ -58,8 +61,8 @@ else if (cpr > 0)
5861
* @param data Searched value
5962
* @return Binary tree which contains the value, null if it doesn't exist
6063
*/
61-
publicBinaryTreesearch(Tdata) {
62-
intcpr =data.compareTo(this.data);//new valuecomparission respect to actual value
64+
publicBinaryTree<T>search(Tdata) {
65+
intcpr =data.compareTo(this.data);//new valuecomparison respect to actual value
6366

6467
if (cpr <0) {
6568
if (this.left ==null)
@@ -113,19 +116,19 @@ public T getData() {
113116
returndata;
114117
}
115118

116-
publicBinaryTreegetRight() {
119+
publicBinaryTree<T>getRight() {
117120
returnright;
118121
}
119122

120-
publicvoidsetRight(BinaryTreeright) {
123+
publicvoidsetRight(BinaryTree<T>right) {
121124
this.right =right;
122125
}
123126

124-
publicBinaryTreegetLeft() {
127+
publicBinaryTree<T>getLeft() {
125128
returnleft;
126129
}
127130

128-
publicvoidsetLeft(BinaryTreeleft) {
131+
publicvoidsetLeft(BinaryTree<T>left) {
129132
this.left =left;
130133
}
131134
}

‎src/main/java/com/datastructures/DisjointSet.java‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packagecom.dataStructures;
1+
packagecom.datastructures;
22

33
importjava.io.Serializable;
44
importjava.util.*;
@@ -18,14 +18,15 @@
1818
*/
1919
publicclassDisjointSet<T>implementsSerializable {
2020
privatestaticfinallongserialVersionUID =3134700471905625636L;
21+
privatestaticfinalStringelementKey ="element";
2122

22-
privateMap<T,Node<T>>nodeMap =newHashMap<>();
23+
privatefinalMap<T,Node<T>>nodeMap =newHashMap<>();
2324

2425
/**
2526
* Add an element to the disjoint-set forests as a set.
2627
*/
2728
publicvoidmakeSet(Telement) {
28-
checkNotNull(element,"element");
29+
checkNotNull(element,elementKey);
2930
nodeMap.putIfAbsent(element,newNode<>());
3031
}
3132

@@ -36,8 +37,8 @@ public void makeSet(T element) {
3637
* Rank is an upper bound on the height of node.
3738
*/
3839
publicvoidunion(Tleft,Tright) {
39-
checkNotNull(left,"element");
40-
checkNotNull(right,"element");
40+
checkNotNull(left,elementKey);
41+
checkNotNull(right,elementKey);
4142

4243
Node<T>leftNode =nodeMap.get(left),
4344
rightNode =nodeMap.get(right);

‎src/main/java/com/datastructures/GeneralQueue.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packagecom.dataStructures;
1+
packagecom.datastructures;
22

33
importcom.types.Queue;
44

‎src/main/java/com/datastructures/IntQueue.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packagecom.dataStructures;
1+
packagecom.datastructures;
22

33
/**
44
* This file contains an implementation of an integer only queue which is extremely quick and

‎src/main/java/com/datastructures/SinglyLinkedList.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packagecom.dataStructures;
1+
packagecom.datastructures;
22

33

44

‎src/main/java/com/datastructures/Stack.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packagecom.dataStructures;
1+
packagecom.datastructures;
22

33
importjava.io.Serializable;
44
importjava.util.EmptyStackException;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp