com.todoroo.andlib.data
Class AbstractModel

java.lang.Object
  extended by com.todoroo.andlib.data.AbstractModel
All Implemented Interfaces:
android.os.Parcelable, java.lang.Cloneable
Direct Known Subclasses:
Metadata, RemoteModel, StoreObject

public abstract class AbstractModel
extends java.lang.Object
implements android.os.Parcelable, java.lang.Cloneable

AbstractModel represents a row in a database.

A single database can be represented by multiple AbstractModels corresponding to different queries that return a different set of columns. Each model exposes a set of properties that it contains.

Author:
Tim Su

Nested Class Summary
static class AbstractModel.ContentValuesSavingVisitor
          Visitor that saves a value into a content values store
 
Nested classes/interfaces inherited from interface android.os.Parcelable
android.os.Parcelable.Creator<T>
 
Field Summary
static Property.IntegerProperty ID_PROPERTY
          id field common to all models
static long NO_ID
          sentinel for objects without an id
 
Fields inherited from interface android.os.Parcelable
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE
 
Constructor Summary
AbstractModel()
           
 
Method Summary
 void clear()
          Clear all data on this model
 void clearValue(Property<?> property)
          Clear the key for the given property
 AbstractModel clone()
           
 boolean containsNonNullValue(Property<?> property)
           
 boolean containsValue(Property<?> property)
           
 int describeContents()
          
 boolean equals(java.lang.Object other)
          Use merged values to compare two models to each other.
 android.content.ContentValues getDatabaseValues()
          Get database-read values for this object
abstract  android.content.ContentValues getDefaultValues()
          Get the default values for this object
 boolean getFlag(Property.IntegerProperty property, int flag)
          Returns the set state of the given flag on the given property
abstract  long getId()
          Utility method to get the identifier of the model, if it exists.
 android.content.ContentValues getMergedValues()
          Get a list of all field/value pairs merged across data sources
 android.content.ContentValues getSetValues()
          Get the user-set values for this object
 java.lang.Object getTransitory(java.lang.String key)
           
<TYPE> TYPE
getValue(Property<TYPE> property)
          Reads the given property.
 int hashCode()
           
 boolean isModified()
          Check if this model has values that have been changed
 boolean isSaved()
           
 void markSaved()
          Transfers all set values into values.
<TYPE> void
mergeWith(android.content.ContentValues other)
          Merges content values with those coming from another source
 void putTransitory(java.lang.String key, java.lang.Object value)
           
 void setFlag(Property.IntegerProperty property, int flag, boolean value)
          Sets the state of the given flag on the given property
 void setId(long id)
           
<TYPE> void
setValue(Property<TYPE> property, TYPE value)
          Sets the given property.
 void writeToParcel(android.os.Parcel dest, int flags)
          
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID_PROPERTY

public static final Property.IntegerProperty ID_PROPERTY
id field common to all models


NO_ID

public static final long NO_ID
sentinel for objects without an id

See Also:
Constant Field Values
Constructor Detail

AbstractModel

public AbstractModel()
Method Detail

getDefaultValues

public abstract android.content.ContentValues getDefaultValues()
Get the default values for this object


getDatabaseValues

public android.content.ContentValues getDatabaseValues()
Get database-read values for this object


getSetValues

public android.content.ContentValues getSetValues()
Get the user-set values for this object


getMergedValues

public android.content.ContentValues getMergedValues()
Get a list of all field/value pairs merged across data sources


clear

public void clear()
Clear all data on this model


markSaved

public void markSaved()
Transfers all set values into values. This occurs when a task is saved - future saves will not need to write all the data as before.


equals

public boolean equals(java.lang.Object other)
Use merged values to compare two models to each other. Must be of exactly the same class.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

clone

public AbstractModel clone()
Overrides:
clone in class java.lang.Object

isModified

public boolean isModified()
Check if this model has values that have been changed


getValue

public <TYPE> TYPE getValue(Property<TYPE> property)
Reads the given property. Make sure this model has this property!


getId

public abstract long getId()
Utility method to get the identifier of the model, if it exists.

Returns:
0L if this model was not added to the database

setId

public void setId(long id)

isSaved

public boolean isSaved()
Returns:
true if this model has found Jesus (i.e. the database)

containsValue

public boolean containsValue(Property<?> property)
Parameters:
property -
Returns:
true if setValues or values contains this property

containsNonNullValue

public boolean containsNonNullValue(Property<?> property)
Parameters:
property -
Returns:
true if setValues or values contains this property, and the value stored is not null

setValue

public <TYPE> void setValue(Property<TYPE> property,
                            TYPE value)
Sets the given property. Make sure this model has this property!


mergeWith

public <TYPE> void mergeWith(android.content.ContentValues other)
Merges content values with those coming from another source


clearValue

public void clearValue(Property<?> property)
Clear the key for the given property

Parameters:
property -

setFlag

public void setFlag(Property.IntegerProperty property,
                    int flag,
                    boolean value)
Sets the state of the given flag on the given property

Parameters:
property -
flag -
value -

getFlag

public boolean getFlag(Property.IntegerProperty property,
                       int flag)
Returns the set state of the given flag on the given property

Parameters:
property - the property to get the set state of the flag
flag - the flag-descriptor (e.g. Task.FLAG_REPEAT_AFTER_COMPLETION)
Returns:
true if the flag is set

putTransitory

public void putTransitory(java.lang.String key,
                          java.lang.Object value)

getTransitory

public java.lang.Object getTransitory(java.lang.String key)

describeContents

public int describeContents()

Specified by:
describeContents in interface android.os.Parcelable

writeToParcel

public void writeToParcel(android.os.Parcel dest,
                          int flags)

Specified by:
writeToParcel in interface android.os.Parcelable