/** * Return the value of the specified {@link Property}. The model prioritizes values as follows: * <ol> * <li>values explicitly set using {@link #set(Property, Object)} or a generated setter</li> * <li>values written to the model as a result of fetching it using a {@link SquidDatabase} or constructing it from * a {@link SquidCursor}</li> * <li>the set of default values as specified by {@link #getDefaultValues()}</li> * </ol> * If a value is not found in any of those places, the result depends on the value of the throwOnFail parameter. * If true, an exception will be throw, if false, null is returned. * * @return the value of the specified property * @throws UnsupportedOperationException if the value is not found in the model */ public <TYPE> TYPE get(Property<TYPE> property, boolean throwOnFail) { if (setValues != null && setValues.containsKey(property.getName())) { return getFromValues(property, setValues); } else if (values != null && values.containsKey(property.getName())) { return getFromValues(property, values); } else if (getDefaultValues().containsKey(property.getName())) { return getFromValues(property, getDefaultValues()); } else if (throwOnFail) { throw new UnsupportedOperationException(property.getName() + " not found in model. Make sure the value was set explicitly, read from a cursor," + " or that the model has a default value for this property."); } return null; }
/** * Copies values from the given {@link ValuesStorage} into the model. The values will be added to the model as read * values (i.e. will not be considered set values or mark the model as dirty). */ public void readPropertiesFromValuesStorage(ValuesStorage values, Property<?>... properties) { prepareToReadProperties(); if (values != null) { for (Property<?> property : properties) { if (values.containsKey(property.getName())) { this.values.put(property.getName(), getFromValues(property, values), true); } } } }
/** * Return the value of the specified {@link Property}. The model prioritizes values as follows: * <ol> * <li>values explicitly set using {@link #set(Property, Object)} or a generated setter</li> * <li>values written to the model as a result of fetching it using a {@link SquidDatabase} or constructing it from * a {@link SquidCursor}</li> * <li>the set of default values as specified by {@link #getDefaultValues()}</li> * </ol> * If a value is not found in any of those places, the result depends on the value of the throwOnFail parameter. * If true, an exception will be throw, if false, null is returned. * * @return the value of the specified property * @throws UnsupportedOperationException if the value is not found in the model */ public <TYPE> TYPE get(Property<TYPE> property, boolean throwOnFail) { if (setValues != null && setValues.containsKey(property.getName())) { return getFromValues(property, setValues); } else if (values != null && values.containsKey(property.getName())) { return getFromValues(property, values); } else if (getDefaultValues().containsKey(property.getName())) { return getFromValues(property, getDefaultValues()); } else if (throwOnFail) { throw new UnsupportedOperationException(property.getName() + " not found in model. Make sure the value was set explicitly, read from a cursor," + " or that the model has a default value for this property."); } return null; }
/** * Copies values from the given {@link ValuesStorage} into the model. The values will be added to the model as read * values (i.e. will not be considered set values or mark the model as dirty). */ public void readPropertiesFromValuesStorage(ValuesStorage values, Property<?>... properties) { prepareToReadProperties(); if (values != null) { for (Property<?> property : properties) { if (values.containsKey(property.getName())) { this.values.put(property.getName(), getFromValues(property, values), true); } } } }