-
- All Implemented Interfaces:
-
com.onesignal.common.events.IEventNotifier
public class Model implements IEventNotifier<IModelChangedHandler>
The base class for a Model. A model is effectively a map of data, each key in the map being a property of the model, each value in the map being the property value. A property can be one of the following values:
Simple Types
------------Boolean String Int/Long/Double/Float
When a Model is nested (a property is a Model type or List of Model types) the child Model is owned and initialized by the parent Model.
When a structured schema should be enforced this class should be extended, the base class utilizing Properties with getters/setters that wrap getProperty and setProperty calls to the underlying data.
When a more dynamic schema is needed, the MapModel class can be used, which bridges a MutableMap and Model.
Deserialization
---------------When deserializing a flat Model nothing specific is required. However if the Model is nested the createModelForProperty and/or createListForProperty needs to be implemented to aide in the deserialization process.
-
-
Field Summary
Fields Modifier and Type Field Description private Stringidprivate final BooleanhasSubscribers
-
Method Summary
Modifier and Type Method Description final StringgetId()final UnitsetId(String id)BooleangetHasSubscribers()final UnitinitializeFromJson(JSONObject jsonObject)Initialize this model from a JSONObject. final UnitinitializeFromModel(String id, Model model)Initialize this model from a Model. final <T extends Enum<T>> UnitsetEnumProperty(String name, T value, String tag, Boolean forceChange)final <T extends Any> UnitsetMapModelProperty(String name, MapModel<T> value, String tag, Boolean forceChange)final <T extends Any> UnitsetListProperty(String name, List<T> value, String tag, Boolean forceChange)final UnitsetStringProperty(String name, String value, String tag, Boolean forceChange)final UnitsetBooleanProperty(String name, Boolean value, String tag, Boolean forceChange)final UnitsetLongProperty(String name, Long value, String tag, Boolean forceChange)final UnitsetDoubleProperty(String name, Double value, String tag, Boolean forceChange)final UnitsetFloatProperty(String name, Float value, String tag, Boolean forceChange)final UnitsetIntProperty(String name, Integer value, String tag, Boolean forceChange)final UnitsetBigDecimalProperty(String name, BigDecimal value, String tag, Boolean forceChange)final UnitsetAnyProperty(String name, Object value, String tag, Boolean forceChange)final <T extends Enum<T>> UnitsetOptEnumProperty(String name, T value, String tag, Boolean forceChange)final <T extends Any> UnitsetOptMapModelProperty(String name, MapModel<T> value, String tag, Boolean forceChange)final <T extends Any> UnitsetOptListProperty(String name, List<T> value, String tag, Boolean forceChange)final UnitsetOptStringProperty(String name, String value, String tag, Boolean forceChange)final UnitsetOptBooleanProperty(String name, Boolean value, String tag, Boolean forceChange)final UnitsetOptLongProperty(String name, Long value, String tag, Boolean forceChange)final UnitsetOptDoubleProperty(String name, Double value, String tag, Boolean forceChange)final UnitsetOptFloatProperty(String name, Float value, String tag, Boolean forceChange)final UnitsetOptIntProperty(String name, Integer value, String tag, Boolean forceChange)final UnitsetOptBigDecimalProperty(String name, BigDecimal value, String tag, Boolean forceChange)final UnitsetOptAnyProperty(String name, Object value, String tag, Boolean forceChange)final BooleanhasProperty(String name)Determine whether the provided property is currently set in this model. final JSONObjecttoJSON()Serialize this model to a JSONObject, recursively if required. Unitsubscribe(IModelChangedHandler handler)Subscribe to listen for events. Unitunsubscribe(IModelChangedHandler handler)Unsubscribe to no longer listen for events. -
-
Method Detail
-
getHasSubscribers
Boolean getHasSubscribers()
-
initializeFromJson
final Unit initializeFromJson(JSONObject jsonObject)
Initialize this model from a JSONObject. Each key-value-pair in the JSONObject will be deserialized into this model, recursively if needed.
- Parameters:
jsonObject- The JSONObject to initialize this model from.
-
initializeFromModel
final Unit initializeFromModel(String id, Model model)
Initialize this model from a Model. The model provided will be replicated within this model.
- Parameters:
id- The id of the model to initialze to.model- The model to initialize this model from.
-
setEnumProperty
final <T extends Enum<T>> Unit setEnumProperty(String name, T value, String tag, Boolean forceChange)
-
setMapModelProperty
final <T extends Any> Unit setMapModelProperty(String name, MapModel<T> value, String tag, Boolean forceChange)
-
setListProperty
final <T extends Any> Unit setListProperty(String name, List<T> value, String tag, Boolean forceChange)
-
setStringProperty
final Unit setStringProperty(String name, String value, String tag, Boolean forceChange)
-
setBooleanProperty
final Unit setBooleanProperty(String name, Boolean value, String tag, Boolean forceChange)
-
setLongProperty
final Unit setLongProperty(String name, Long value, String tag, Boolean forceChange)
-
setDoubleProperty
final Unit setDoubleProperty(String name, Double value, String tag, Boolean forceChange)
-
setFloatProperty
final Unit setFloatProperty(String name, Float value, String tag, Boolean forceChange)
-
setIntProperty
final Unit setIntProperty(String name, Integer value, String tag, Boolean forceChange)
-
setBigDecimalProperty
final Unit setBigDecimalProperty(String name, BigDecimal value, String tag, Boolean forceChange)
-
setAnyProperty
final Unit setAnyProperty(String name, Object value, String tag, Boolean forceChange)
-
setOptEnumProperty
final <T extends Enum<T>> Unit setOptEnumProperty(String name, T value, String tag, Boolean forceChange)
-
setOptMapModelProperty
final <T extends Any> Unit setOptMapModelProperty(String name, MapModel<T> value, String tag, Boolean forceChange)
-
setOptListProperty
final <T extends Any> Unit setOptListProperty(String name, List<T> value, String tag, Boolean forceChange)
-
setOptStringProperty
final Unit setOptStringProperty(String name, String value, String tag, Boolean forceChange)
-
setOptBooleanProperty
final Unit setOptBooleanProperty(String name, Boolean value, String tag, Boolean forceChange)
-
setOptLongProperty
final Unit setOptLongProperty(String name, Long value, String tag, Boolean forceChange)
-
setOptDoubleProperty
final Unit setOptDoubleProperty(String name, Double value, String tag, Boolean forceChange)
-
setOptFloatProperty
final Unit setOptFloatProperty(String name, Float value, String tag, Boolean forceChange)
-
setOptIntProperty
final Unit setOptIntProperty(String name, Integer value, String tag, Boolean forceChange)
-
setOptBigDecimalProperty
final Unit setOptBigDecimalProperty(String name, BigDecimal value, String tag, Boolean forceChange)
-
setOptAnyProperty
final Unit setOptAnyProperty(String name, Object value, String tag, Boolean forceChange)
-
hasProperty
final Boolean hasProperty(String name)
Determine whether the provided property is currently set in this model.
- Parameters:
name- The name of the property to test for.
-
toJSON
final JSONObject toJSON()
Serialize this model to a JSONObject, recursively if required.
-
subscribe
Unit subscribe(IModelChangedHandler handler)
Subscribe to listen for events.
- Parameters:
handler- The handler that will be called when the event(s) occur.
-
unsubscribe
Unit unsubscribe(IModelChangedHandler handler)
Unsubscribe to no longer listen for events.
- Parameters:
handler- The handler that was previous registered via subscribe.
-
-
-
-