operator + method
Adds two DataRefModel objects. Collection paths must have an odd number of segments.
Implementation
DataRefModel operator +(DataRefModel other) {
final temp = [...pathSegments, ...other.pathSegments];
final length = temp.length;
// Check that collection segments always have an odd length
if (length.isEven) {
final collection = temp.sublist(0, length - 1);
if (collection.length.isEven) {
throw StateError(
'[DataRefModelExtension] Invalid collection path: Collection must have an odd number of segments.',
);
}
final id = temp.last;
return DataRefModel(
id: id,
collection: collection,
);
} else {
final collection = temp;
if (collection.length.isEven) {
throw StateError(
'[DataRefModelExtension] Invalid collection path: Collection must have an odd number of segments.',
);
}
return DataRefModel(
id: null,
collection: collection,
);
}
}