org.apache.thrift
Class IntRangeSet

java.lang.Object
  extended by org.apache.thrift.IntRangeSet
All Implemented Interfaces:
java.lang.Iterable<java.lang.Integer>, java.util.Collection<java.lang.Integer>, java.util.Set<java.lang.Integer>

public class IntRangeSet
extends java.lang.Object
implements java.util.Set<java.lang.Integer>

IntRangeSet is a specialized Set implementation designed specifically to make the generated validate() method calls faster. It groups the set values into ranges, and in the contains() call, it does num ranges * 2 comparisons max. For the common case, which is a single, contiguous range, this approach is about 60% faster than using a HashSet. If you had a very ragged value set, like all the odd numbers, for instance, then you would end up with pretty poor running time.


Constructor Summary
IntRangeSet(int... values)
           
 
Method Summary
 boolean add(java.lang.Integer i)
           
 boolean addAll(java.util.Collection<? extends java.lang.Integer> arg0)
           
 void clear()
           
 boolean contains(int val)
          This is much faster, since it doesn't stop at Integer on the way through.
 boolean contains(java.lang.Object arg0)
          While this method is here for Set interface compatibility, you should avoid using it.
 boolean containsAll(java.util.Collection<?> arg0)
           
 boolean isEmpty()
           
 java.util.Iterator<java.lang.Integer> iterator()
           
 boolean remove(java.lang.Object arg0)
           
 boolean removeAll(java.util.Collection<?> arg0)
           
 boolean retainAll(java.util.Collection<?> arg0)
           
 int size()
           
 java.lang.Object[] toArray()
           
<T> T[]
toArray(T[] arg0)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
equals, hashCode
 

Constructor Detail

IntRangeSet

public IntRangeSet(int... values)
Method Detail

add

public boolean add(java.lang.Integer i)
Specified by:
add in interface java.util.Collection<java.lang.Integer>
Specified by:
add in interface java.util.Set<java.lang.Integer>

clear

public void clear()
Specified by:
clear in interface java.util.Collection<java.lang.Integer>
Specified by:
clear in interface java.util.Set<java.lang.Integer>

addAll

public boolean addAll(java.util.Collection<? extends java.lang.Integer> arg0)
Specified by:
addAll in interface java.util.Collection<java.lang.Integer>
Specified by:
addAll in interface java.util.Set<java.lang.Integer>

contains

public boolean contains(java.lang.Object arg0)
While this method is here for Set interface compatibility, you should avoid using it. It incurs boxing overhead! Use the int method directly, instead.

Specified by:
contains in interface java.util.Collection<java.lang.Integer>
Specified by:
contains in interface java.util.Set<java.lang.Integer>

contains

public boolean contains(int val)
This is much faster, since it doesn't stop at Integer on the way through.

Parameters:
val - the value you want to check set membership for
Returns:
true if val was found, false otherwise

containsAll

public boolean containsAll(java.util.Collection<?> arg0)
Specified by:
containsAll in interface java.util.Collection<java.lang.Integer>
Specified by:
containsAll in interface java.util.Set<java.lang.Integer>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection<java.lang.Integer>
Specified by:
isEmpty in interface java.util.Set<java.lang.Integer>

iterator

public java.util.Iterator<java.lang.Integer> iterator()
Specified by:
iterator in interface java.lang.Iterable<java.lang.Integer>
Specified by:
iterator in interface java.util.Collection<java.lang.Integer>
Specified by:
iterator in interface java.util.Set<java.lang.Integer>

remove

public boolean remove(java.lang.Object arg0)
Specified by:
remove in interface java.util.Collection<java.lang.Integer>
Specified by:
remove in interface java.util.Set<java.lang.Integer>

removeAll

public boolean removeAll(java.util.Collection<?> arg0)
Specified by:
removeAll in interface java.util.Collection<java.lang.Integer>
Specified by:
removeAll in interface java.util.Set<java.lang.Integer>

retainAll

public boolean retainAll(java.util.Collection<?> arg0)
Specified by:
retainAll in interface java.util.Collection<java.lang.Integer>
Specified by:
retainAll in interface java.util.Set<java.lang.Integer>

size

public int size()
Specified by:
size in interface java.util.Collection<java.lang.Integer>
Specified by:
size in interface java.util.Set<java.lang.Integer>

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection<java.lang.Integer>
Specified by:
toArray in interface java.util.Set<java.lang.Integer>

toArray

public <T> T[] toArray(T[] arg0)
Specified by:
toArray in interface java.util.Collection<java.lang.Integer>
Specified by:
toArray in interface java.util.Set<java.lang.Integer>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object