blob: 84522debd49949648e5cb53f189513800153e383 [file] [log] [blame]
Simon Hunt5f6dbf82016-03-30 08:53:33 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Simon Hunt5f6dbf82016-03-30 08:53:33 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.ui.model.topo;
18
Simon Huntc0f20c12016-05-09 09:30:20 -070019import com.google.common.base.MoreObjects;
Simon Hunt23fb1352016-04-11 12:15:19 -070020import org.onosproject.net.Device;
Simon Hunt642bc452016-05-04 19:34:45 -070021import org.onosproject.net.DeviceId;
Simon Huntc0f20c12016-05-09 09:30:20 -070022import org.onosproject.net.region.RegionId;
Simon Hunt23fb1352016-04-11 12:15:19 -070023
Simon Hunt5f6dbf82016-03-30 08:53:33 -070024/**
25 * Represents a device.
26 */
27public class UiDevice extends UiNode {
Simon Hunt23fb1352016-04-11 12:15:19 -070028
Simon Huntc0f20c12016-05-09 09:30:20 -070029 private final UiTopology topology;
30 private final Device device;
31
32 private RegionId regionId;
33
34 /**
35 * Creates a new UI device.
36 *
37 * @param topology parent topology
38 * @param device backing device
39 */
40 public UiDevice(UiTopology topology, Device device) {
41 this.topology = topology;
42 this.device = device;
43 }
44
45 /**
46 * Sets the ID of the region to which this device belongs.
47 *
48 * @param regionId region identifier
49 */
50 public void setRegionId(RegionId regionId) {
51 this.regionId = regionId;
52 }
Simon Hunt23fb1352016-04-11 12:15:19 -070053
54 @Override
Simon Huntc0f20c12016-05-09 09:30:20 -070055 public String toString() {
56 return MoreObjects.toStringHelper(this)
57 .add("id", id())
58 .add("region", regionId)
59 .toString();
Simon Hunt23fb1352016-04-11 12:15:19 -070060 }
Simon Hunt642bc452016-05-04 19:34:45 -070061
62 /**
63 * Returns the identity of the device.
64 *
65 * @return device ID
66 */
67 public DeviceId id() {
68 return device.id();
69 }
70
71 @Override
72 public String idAsString() {
73 return id().toString();
74 }
Simon Huntc0f20c12016-05-09 09:30:20 -070075
76 /**
77 * Returns the device instance backing this UI device.
78 *
79 * @return the backing device instance
80 */
81 public Device backingDevice() {
82 return device;
83 }
84
85 /**
Simon Hunt58a0dd02016-05-17 11:54:23 -070086 * Returns the identifier of the region to which this device belongs.
87 * This will be null if the device does not belong to any region.
88 *
Simon Huntb0582492016-09-20 18:26:38 -070089 * @return region ID
Simon Hunt58a0dd02016-05-17 11:54:23 -070090 */
91 public RegionId regionId() {
92 return regionId;
93 }
94
95 /**
Simon Huntc0f20c12016-05-09 09:30:20 -070096 * Returns the UI region to which this device belongs.
97 *
98 * @return the UI region
99 */
100 public UiRegion uiRegion() {
101 return topology.findRegion(regionId);
102 }
Simon Huntd5b96732016-07-08 13:22:27 -0700103
104 /**
105 * Returns a string representation of the type of the backing device.
106 *
107 * @return the device type
108 */
109 public String type() {
110 return device.type().toString().toLowerCase();
111 }
Simon Hunt5f6dbf82016-03-30 08:53:33 -0700112}