Skip to content

Commit 368358c

Browse files
committed
Fix some code inspection warnings
1 parent c9f5d6d commit 368358c

17 files changed

+40
-47
lines changed

src/main/java/by/andd3dfx/collections/StackWithMinSupportO1.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
*/
1919
public class StackWithMinSupportO1 {
2020

21-
private Deque<Integer> stack = new ArrayDeque<>();
22-
private Deque<Integer> minHistoryStack = new ArrayDeque<>();
21+
private final Deque<Integer> stack = new ArrayDeque<>();
22+
private final Deque<Integer> minHistoryStack = new ArrayDeque<>();
2323

2424
public void push(int element) {
2525
stack.push(element);
@@ -30,7 +30,7 @@ public void push(int element) {
3030
}
3131

3232
public int pop() {
33-
Integer result = stack.pop();
33+
var result = stack.pop();
3434
if (minHistoryStack.peek() == result) {
3535
minHistoryStack.pop();
3636
}

src/main/java/by/andd3dfx/multithreading/forkjoin/CustomRecursiveTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private Collection<CustomRecursiveTask> createSubtasks() {
4141

4242
private Integer processNLog(int[] arr) {
4343
String threadName = Thread.currentThread().getName();
44-
logger.info(String.format("Work (%s) was processed by thread %s", arr, threadName));
44+
logger.info(String.format("Work (%s) was processed by thread %s", Arrays.toString(arr), threadName));
4545

4646
int result = process(arr);
4747
logger.info(String.format("Processed %s with result: %d", Arrays.toString(arr), result));

src/main/java/by/andd3dfx/numeric/MaxMultiplicationOf3InArray.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package by.andd3dfx.numeric;
22

33
import java.util.Arrays;
4-
import java.util.stream.Collectors;
54

65
import static java.lang.Math.max;
76

src/main/java/by/andd3dfx/proxy/SomeInterface1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package by.andd3dfx.proxy;
22

33
/**
4-
* Check usage of it in {@link ProxyCreationByInterfacesTest}
4+
* Check usage of it in tests
55
*/
66
public interface SomeInterface1 {
77

src/main/java/by/andd3dfx/proxy/SomeInterface2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package by.andd3dfx.proxy;
22

33
/**
4-
* Check usage of it in {@link ProxyCreationByInterfacesTest}
4+
* Check usage of it in tests
55
*/
66
public interface SomeInterface2 {
77

src/main/java/by/andd3dfx/refactoring/refactored/EventParser.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import java.util.EnumMap;
1010
import java.util.List;
11-
import java.util.stream.Collectors;
1211

1312
/**
1413
* @see <a href="https://youtu.be/jdnNYxVk5BE">Video solution</a>
@@ -19,7 +18,7 @@ public class EventParser {
1918

2019
static {
2120
Reflections reflections = new Reflections(IEventParser.class.getPackageName());
22-
reflections.getSubTypesOf(IEventParser.class).stream()
21+
reflections.getSubTypesOf(IEventParser.class)
2322
.forEach(aClass -> extracted(aClass));
2423

2524
for (EventType eventType : EventType.values()) {

src/main/java/by/andd3dfx/sorting/BubbleSort.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
public class BubbleSort {
77

8-
public static <T extends Comparable> void apply(T[] array) {
8+
public static <T extends Comparable<T>> void apply(T[] array) {
99
var sorted = false;
1010
while (!sorted) {
1111
sorted = true;
@@ -19,7 +19,7 @@ public static <T extends Comparable> void apply(T[] array) {
1919
}
2020
}
2121

22-
public static <T extends Comparable> void apply2(T[] array) {
22+
public static <T extends Comparable<T>> void apply2(T[] array) {
2323
for (var outIndex = array.length - 1; outIndex > 0; outIndex--) {
2424
for (var inIndex = 0; inIndex < outIndex; inIndex++) {
2525
if (array[inIndex].compareTo(array[inIndex + 1]) > 0) {

src/main/java/by/andd3dfx/sorting/BucketSort.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@ public class BucketSort {
77

88
private static final int BUCKETS_COUNT = 10;
99

10-
public static <T extends Comparable> void apply(T[] items) {
10+
public static <T extends Comparable<T>> void apply(T[] items) {
1111
// Prepare empty buckets
12-
List<List<Comparable>> buckets = new ArrayList<>(BUCKETS_COUNT);
12+
List<List<Comparable<T>>> buckets = new ArrayList<>(BUCKETS_COUNT);
1313
for (int i = 0; i < BUCKETS_COUNT; i++) {
1414
buckets.add(new ArrayList<>());
1515
}
1616

1717
// Fill in buckets
18-
for (T t : items) {
19-
var bucketIndex = determineBucketIndex(t, BUCKETS_COUNT);
18+
for (var t : items) {
19+
var bucketIndex = determineBucketIndex(t);
2020
buckets.get(bucketIndex).add(t);
2121
}
2222

2323
int currIndex = 0;
2424
for (int bucketIndex = 0; bucketIndex < BUCKETS_COUNT; bucketIndex++) {
25-
List<Comparable> bucket = buckets.get(bucketIndex);
25+
var bucket = buckets.get(bucketIndex);
2626

2727
// Sort elements in each bucket
28-
Comparable[] array = bucket.toArray(new Comparable[0]);
28+
var array = bucket.toArray(new Comparable[0]);
2929
InsertionSort.apply(array);
3030

3131
// Populate the result array with values from bucket
@@ -39,29 +39,29 @@ public static <T extends Comparable> void apply(T[] items) {
3939
/**
4040
* Not found better way, but sorter parameterized now
4141
*/
42-
private static int determineBucketIndex(Comparable element, int bucketsCount) {
42+
private static <T> int determineBucketIndex(Comparable<T> element) {
4343
if (element instanceof Integer) {
44-
return (int) ((bucketsCount - 1) *
44+
return (int) ((BUCKETS_COUNT - 1) *
4545
((Integer) element - (double) Integer.MIN_VALUE) / ((double) Integer.MAX_VALUE - (double) Integer.MIN_VALUE));
4646
}
4747
if (element instanceof Long) {
48-
return (int) ((bucketsCount - 1) *
48+
return (int) ((BUCKETS_COUNT - 1) *
4949
((Long) element - (double) Long.MIN_VALUE) / ((double) Long.MAX_VALUE - (double) Long.MIN_VALUE));
5050
}
5151
if (element instanceof Double) {
52-
return (int) ((bucketsCount - 1) *
52+
return (int) ((BUCKETS_COUNT - 1) *
5353
((Double) element - Double.MIN_VALUE) / (Double.MAX_VALUE - Double.MIN_VALUE));
5454
}
5555
if (element instanceof Float) {
56-
return (int) ((bucketsCount - 1) *
56+
return (int) ((BUCKETS_COUNT - 1) *
5757
((Float) element - Float.MIN_VALUE) / (Float.MAX_VALUE - Float.MIN_VALUE));
5858
}
5959
if (element instanceof Byte) {
60-
return (bucketsCount - 1) *
60+
return (BUCKETS_COUNT - 1) *
6161
((Byte) element - Byte.MIN_VALUE) / (Byte.MAX_VALUE - Byte.MIN_VALUE);
6262
}
6363
if (element instanceof Short) {
64-
return (bucketsCount - 1) *
64+
return (BUCKETS_COUNT - 1) *
6565
((Short) element - Byte.MIN_VALUE) / (Short.MAX_VALUE - Short.MIN_VALUE);
6666
}
6767

src/main/java/by/andd3dfx/sorting/HeapSort.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public class HeapSort {
44

5-
public static <T extends Comparable> void apply(T[] items) {
5+
public static <T extends Comparable<T>> void apply(T[] items) {
66
var n = items.length;
77

88
// Build heap (rearrange array)
@@ -22,7 +22,7 @@ public static <T extends Comparable> void apply(T[] items) {
2222

2323
// Heapify a subtree rooted with node items[root].
2424
// n is size of heap
25-
private static <T extends Comparable> void heapify(T[] items, int n, int root) {
25+
private static <T extends Comparable<T>> void heapify(T[] items, int n, int root) {
2626
var largest = root;
2727
var l = 2 * root + 1;
2828
var r = l + 1;
@@ -46,7 +46,7 @@ private static <T extends Comparable> void heapify(T[] items, int n, int root) {
4646
}
4747
}
4848

49-
private static <T extends Comparable> boolean greaterThan(T a, T b) {
49+
private static <T extends Comparable<T>> boolean greaterThan(T a, T b) {
5050
return a.compareTo(b) > 0;
5151
}
5252

src/main/java/by/andd3dfx/sorting/InsertionSort.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
public class InsertionSort {
99

10-
public static <T extends Comparable> void apply(T[] array) {
10+
public static <T extends Comparable<T>> void apply(T[] array) {
1111
for (int i = 1; i < array.length; i++) {
1212
var x = array[i];
1313

src/main/java/by/andd3dfx/sorting/MergeSort.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
public class MergeSort {
99

10-
public static <T extends Comparable> void apply(T[] items) {
10+
public static <T extends Comparable<T>> void apply(T[] items) {
1111
int n = items.length;
1212
if (n < 2) {
1313
return;
@@ -23,7 +23,7 @@ public static <T extends Comparable> void apply(T[] items) {
2323
merge(items, left, right);
2424
}
2525

26-
private static <T extends Comparable> void merge(T[] items, T[] left, T[] right) {
26+
private static <T extends Comparable<T>> void merge(T[] items, T[] left, T[] right) {
2727
int leftLength = left.length;
2828
int rightLength = right.length;
2929
int i = 0, j = 0, k = 0;
@@ -52,7 +52,7 @@ private static <T extends Comparable> void merge(T[] items, T[] left, T[] right)
5252
}
5353
}
5454

55-
private static <T extends Comparable> boolean lessOrEqualsThan(T a, T b) {
55+
private static <T extends Comparable<T>> boolean lessOrEqualsThan(T a, T b) {
5656
return a.compareTo(b) <= 0;
5757
}
5858
}

src/main/java/by/andd3dfx/sorting/QuickSort.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
*/
66
public class QuickSort {
77

8-
public static <T extends Comparable> void apply(T[] items) {
8+
public static <T extends Comparable<T>> void apply(T[] items) {
99
quickSort(items, 0, items.length - 1);
1010
}
1111

12-
private static <T extends Comparable> void quickSort(T[] items, int low, int high) {
12+
private static <T extends Comparable<T>> void quickSort(T[] items, int low, int high) {
1313
if (low < high) {
1414
int p = partition(items, low, high);
1515
quickSort(items, low, p);
1616
quickSort(items, p + 1, high);
1717
}
1818
}
1919

20-
private static <T extends Comparable> int partition(T[] items, int low, int high) {
20+
private static <T extends Comparable<T>> int partition(T[] items, int low, int high) {
2121
var v = items[(low + high) / 2];
2222
int i = low;
2323
int j = high;
@@ -40,11 +40,11 @@ private static <T extends Comparable> int partition(T[] items, int low, int high
4040
return j;
4141
}
4242

43-
private static <T extends Comparable> boolean lessThan(T a, T b) {
43+
private static <T extends Comparable<T>> boolean lessThan(T a, T b) {
4444
return a.compareTo(b) < 0;
4545
}
4646

47-
private static <T extends Comparable> boolean greaterThan(T a, T b) {
47+
private static <T extends Comparable<T>> boolean greaterThan(T a, T b) {
4848
return a.compareTo(b) > 0;
4949
}
5050

src/main/java/by/andd3dfx/sorting/SelectionSort.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
public class SelectionSort {
77

8-
public static <T extends Comparable> void apply(T[] array) {
8+
public static <T extends Comparable<T>> void apply(T[] array) {
99
for (int i = 0; i < array.length; i++) {
1010
int minIndex = i;
1111

@@ -17,7 +17,7 @@ public static <T extends Comparable> void apply(T[] array) {
1717
}
1818
}
1919

20-
private static <T extends Comparable> boolean lessThan(T a, T b) {
20+
private static <T extends Comparable<T>> boolean lessThan(T a, T b) {
2121
return a.compareTo(b) < 0;
2222
}
2323

src/main/java/by/andd3dfx/sorting/ShellSort.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
public class ShellSort {
77

8-
public static <T extends Comparable> void apply(T[] array) {
8+
public static <T extends Comparable<T>> void apply(T[] array) {
99
int d = 1;
1010

1111
while (d <= array.length / 3) {
@@ -28,7 +28,7 @@ public static <T extends Comparable> void apply(T[] array) {
2828
}
2929
}
3030

31-
private static <T extends Comparable> boolean greaterThan(T a, T b) {
31+
private static <T extends Comparable<T>> boolean greaterThan(T a, T b) {
3232
return a.compareTo(b) > 0;
3333
}
3434
}

src/main/java/by/andd3dfx/string/CaesarCipher.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package by.andd3dfx.string;
22

3-
import java.util.Arrays;
4-
import java.util.stream.Collectors;
5-
63
/**
74
* <pre>
85
* Расшифровка методом Цезаря

src/main/java/by/andd3dfx/string/LongestWordWithoutRepeatingChars.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package by.andd3dfx.string;
22

33
import java.util.HashSet;
4-
import java.util.Set;
54

65
/**
76
* <pre>
@@ -39,7 +38,7 @@ public static int determine(String s) {
3938
int max = 0;
4039

4140
var chars = s.toCharArray();
42-
Set set = new HashSet();
41+
var set = new HashSet<>();
4342

4443
while (right < chars.length) {
4544
if (set.contains(chars[right])) {

src/main/java/by/andd3dfx/string/Palindrome.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package by.andd3dfx.string;
22

33
import java.util.HashSet;
4-
import java.util.Set;
54

65
/**
76
* @see <a href="https://youtu.be/XZMOlvKRzd0">Video solution</a>
@@ -110,7 +109,7 @@ public static boolean canFormPalindrome(String str) {
110109
* Идея решения в том, что в палиндроме все символы встречаются четное кол-во раз, кроме, максимум одного символа.
111110
* Убеждаемся, что таких одиночных символов не более одного.
112111
*/
113-
Set set = new HashSet();
112+
var set = new HashSet<>();
114113
for (var ch : str.toCharArray()) {
115114
if (!set.contains(ch)) {
116115
set.add(ch);

0 commit comments

Comments
 (0)