com.threerings.util
Class StreamableEnumSet<E extends Enum<E>>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<E>
          extended by com.threerings.util.StreamableEnumSet<E>
Type Parameters:
E - the type of enum being stored in this set.
All Implemented Interfaces:
Streamable, Cloneable, Iterable<E>, Collection<E>, Set<E>

public class StreamableEnumSet<E extends Enum<E>>
extends AbstractSet<E>
implements Cloneable, Streamable

An EnumSet equivalent (not a subclass, because EnumSet's implementation is private) that can be streamed.

See Also:
Streamable

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.threerings.io.Streamable
Streamable.Closure
 
Field Summary
protected  byte[] _contents
          A byte array with bits set for each element in the set.
protected  Class<E> _elementType
          The element type.
protected  int _modcount
          The modification count (used to detect concurrent modifications).
protected  int _size
          The number of elements in the set.
 
Constructor Summary
StreamableEnumSet(Class<E> elementType)
          Creates a new, empty enum set for storing elements of the specified class.
 
Method Summary
 boolean add(E o)
           
static
<E extends Enum<E>>
StreamableEnumSet<E>
allOf(Class<E> elementType)
          Creates a set containing all elements of the specified type.
protected  boolean classDefinesElementType()
          Subclasses that only store elements of a single enum type (initialized in their no-arg constructors) can return true here to avoid the overhead of streaming the enum type for each instance.
 void clear()
           
 StreamableEnumSet<E> clone()
           
static
<E extends Enum<E>>
StreamableEnumSet<E>
complementOf(StreamableEnumSet<E> s)
          Creates a set containing all elements not in the set provided.
 boolean contains(Object o)
           
static
<E extends Enum<E>>
StreamableEnumSet<E>
copyOf(Collection<E> s)
          Creates a set containing all elements in the collection provided (which must have at least one element, unless it is a StreamableEnumSet).
static
<E extends Enum<E>>
StreamableEnumSet<E>
copyOf(StreamableEnumSet<E> s)
          Creates a set containing all elements in the set provided.
protected  void initContents()
          Creates the contents array.
 Iterator<E> iterator()
           
static
<E extends Enum<E>>
StreamableEnumSet<E>
noneOf(Class<E> elementType)
          Creates an empty set of the specified type.
static
<E extends Enum<E>>
StreamableEnumSet<E>
of(E first, E... rest)
          Creates a set consisting of the specified elements.
static
<E extends Enum<E>>
StreamableEnumSet<E>
range(E from, E to)
          Creates a set that includes all enum constants in the specified (inclusive) range.
 void readObject(ObjectInputStream in)
          Reads our custom streamable fields.
 boolean remove(Object o)
           
 int size()
           
 void writeObject(ObjectOutputStream out)
          Writes our custom streamable fields.
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, containsAll, isEmpty, retainAll, toArray, toArray
 

Field Detail

_elementType

protected Class<E extends Enum<E>> _elementType
The element type.


_contents

protected byte[] _contents
A byte array with bits set for each element in the set.


_size

protected int _size
The number of elements in the set.


_modcount

protected int _modcount
The modification count (used to detect concurrent modifications).

Constructor Detail

StreamableEnumSet

public StreamableEnumSet(Class<E> elementType)
Creates a new, empty enum set for storing elements of the specified class.

Method Detail

noneOf

public static <E extends Enum<E>> StreamableEnumSet<E> noneOf(Class<E> elementType)
Creates an empty set of the specified type.


allOf

public static <E extends Enum<E>> StreamableEnumSet<E> allOf(Class<E> elementType)
Creates a set containing all elements of the specified type.


copyOf

public static <E extends Enum<E>> StreamableEnumSet<E> copyOf(Collection<E> s)
Creates a set containing all elements in the collection provided (which must have at least one element, unless it is a StreamableEnumSet).


copyOf

public static <E extends Enum<E>> StreamableEnumSet<E> copyOf(StreamableEnumSet<E> s)
Creates a set containing all elements in the set provided.


complementOf

public static <E extends Enum<E>> StreamableEnumSet<E> complementOf(StreamableEnumSet<E> s)
Creates a set containing all elements not in the set provided.


of

public static <E extends Enum<E>> StreamableEnumSet<E> of(E first,
                                                          E... rest)
Creates a set consisting of the specified elements.


range

public static <E extends Enum<E>> StreamableEnumSet<E> range(E from,
                                                             E to)
Creates a set that includes all enum constants in the specified (inclusive) range.


iterator

public Iterator<E> iterator()
Specified by:
iterator in interface Iterable<E extends Enum<E>>
Specified by:
iterator in interface Collection<E extends Enum<E>>
Specified by:
iterator in interface Set<E extends Enum<E>>
Specified by:
iterator in class AbstractCollection<E extends Enum<E>>

size

public int size()
Specified by:
size in interface Collection<E extends Enum<E>>
Specified by:
size in interface Set<E extends Enum<E>>
Specified by:
size in class AbstractCollection<E extends Enum<E>>

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<E extends Enum<E>>
Specified by:
contains in interface Set<E extends Enum<E>>
Overrides:
contains in class AbstractCollection<E extends Enum<E>>

add

public boolean add(E o)
Specified by:
add in interface Collection<E extends Enum<E>>
Specified by:
add in interface Set<E extends Enum<E>>
Overrides:
add in class AbstractCollection<E extends Enum<E>>

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<E extends Enum<E>>
Specified by:
remove in interface Set<E extends Enum<E>>
Overrides:
remove in class AbstractCollection<E extends Enum<E>>

clear

public void clear()
Specified by:
clear in interface Collection<E extends Enum<E>>
Specified by:
clear in interface Set<E extends Enum<E>>
Overrides:
clear in class AbstractCollection<E extends Enum<E>>

clone

public StreamableEnumSet<E> clone()
Overrides:
clone in class Object

writeObject

public void writeObject(ObjectOutputStream out)
                 throws IOException
Writes our custom streamable fields.

Throws:
IOException

readObject

public void readObject(ObjectInputStream in)
                throws IOException,
                       ClassNotFoundException
Reads our custom streamable fields.

Throws:
IOException
ClassNotFoundException

classDefinesElementType

protected boolean classDefinesElementType()
Subclasses that only store elements of a single enum type (initialized in their no-arg constructors) can return true here to avoid the overhead of streaming the enum type for each instance.


initContents

protected void initContents()
Creates the contents array.