tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.device; |
| 2 | |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 3 | import org.onlab.onos.net.AbstractDescription; |
| 4 | import org.onlab.onos.net.SparseAnnotations; |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 5 | |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 6 | import java.net.URI; |
| 7 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 8 | import static com.google.common.base.MoreObjects.toStringHelper; |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 9 | import static com.google.common.base.Preconditions.checkNotNull; |
| 10 | import static org.onlab.onos.net.Device.Type; |
| 11 | |
| 12 | /** |
| 13 | * Default implementation of immutable device description entity. |
| 14 | */ |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 15 | public class DefaultDeviceDescription extends AbstractDescription |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 16 | implements DeviceDescription { |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 17 | private final URI uri; |
| 18 | private final Type type; |
| 19 | private final String manufacturer; |
| 20 | private final String hwVersion; |
| 21 | private final String swVersion; |
| 22 | private final String serialNumber; |
| 23 | |
| 24 | /** |
| 25 | * Creates a device description using the supplied information. |
| 26 | * |
| 27 | * @param uri device URI |
| 28 | * @param type device type |
| 29 | * @param manufacturer device manufacturer |
| 30 | * @param hwVersion device HW version |
| 31 | * @param swVersion device SW version |
| 32 | * @param serialNumber device serial number |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 33 | * @param annotations optional key/value annotations map |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 34 | */ |
| 35 | public DefaultDeviceDescription(URI uri, Type type, String manufacturer, |
| 36 | String hwVersion, String swVersion, |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 37 | String serialNumber, |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 38 | SparseAnnotations... annotations) { |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 39 | super(annotations); |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 40 | this.uri = checkNotNull(uri, "Device URI cannot be null"); |
| 41 | this.type = checkNotNull(type, "Device type cannot be null"); |
| 42 | this.manufacturer = manufacturer; |
| 43 | this.hwVersion = hwVersion; |
| 44 | this.swVersion = swVersion; |
| 45 | this.serialNumber = serialNumber; |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public URI deviceURI() { |
| 50 | return uri; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public Type type() { |
| 55 | return type; |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public String manufacturer() { |
| 60 | return manufacturer; |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public String hwVersion() { |
| 65 | return hwVersion; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public String swVersion() { |
| 70 | return swVersion; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public String serialNumber() { |
| 75 | return serialNumber; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public String toString() { |
| 80 | return toStringHelper(this) |
| 81 | .add("uri", uri).add("type", type).add("mfr", manufacturer) |
| 82 | .add("hw", hwVersion).add("sw", swVersion) |
| 83 | .add("serial", serialNumber) |
| 84 | .toString(); |
| 85 | } |
| 86 | |
| 87 | } |