-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
When writing code that depend on e.g max value being set you often end up having to do something like:
Number maxValue = realm.where(Person.class).max("id"); long id = (maxValue != null) ? maxValue.longValue() : -1; new Person(++id)
We added default values to first()/last() when the collection was empty and doing the same for max/min/average would help removing annoying code like the above:
Like this:
Number maxValue = realm.where(Person.class).max("id", -1) new Person(++maxValue);
Proposed API changes
// Add 4 new methods to RealmQuery Number max(String fieldName, Number defaultValue); Number min(String fieldName, Number defaultValue); Date minimumDate(String fieldName, Date defaultValue); Date maximumDate(String fieldName, Date defaultValue); // Add 4 new methods to RealmCollection Number max(String fieldName, Number defaultValue); Number min(String fieldName, Number defaultValue); Date minDate(String fieldName, Date defaultValue); Date maxDate(String fieldName, Date defaultValue);