withTerminal method
Dressed ID: name@address/terminal
Implementation
@override
ID withTerminal(String newTerminal) {
// check old terminal (device)
String oldTerminal = terminal ?? '';
if (newTerminal.isEmpty) {
// should not happen
return oldTerminal.isEmpty ? this : ID.create(name: name, address: address);
}
// new terminal not empty (normally),
// try to add/replace terminal
if (newTerminal == oldTerminal) {
// old terminal equals to the new terminal,
// nothing changed
return this;
}
// create new ID with terminal
return ID.create(name: name, address: address, terminal: newTerminal);
}