public class IntSet extends Object implements Cloneable, Serializable, FastSerializable, Iterable<Integer>
Constructor and Description |
---|
IntSet()
Construct a new empty set.
|
IntSet(DataInput inStream)
FastSerializable constructor.
|
IntSet(int capacity)
Construct a new empty set, with the given initial allocation size
|
IntSet(int[] fromData)
Construct a set from an integer array.
|
IntSet(int[] fromData,
boolean sorted)
Construct a set from an integer array.
|
IntSet(IntSet fromSet)
Construct a copy of an IntSet.
|
IntSet(String str)
Construct a set from a toString() representation
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(int val)
Add a value to the set.
|
IntSet |
addAll(int[] vals)
Add an array of values to the set.
|
IntSet |
addAll(IntSet other)
Add the values from another
IntSet to this set. |
StringBuffer |
appendToStringBuffer(StringBuffer sb)
Appends a textual representation of this IntSet to the given StringBuffer.
|
void |
clear()
Sets this IntSet to represent the empty set.
|
IntSet |
clone()
Performs a deep copy of the set.
|
static IntSet |
complement(IntSet superset,
IntSet subset)
Return a new set that is the complement of a subset within a superset.
|
boolean |
contains(int val)
Check if a value is contained in the set.
|
boolean |
containsAll(int[] vals)
Check if the given values are contained in the set.
|
boolean |
containsAll(IntSet other)
Check if the given values are contained in this set.
|
static IntSet |
copyOf(int[] from)
Construct a new set that contains the given values.
|
static IntSet |
copyOf(Set<Integer> fromSet)
Construct a new set that contains a copy of the values in the given set.
|
static IntSet |
emptySet()
Construct a new empty set.
|
boolean |
equals(Object other)
Set equality.
|
void |
fromArray(int[] fromData)
Sets the integers in this IntSet to be those in the given array.
|
void |
fromArray(int[] fromData,
boolean sorted)
Sets the integers in this IntSet to be those in the given array.
|
int |
get(int index)
Get the value at a specified index.
|
int |
hashCode()
Computes a hash code value for this object.
|
static IntSet |
intersection(IntSet setA,
IntSet setB)
Return a new set that is the intersection of two other sets.
|
boolean |
isEmpty()
Determines whether this IntSet represents an empty set.
|
boolean |
isSubsetOf(IntSet superset)
Determines whether this IntSet is a subset of the given IntSet.
|
boolean |
isSupersetOf(IntSet subset)
Determines whether this IntSet is a superset of the given IntSet.
|
Iterator<Integer> |
iterator() |
int |
lowestMember()
Gets the smallest valued int from this IntSet.
|
static IntSet |
of(int... values)
Construct a set with the given values.
|
boolean |
remove(int val)
Remove a value from the set.
|
IntSet |
removeAll(int[] vals)
Remove an array of values to the set.
|
IntSet |
removeAll(IntSet other)
Remove all values in the provided
IntSet from this set. |
int |
size()
Gets the size of this IntSet.
|
int[] |
toArray()
Return an array containing only the set data (sorted).
|
void |
toStream(DataOutput outStream)
Serialize the state of this object to a stream.
|
String |
toString()
Returns a textual representation of this IntSet.
|
static IntSet |
union(IntSet setA,
IntSet setB)
Return a new set that is the union of two other sets.
|
public IntSet()
public IntSet(int capacity)
capacity
- the initial storage capacity to use; may be adjusted if too small.public IntSet(IntSet fromSet)
fromSet
- the set to copypublic IntSet(int[] fromData, boolean sorted)
fromData
- the initial contents of the set; not modifiedsorted
- if true, fromArray is assumed to be already sortedpublic IntSet(int[] fromData)
fromData
- an array holding the initial set contents; assumed to be unsorted.public IntSet(DataInput inStream) throws IOException
IOException
public IntSet(String str) throws IllegalArgumentException
IllegalArgumentException
public static IntSet of(int... values)
values
- values to include in the new setpublic static IntSet emptySet()
public static IntSet copyOf(int[] from)
from
- an array of unsorted valuespublic static IntSet copyOf(Set<Integer> fromSet)
fromSet
- a set of Integerspublic void toStream(DataOutput outStream) throws IOException
FastSerializable
toStream
in interface FastSerializable
outStream
- the stream to serialize to.IOException
- if an error occurs during serializationpublic int hashCode()
public boolean isEmpty()
public boolean add(int val)
val
- the value to addpublic IntSet addAll(int[] vals)
vals
- the values to add.IntSet
public IntSet addAll(IntSet other)
IntSet
to this set.other
- the set of values to add.IntSet
.public boolean remove(int val)
val
- the value to removepublic IntSet removeAll(int[] vals)
vals
- the values to remove.IntSet
public IntSet removeAll(IntSet other)
IntSet
from this set.other
- the set of values to remove from this set.IntSet
.public boolean contains(int val)
val
- the value to check forpublic boolean containsAll(int[] vals)
vals
- the values to check forpublic boolean containsAll(IntSet other)
other
- the set of values to check for.public void fromArray(int[] fromData)
fromData
- array of intspublic void fromArray(int[] fromData, boolean sorted)
fromData
- array of intssorted
- whether the ints in array fromData are in sorted sequencepublic void clear()
public int[] toArray()
public String toString()
public StringBuffer appendToStringBuffer(StringBuffer sb)
sb
- StringBufferpublic static IntSet intersection(IntSet setA, IntSet setB)
setA
- the first set to intersect; null means an empty setsetB
- the second set to intersect; null means an empty setpublic static IntSet union(IntSet setA, IntSet setB)
setA
- the first set to union; null means an empty setsetB
- the second set to union; null means an empty setpublic static IntSet complement(IntSet superset, IntSet subset)
superset
- the superset to perform the complement within; null means the empty setsubset
- the subset to complement; null means the empty setpublic boolean isSupersetOf(IntSet subset)
subset
- the conjectured subset of this IntSetpublic boolean isSubsetOf(IntSet superset)
superset
- the conjectured superset of this IntSetpublic int size()
public int lowestMember()
NoSuchElementException
- if this IntSet is emptypublic int get(int index) throws ArrayIndexOutOfBoundsException
size()
- 1
returns the highest value, and
any index in between returns the corresponding value.index
- the index.ArrayIndexOutOfBoundsException
- if index
is less than zero or
greater than or equal to the size of the set.