Skip to content

Commit

Permalink
Iterator.remove() has a default implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Feb 25, 2020
1 parent 9e8bbfd commit e10a64e
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 23 deletions.
4 changes: 0 additions & 4 deletions src/main/java/org/kohsuke/github/GHNotificationStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,6 @@ private long calcNextCheckTime(GitHubResponse<GHThread[]> response) {
long seconds = Integer.parseInt(v);
return System.currentTimeMillis() + seconds * 1000;
}

public void remove() {
throw new UnsupportedOperationException();
}
};
}

Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/kohsuke/github/GHPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ public List<GHRepository> next() {
r.root = root;
return Arrays.asList(batch);
}

public void remove() {
throw new UnsupportedOperationException();
}
};
}
};
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/kohsuke/github/GitHubPageIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ public GitHubResponse<T> finalResponse() {
return finalResponse;
}

public void remove() {
throw new UnsupportedOperationException();
}

/**
* Fetch is called at the start of {@link #hasNext()} or {@link #next()} to fetch another page of data if it is
* needed.
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/kohsuke/github/PagedIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ private void fetch() {
}
}

public void remove() {
throw new UnsupportedOperationException();
}

/**
* Gets the next page worth of data.
*
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/org/kohsuke/github/PagedSearchIterable.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ private void populate() {
}

/**
* Adapts {@link Iterator}.
* Adapts from {@link Iterator<SearchResult<T>>} to {@link Iterator<T[]>}.
*
* @param base
* the base
* @return the iterator
* {@link Iterator<SearchResult<T>>} to adapt.
* @return a {@link Iterator<T[]>} wrapping the base {@link Iterator<SearchResult<T>>}.
*/
protected Iterator<T[]> adapt(final Iterator<? extends SearchResult<T>> base) {
return new Iterator<T[]>() {
Expand All @@ -75,10 +75,6 @@ public T[] next() {
result = v;
return v.getItems(root);
}

public void remove() {
throw new UnsupportedOperationException();
}
};
}
}
8 changes: 8 additions & 0 deletions src/test/java/org/kohsuke/github/GitHubTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ public void testListAllRepositories() throws Exception {
assertNotNull(r.getUrl());
assertNotEquals(0L, r.getId());
}

// ensure the iterator throws as expected
try {
itr.remove();
fail();
} catch (UnsupportedOperationException e) {
assertThat(e, notNullValue());
}
}

@Test
Expand Down

0 comments on commit e10a64e

Please sign in to comment.