-
-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Null checks + minor fixes (#640)
* readability * Refactor: enhanced for loop * typo fix, added a type test, added a check to avoid NullPointerException, added logger * fix:remove extra line in docker readme (#638) * typo in method * minor fix * reordered modifiers * final method in final class * Condition 'v2 != null' is always 'true' when reached * final method in final class * identical method * final method in final class * null check * null checks and redundant conditional * null check * added a private constructor, error messages --------- Co-authored-by: Amin Malek Mohammadi <[email protected]>
- Loading branch information
Showing
2 changed files
with
149 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
Subject: [PATCH] Uncommitted changes before rebase [Changes] | ||
--- | ||
Index: bundles/sirix-core/src/main/java/org/sirix/utils/IntToObjectMap.java | ||
IDEA additional info: | ||
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | ||
<+>UTF-8 | ||
=================================================================== | ||
diff --git a/bundles/sirix-core/src/main/java/org/sirix/utils/IntToObjectMap.java b/bundles/sirix-core/src/main/java/org/sirix/utils/IntToObjectMap.java | ||
--- a/bundles/sirix-core/src/main/java/org/sirix/utils/IntToObjectMap.java | ||
+++ b/bundles/sirix-core/src/main/java/org/sirix/utils/IntToObjectMap.java | ||
@@ -1,7 +1,11 @@ | ||
package org.sirix.utils; | ||
|
||
+import org.slf4j.Logger; | ||
+import org.slf4j.LoggerFactory; | ||
+ | ||
import java.util.Arrays; | ||
import java.util.Iterator; | ||
+import java.util.NoSuchElementException; | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
@@ -137,9 +141,13 @@ | ||
|
||
@SuppressWarnings("unchecked") | ||
public T next() { | ||
+ if (!iterator.hasNext()) { | ||
+ throw new NoSuchElementException(); | ||
+ } | ||
return (T) values[iterator.next()]; | ||
} | ||
|
||
+ @Override | ||
public void remove() { | ||
iterator.remove(); | ||
} | ||
@@ -151,7 +159,7 @@ | ||
private static int defaultCapacity = 16; | ||
|
||
/** | ||
- * Holds the base hash entries. if the capacity is 2^N, than the base hash | ||
+ * Holds the base hash entries. if the capacity is 2^N, thn the base hash | ||
* holds 2^(N+1). It can hold | ||
*/ | ||
int[] baseHash; | ||
@@ -301,7 +309,7 @@ | ||
// And setting all the <code>next[i]</code> to point at | ||
// <code>i+1</code>. | ||
for (int i = 1; i < this.capacity; ) { | ||
- next[i] = ++i; | ||
+ next[i] = i + 1; | ||
} | ||
|
||
// Surly, the last one should point to the 'Ground'. | ||
@@ -329,8 +337,7 @@ | ||
* false otherwise. | ||
*/ | ||
public boolean containsValue(Object o) { | ||
- for (Iterator<T> iterator = iterator(); iterator.hasNext(); ) { | ||
- T object = iterator.next(); | ||
+ for (T object : this) { | ||
if (object.equals(o)) { | ||
return true; | ||
} | ||
@@ -353,7 +360,7 @@ | ||
|
||
// while the index does not point to the 'Ground' | ||
while (localIndex != 0) { | ||
- // returns the index found in case of of a matching key. | ||
+ // returns the index found in case of a matching key. | ||
if (keys[localIndex] == key) { | ||
return localIndex; | ||
} | ||
@@ -384,7 +391,7 @@ | ||
|
||
// while the index does not point to the 'Ground' | ||
while (index != 0) { | ||
- // returns the index found in case of of a matching key. | ||
+ // returns the index found in case of a matching key. | ||
if (keys[index] == key) { | ||
return index; | ||
} | ||
@@ -465,7 +472,7 @@ | ||
@SuppressWarnings("unused") | ||
private void printBaseHash() { | ||
for (int i = 0; i < this.baseHash.length; i++) { | ||
- System.out.println(i + ".\t" + baseHash[i]); | ||
+ LOGGER.info("{}.\t{}", i, baseHash[i]); | ||
} | ||
} | ||
|
||
@@ -491,7 +498,7 @@ | ||
|
||
// Is there enough room for a new pair? | ||
if (size == capacity) { | ||
- // No? Than grow up! | ||
+ // No? Then grow up! | ||
grow(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters