Skip to content

Commit 6763466

Browse files
committed
Bridge the gap between Iterable and ALStack.
1 parent 5d4d082 commit 6763466

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

‎stream/LimitFilter.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ of this software and associated documentation files (the "Software"), to deal
2626

2727
import org.json.stream.JSONStreamReader.ParseState;
2828
import org.json.util.JSONPointerUtils;
29+
import org.json.util.SizedIterable;
2930

3031
/**
3132
* Filtering for structures during a parse. Provided by the {@link BuilderLimits}
@@ -46,7 +47,7 @@ public interface LimitFilter {
4647
* @return {@code true} to allow the value to be created, otherwise
4748
* {@code false} to skip the value
4849
*/
49-
boolean acceptIndex(int index, ParseState state, Iterable<StructureBuilder> stack);
50+
boolean acceptIndex(int index, ParseState state, SizedIterable<StructureBuilder> stack);
5051

5152
/**
5253
* Determine whether to accept or reject a value within an object.
@@ -58,6 +59,6 @@ public interface LimitFilter {
5859
* @return {@code true} to allow the value to be created, otherwise
5960
* {@code false} to skip the value
6061
*/
61-
boolean acceptField(String fieldName, ParseState state, Iterable<StructureBuilder> stack);
62+
boolean acceptField(String fieldName, ParseState state, SizedIterable<StructureBuilder> stack);
6263

6364
}

‎util/ALStack.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ of this software and associated documentation files (the "Software"), to deal
3535
* @author JSON.org
3636
* @version 2016-6-30
3737
*/
38-
public final class ALStack<E> implements Iterable<E> {
38+
public final class ALStack<E> implements SizedIterable<E> {
3939
private final ArrayList<E> elements;
4040

4141
/**
@@ -97,6 +97,7 @@ public E peek() throws EmptyStackException {
9797
*
9898
* @return {@code true} if the stack is empty, otherwise {@code false}
9999
*/
100+
@Override
100101
public boolean isEmpty() {
101102
return elements.isEmpty();
102103
}
@@ -106,6 +107,7 @@ public boolean isEmpty() {
106107
*
107108
* @return the number of elements on the stack
108109
*/
110+
@Override
109111
public int size() {
110112
return elements.size();
111113
}

‎util/SizedIterable.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.json.util;
2+
3+
/**
4+
* Adds size information to an {@code Iterable}. For when a {@code Collection}
5+
* has too big a contract.
6+
*
7+
* @author JSON.org
8+
* @version 2016-08-07
9+
*/
10+
public interface SizedIterable<T> extends Iterable<T> {
11+
12+
int size();
13+
14+
boolean isEmpty();
15+
16+
}

0 commit comments

Comments
 (0)