package com.battery.device.api.model; import java.util.Objects; /** 设备身份;通道身份在此基础上增加通道号。 */ public record DeviceIdentity(String adapterCode, int devtype, int devid, int subdevid) { public DeviceIdentity { adapterCode = Objects.requireNonNull(adapterCode, "adapterCode").trim(); if (adapterCode.isEmpty()) throw new IllegalArgumentException("adapterCode must not be blank"); if (devtype < 0 || devid < 0 || subdevid < 0) throw new IllegalArgumentException("device identity values must be non-negative"); } public static DeviceIdentity from(ChannelIdentity channel) { Objects.requireNonNull(channel, "channel"); return new DeviceIdentity(channel.adapterCode(), channel.devtype(), channel.devid(), channel.subdevid()); } }