Skip to content

Commit

Permalink
added CF annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Jan 8, 2024
1 parent 6f3728c commit 1c2fb6b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.util.NoSuchElementException;
import java.util.Set;

import org.checkerframework.checker.initialization.qual.UnknownInitialization;
import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;
import org.checkerframework.checker.nullness.qual.Nullable;

import io.usethesource.vallang.IValue;
Expand Down Expand Up @@ -454,9 +456,9 @@ public String toString(){
}

private static class SetIterator implements Iterator<IValue>{
private final Entry<IValue>[] data;
private final Entry<IValue>@Nullable[] data;

private Entry<IValue> current;
private @Nullable Entry<IValue> current;
private int index;

public SetIterator(Entry<IValue>[] entries){
Expand All @@ -469,7 +471,7 @@ public SetIterator(Entry<IValue>[] entries){
locateNext();
}

private void locateNext(){
private void locateNext(@UnknownInitialization SetIterator this) {
Entry<IValue> next = current.next;
if(next != null){
current = next;
Expand All @@ -489,20 +491,26 @@ private void locateNext(){
index = 0;
}

@EnsuresNonNullIf(expression="this.current", result=true)
@Override
public boolean hasNext(){
return (current != null);
}

@Override
public IValue next(){
if(!hasNext()) throw new NoSuchElementException("There are no more elements in this iteration");
if (!hasNext()) {
throw new NoSuchElementException("There are no more elements in this iteration");
}

IValue value = current.value;
locateNext();

return value;
}

public void remove(){
@Override
public void remove() {
throw new UnsupportedOperationException("This iterator doesn't support removal.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.NoSuchElementException;
import java.util.Set;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
Expand Down Expand Up @@ -162,8 +163,13 @@ private void ensureCapacity(){
* The value to insert.
* @return Returns true if this set didn't contain the given value yet; false if it did.
*/
@Override
public boolean add(V value){
ensureCapacity();

if (value == null) {
throw new NullPointerException();
}

int hash = value.hashCode();
int position = hash & hashMask;
Expand Down

0 comments on commit 1c2fb6b

Please sign in to comment.