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

0 commit comments

Comments
 (0)