Skip to content

Commit a116493

Browse files
authored
Fixed sonar warnings.
1 parent 2cd1315 commit a116493

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

src/main/java/g1901_2000/s1912_design_movie_rental_system/MovieRentingSystem.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
import java.util.List;
1212
import java.util.TreeSet;
1313

14+
@SuppressWarnings("java:S1172")
1415
public class MovieRentingSystem {
15-
16-
static class Point {
16+
private static class Point {
1717
int movie;
1818
int shop;
1919
int price;
@@ -25,10 +25,9 @@ public Point(int movie, int shop, int price) {
2525
}
2626
}
2727

28-
HashMap<Integer, TreeSet<Point>> unrentedMovies = new HashMap<>();
29-
HashMap<String, Integer> shopMovieToPrice = new HashMap<>();
30-
31-
Comparator<Point> comparator =
28+
private HashMap<Integer, TreeSet<Point>> unrentedMovies = new HashMap<>();
29+
private HashMap<String, Integer> shopMovieToPrice = new HashMap<>();
30+
private Comparator<Point> comparator =
3231
(o1, o2) -> {
3332
if (o1.price != o2.price) {
3433
return Integer.compare(o1.price, o2.price);
@@ -38,18 +37,14 @@ public Point(int movie, int shop, int price) {
3837
return Integer.compare(o1.movie, o2.movie);
3938
}
4039
};
41-
42-
TreeSet<Point> rented = new TreeSet<>(comparator);
40+
private TreeSet<Point> rented = new TreeSet<>(comparator);
4341

4442
public MovieRentingSystem(int n, int[][] entries) {
45-
4643
for (int[] entry : entries) {
4744
int shop = entry[0];
4845
int movie = entry[1];
4946
int price = entry[2];
50-
5147
unrentedMovies.putIfAbsent(movie, new TreeSet<>(comparator));
52-
5348
unrentedMovies.get(movie).add(new Point(movie, shop, price));
5449
shopMovieToPrice.put(shop + "+" + movie, price);
5550
}

src/main/java/g1901_2000/s1923_longest_common_subpath/Solution.java

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

33
import java.util.HashSet;
44

5-
class Solution {
5+
@SuppressWarnings("java:S1172")
6+
public class Solution {
67
private static final long BASE = 100001;
78
private static final long MOD = (long) (Math.pow(10, 11) + 7);
89
private long[] pow;
@@ -15,23 +16,19 @@ public int longestCommonSubpath(int n, int[][] paths) {
1516
}
1617
pow = new long[min + 1];
1718
pow[0]++;
18-
1919
for (int i = 1; i <= min; i++) {
2020
pow[i] = (pow[i - 1] * BASE) % MOD;
2121
}
22-
2322
int st = 1;
2423
int end = min;
2524
int mid = (st + end) / 2;
26-
2725
while (st <= end) {
2826
if (commonSubstring(paths, mid)) {
2927
res = mid;
3028
st = mid + 1;
3129
} else {
3230
end = mid - 1;
3331
}
34-
3532
mid = (st + end) / 2;
3633
}
3734
return res;
@@ -51,17 +48,14 @@ private boolean commonSubstring(int[][] paths, int l) {
5148
private HashSet<Long> rollingHash(int[] a, int l) {
5249
HashSet<Long> set = new HashSet<>();
5350
long hash = 0;
54-
5551
for (int i = 0; i < l; i++) {
5652
hash = (hash * BASE + a[i]) % MOD;
5753
}
5854
set.add(hash);
59-
6055
for (int n = a.length, curr = l, prev = 0; curr < n; prev++, curr++) {
6156
hash = (((hash * BASE) % MOD - (a[prev] * pow[l]) % MOD + a[curr]) + MOD) % MOD;
6257
set.add(hash);
6358
}
64-
6559
return set;
6660
}
6761
}

0 commit comments

Comments
 (0)