copyWith method
Returns a copy of this object with its field values replaced by the ones provided to this method.
Since ipAddress
, applicationKey
, and clientKey
are nullable, they
are defaulted to empty strings in this method. If left as empty strings,
their current values in this Bridge object will be used. This way, if
they are null
, the program will know that they are intentionally being
set to null
.
copyOriginalValues
is true if you want to maintain the original object's
initial values. This is useful if you plan on using this object in a PUT
request.
Throws InvalidIdException if owner.id
is empty and optimizeFor
is
not set to OptimizeFor.dontOptimize.
Implementation
Bridge copyWith({
ResourceType? type,
String? id,
String? idV1,
String? applicationKey = "",
String? clientKey = "",
String? ipAddress = "",
Relative? owner,
String? bridgeId,
String? timeZone,
bool copyOriginalValues = true,
}) {
Bridge toReturn = Bridge(
type: copyOriginalValues ? originalType : (type ?? this.type),
id: id ?? this.id,
idV1: idV1 ?? this.idV1,
applicationKey: applicationKey == null || applicationKey.isNotEmpty
? applicationKey
: this.applicationKey,
clientKey: clientKey == null || clientKey.isNotEmpty
? clientKey
: this.clientKey,
ipAddress: ipAddress == null || ipAddress.isNotEmpty
? ipAddress
: this.ipAddress,
owner:
owner ?? this.owner.copyWith(copyOriginalValues: copyOriginalValues),
bridgeId: bridgeId ?? this.bridgeId,
timeZone: timeZone ?? this.timeZone,
);
if (copyOriginalValues) {
toReturn.type = type ?? this.type;
}
return toReturn;
}