com.threerings.delta
Class ReflectiveDelta

java.lang.Object
  extended by com.threerings.delta.Delta
      extended by com.threerings.delta.ReflectiveDelta
All Implemented Interfaces:
Streamable
Direct Known Subclasses:
ActorDelta

public class ReflectiveDelta
extends Delta

A delta object that uses reflection to compare and modify the objects' fields. Note that unchanged object fields will be preserved by reference.


Nested Class Summary
protected static class ReflectiveDelta.ClassMapping
          Contains cached information about a class.
protected static class ReflectiveDelta.FieldHandler
          Handles a particular field.
protected static class ReflectiveDelta.FinalFieldHandler
          Base class for final field handlers.
 
Nested classes/interfaces inherited from interface com.threerings.io.Streamable
Streamable.Closure
 
Field Summary
protected static Map<Class<?>,ReflectiveDelta.ClassMapping> _classes
          Cached mappings for deltable classes.
protected  Class<?> _clazz
          The object class.
protected  BareArrayMask _mask
          The mask indicating which fields have changed.
protected  Object[] _values
          The values for each of the object's changed fields (either a new value or a Delta object).
protected static ReflectiveDelta.FieldHandler FINAL_OBJECT_FIELD_HANDLER
          Handler for final object fields.
protected static Map<Class<?>,ReflectiveDelta.FieldHandler> FINAL_PRIMITIVE_FIELD_HANDLERS
          Field handlers for final primitive fields mapped by class.
protected static ReflectiveDelta.FieldHandler OBJECT_FIELD_HANDLER
          Handler for object fields.
protected static Map<Class<?>,ReflectiveDelta.FieldHandler> PRIMITIVE_FIELD_HANDLERS
          Field handlers for primitive fields mapped by class.
 
Fields inherited from class com.threerings.delta.Delta
_classStreamer, _creators, _none, _wrapperStreamers
 
Constructor Summary
ReflectiveDelta()
          No-arg constructor for deserialization.
ReflectiveDelta(Object original, Object revised)
          Creates a new reflective delta that transforms the original object into the revised object (both of which must be instances of the same class).
 
Method Summary
 Object apply(Object original)
          Applies this delta to the specified object.
protected static void collectFields(Class<?> clazz, List<Field> fields)
          Collects all appropriate fields of the specified class (and its superclasses) and places them in the provided results object.
protected static ReflectiveDelta.ClassMapping getClassMapping(Class<?> clazz)
          Returns the class mapping for the specified class.
 boolean isEmpty()
          Checks whether the delta is empty.
 Delta merge(Delta other)
          Merges this delta with another.
protected  void populateMerged(ReflectiveDelta other, ReflectiveDelta merged)
          Populates the merged delta.
 void readObject(ObjectInputStream in)
          Custom read method.
 String toString()
           
 void writeObject(ObjectOutputStream out)
          Custom write method.
 
Methods inherited from class com.threerings.delta.Delta
checkDeltable, createDelta
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_clazz

protected Class<?> _clazz
The object class.


_mask

protected BareArrayMask _mask
The mask indicating which fields have changed.


_values

protected Object[] _values
The values for each of the object's changed fields (either a new value or a Delta object).


_classes

protected static Map<Class<?>,ReflectiveDelta.ClassMapping> _classes
Cached mappings for deltable classes.


PRIMITIVE_FIELD_HANDLERS

protected static final Map<Class<?>,ReflectiveDelta.FieldHandler> PRIMITIVE_FIELD_HANDLERS
Field handlers for primitive fields mapped by class.


FINAL_PRIMITIVE_FIELD_HANDLERS

protected static final Map<Class<?>,ReflectiveDelta.FieldHandler> FINAL_PRIMITIVE_FIELD_HANDLERS
Field handlers for final primitive fields mapped by class.


OBJECT_FIELD_HANDLER

protected static final ReflectiveDelta.FieldHandler OBJECT_FIELD_HANDLER
Handler for object fields.


FINAL_OBJECT_FIELD_HANDLER

protected static final ReflectiveDelta.FieldHandler FINAL_OBJECT_FIELD_HANDLER
Handler for final object fields.

Constructor Detail

ReflectiveDelta

public ReflectiveDelta(Object original,
                       Object revised)
Creates a new reflective delta that transforms the original object into the revised object (both of which must be instances of the same class).


ReflectiveDelta

public ReflectiveDelta()
No-arg constructor for deserialization.

Method Detail

isEmpty

public boolean isEmpty()
Checks whether the delta is empty.


writeObject

public void writeObject(ObjectOutputStream out)
                 throws IOException
Custom write method.

Throws:
IOException

readObject

public void readObject(ObjectInputStream in)
                throws IOException,
                       ClassNotFoundException
Custom read method.

Throws:
IOException
ClassNotFoundException

apply

public Object apply(Object original)
Description copied from class: Delta
Applies this delta to the specified object.

Specified by:
apply in class Delta
Returns:
a new object incorporating the changes represented by this delta.

merge

public Delta merge(Delta other)
Description copied from class: Delta
Merges this delta with another.

Specified by:
merge in class Delta
Returns:
a new delta containing the changes included in both.

toString

public String toString()
Overrides:
toString in class Object

populateMerged

protected void populateMerged(ReflectiveDelta other,
                              ReflectiveDelta merged)
Populates the merged delta.


getClassMapping

protected static ReflectiveDelta.ClassMapping getClassMapping(Class<?> clazz)
Returns the class mapping for the specified class.


collectFields

protected static void collectFields(Class<?> clazz,
                                    List<Field> fields)
Collects all appropriate fields of the specified class (and its superclasses) and places them in the provided results object.