Skip to content

Commit

Permalink
HSEARCH-4926 Improve casts in HashTable
Browse files Browse the repository at this point in the history
This doesn't change the behavior in practice, but is slightly more
correct, and will avoid Sonar reporting a bug.
  • Loading branch information
yrodiere committed Aug 25, 2023
1 parent 779d735 commit 283c85e
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
*/
public abstract class HashTable<T> implements Iterable<T> {

final T[] buckets;
final Object[] buckets;

@SuppressWarnings("unchecked")
HashTable(int size) {
this.buckets = (T[]) new Object[size];
this.buckets = new Object[size];
}

/**
Expand All @@ -41,11 +40,12 @@ public boolean hasNext() {
}

@Override
@SuppressWarnings("unchecked")
public T next() {
if ( !hasNext() ) {
throw new NoSuchElementException();
}
return buckets[index++];
return (T) buckets[index++];
}
};
}
Expand All @@ -63,8 +63,9 @@ public final T get(CharSequence key) {
* @return The content of the bucket at index {@code index}.
* @throws ArrayIndexOutOfBoundsException If the given index is negative or higher than the table's size.
*/
@SuppressWarnings("unchecked")
public final T get(int index) {
return buckets[index];
return (T) buckets[index];
}

/**
Expand Down

0 comments on commit 283c85e

Please sign in to comment.