8000 1,消除非收检警告 · ownermz/javaalgorithm@da23fc5 · GitHub
[go: up one dir, main page]

Skip to content {"props":{"docsUrl":"https://docs.github.com/get-started/accessibility/keyboard-shortcuts"}}

Commit da23fc5

Browse files
author
shengshijun
committed
1,消除非收检警告
2,把手动复制数组改成System.arraycopy 3,简化部分代码。
1 parent 382122f commit da23fc5

File tree

11 files changed

+19
-22
lines changed

11 files changed

+19
-22
lines changed

src/main/java/ssj/algorithm/collections/HashMap.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ protected Node<K, V> newNode(K key, V value) {
4242
return new Node<>(key, value, null);
4343
}
4444

45+
@SuppressWarnings("unchecked")
4546
protected Node<K, V>[] newNodeArray(int size) {
4647
return (Node<K, V>[]) (new Node[size]);
4748
}

src/main/java/ssj/algorithm/collections/LinkedHashMap.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ protected Node<K, V> newNode(K key, V value) {
3030
}
3131

3232
@Override
33+
@SuppressWarnings("unchecked")
3334
protected Node<K, V>[] newNodeArray(int size) {
3435
return (LinkedNode<K, V>[]) (new LinkedNode[size]);
3536
}

src/main/java/ssj/algorithm/collections/LinkedList.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ public boolean equals(Object obj) {
211211
return false;
212212
}
213213
Node this_cur_node = this._head.getNext();
214+
@SuppressWarnings("unchecked")
214215
Node that_cur_node = list._head.getNext();
215216
while (this_cur_node != _head && that_cur_node != list._head) {
216217
if (!this_cur_node.getValue().equals(that_cur_node.getValue())) {
@@ -338,6 +339,7 @@ public boolean equals(Object o) {
338339
if (this == o) return true;
339340
if (o == null || getClass() != o.getClass()) return false;
340341

342+
@SuppressWarnings("unchecked")
341343
Node node = (Node) o;
342344

343345
if (next != null ? !next.equals(node.next) : node.next != null) return false;

src/main/java/ssj/algorithm/collections/SkipList.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ public boolean equals(Object o) {
266266
if (this == o) return true;
267267
if (o == null || getClass() != o.getClass()) return false;
268268

269+
@SuppressWarnings("unchecked")
269270
Node node = (Node) o;
270271

271272
if (!value.equals(node.value)) return false;

src/main/java/ssj/algorithm/collections/SortedSet.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/main/java/ssj/algorithm/collections/TreeMap.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ private void checkCurrencyModify(int expect_size) {
7777
@Override
7878
public String toString() {
7979
StringBuilder sb = new StringBuilder("TreeMap { \n");
80-
Iterator<Node> iterator = _tree.iterator();
81-
while (iterator.hasNext()) {
82-
sb.append(iterator.next());
80+
for (Node a_tree : _tree) {
81+
sb.append(a_tree);
8382
sb.append("\n");
8483
}
8584
sb.append("}");
@@ -167,11 +166,11 @@ public boolean equals(Object o) {
167166
if (this == o) return true;
168167
if (o == null || getClass() != o.getClass()) return false;
169168

169+
@SuppressWarnings("unchecked")
170170
Node node = (Node) o;
171171

172-
if (!getKey().equals(node.getKey())) return false;
172+
return getKey().equals(node.getKey());
173173

174-
return true;
175174
}
176175

177176
@Override

src/main/java/ssj/algorithm/collections/Trie.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ public boolean equals(Object o) {
112112
if (this == o) return true;
113113
if (o == null || getClass() != o.getClass()) return false;
114114

115+
@SuppressWarnings("unchecked")
115116
Node node = (Node) o;
116117

117-
if (value != node.value) return false;
118+
return value == node.value;
118119

119-
return true;
120120
}
121121

122122
@Override

src/main/java/ssj/algorithm/collections/Vector.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public Vector() {
3232
}
3333

3434
@Override
35+
@SuppressWarnings("unchecked")
3536
public T get(int index) {
3637
Preconditions.checkPositionIndex(index, size());
3738
return (T) _values[index];
@@ -46,9 +47,7 @@ public void set(int index, T ele) {
4647

4748
@Override
4849
public void remove(int index) {
49-
for (int i = index; i < size() - 1; i++) {
50-
_values[i] = _values[i + 1];
51-
}
50+
System.arraycopy(_values, index + 1, _values, index, size() - 1 - index);
5251
_cur_pointer--;
5352
}
5453

@@ -59,6 +58,7 @@ public T binarySearch(T ele, Comparator<T> comparator) {
5958
public T binarySearch(T ele, int from, int to, Comparator<T> comparator) {
6059
Preconditions.checkNotNull(ele);
6160
Preconditions.checkNotNull(comparator);
61+
@SuppressWarnings("unchecked")
6262
int ele_index = Arrays.binarySearch((T[]) _values, from, to, ele, comparator);
6363
if (ele_index == -1) {
6464
return null;
@@ -131,6 +131,7 @@ private int extendSize() {
131131
}
132132

133133
public Vector<T> sortThis(Comparator<T> comparator) {
134+
@SuppressWarnings("unchecked")
134135
T[] new_arr = (T[]) _values;
135136
ArrayUtil.sort(new_arr, comparator);
136137
_values = new_arr;

src/main/java/ssj/algorithm/math/MathUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static double max(double... vals) {
3131
return max_value;
3232
}
3333

34-
public static <T extends Comparable> T max(T... vals) {
34+
public static <T extends Comparable<T>> T max(T... vals) {
3535
Preconditions.checkNotNull(vals, "vals should not be null");
3636
Preconditions.checkArgument(vals.length > 0, "vals should not be empty");
3737

@@ -82,6 +82,7 @@ private static boolean doubleEqual(double one, double two) {
8282
return Math.abs(one - two) < 0.0000001;
8383
}
8484

85+
@SafeVarargs
8586
public static <T extends Comparable<T>> T min(T... arr) {
8687
Preconditions.checkNotNull(arr);
8788
if (arr.length == 0) {

src/main/java/ssj/algorithm/string/StringBuilder.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ public void append(Object ele) {
5353

5454
public void remove(int index) {
5555
Preconditions.checkPositionIndex(index, size());
56-
for (int j = index; j < size() - 1; j++) {
57-
_interval_string[j] = _interval_string[j + 1];
58-
}
56+
System.arraycopy(_interval_string, index + 1, _interval_string, index, size() - 1 - index);
5957
_cur_point--;
6058
}
6159

src/test/java/ssj/algorithm/string/StringBuilderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public void testDelete() {
3434
sb.append(i);
3535
}
3636
assertEquals(sb.size(), 10);
37-
sb.remove(1);
3837
sb.remove(9);
38+
sb.remove(1);
3939
assertEquals(sb.size(), 8);
4040
assertEquals(sb.toString(), "02345678");
4141
sb.delete('8');

0 commit comments

Comments
 (0)
0