set method

Future<String?> set(
  1. Field field,
  2. String? value
)

Sets an ordinal field of the node.

@param field the ordinal field to be set @param value the new value @return the previously set value @throws StorageException if a field does not exist

Implementation

Future<String?> set(Field field, String? value) async {
  if (!_skeletonOrdinals.contains(field)) {
    await _init();
  }

  var current = _ordinals[field];

  if (field != Field.lastModified &&
      ((current != null && current != value) ||
          (current == null && value != null))) {
    touch();
  }
  switch (field) {
    case Field.owner:
    case Field.path:
    case Field.visibility:
    case Field.lastModified:
    case Field.expiry:
      if (value == null) {
        return _ordinals.remove(field);
      }
      _ordinals[field] = value;
      return current;
    case Field.tombstone:
      _ordinals[field] = ('true' == value) ? 'true' : 'false';
      return current ?? 'false';
    default:
      throw StorageException('unable to set field ' + field.toString());
  }
}