44import java .util .NoSuchElementException ;
55import java .util .Spliterator ;
66import java .util .Spliterators ;
7+ import java .util .logging .Logger ;
78import java .util .PrimitiveIterator .OfInt ;
89import java .util .stream .IntStream ;
910import java .util .stream .StreamSupport ;
1011
1112public final class IntegerBitSet extends BaseIntegerSet {
13+ private static final Logger LOGGER = Logger .getLogger (IntegerBitSet .class .getName ());
14+
1215 static final int MAX_COLLECTION_SIZE = 8192 ;
1316
1417 protected final BitSet bitSet ;
@@ -98,20 +101,30 @@ public Spliterator.OfInt spliterator(){
98101 public IntStream intStream () {
99102 return StreamSupport .intStream (spliterator (), false );
100103 }
104+
105+ private static final void logOutOfRange (int value ) {
106+ LOGGER .warning ("Exceeding IntegerBitSet.MAX_COLLECTION_SIZE: " + value );
107+ }
101108
102109 public void addRange (int start , int end ) {
103110 int realStart = from + start ;
104111 int realEnd = from + end ;
105- if (realStart >= to || realEnd > to ) {
106- throw new IndexOutOfBoundsException ();
112+ if (realStart >= to ) {
113+ logOutOfRange (start );
114+ return ;
115+ }
116+ if (realEnd > to ) {
117+ logOutOfRange (end );
118+ realEnd = to ;
107119 }
108120 bitSet .set (realStart , realEnd );
109121 }
110122
111123 public boolean addInt (int value ) {
112124 int offset = from + value ;
113125 if (offset >= to ) {
114- throw new IndexOutOfBoundsException ();
126+ logOutOfRange (value );
127+ return false ;
115128 }
116129 boolean present = bitSet .get (offset );
117130 if (present ) {
@@ -124,7 +137,8 @@ public boolean addInt(int value) {
124137 public boolean removeInt (int value ) {
125138 int offset = from + value ;
126139 if (offset >= to ) {
127- throw new IndexOutOfBoundsException ();
140+ logOutOfRange (value );
141+ return false ;
128142 }
129143 boolean present = bitSet .get (offset );
130144 if (!present ) {
0 commit comments