blob: 12d3b629dbe16a3a30443b943f4fc77cd4442484 [file] [log] [blame]
Simon Hunta17fa672015-08-19 18:42:22 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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.
Simon Hunta17fa672015-08-19 18:42:22 -070015 */
16
17package org.onosproject.ui.topo;
18
Simon Hunt94f7dae2015-08-26 17:40:59 -070019import java.util.Collection;
Simon Hunta17fa672015-08-19 18:42:22 -070020import java.util.Collections;
Simon Hunt94f7dae2015-08-26 17:40:59 -070021import java.util.HashMap;
22import java.util.Map;
Simon Hunta17fa672015-08-19 18:42:22 -070023
Simon Hunt743a8492015-08-25 16:18:19 -070024import static com.google.common.base.Preconditions.checkNotNull;
25
Simon Hunta17fa672015-08-19 18:42:22 -070026/**
27 * Encapsulates highlights to be applied to the topology view, such as
28 * highlighting links, displaying link labels, perhaps even decorating
29 * nodes with badges, etc.
30 */
31public class Highlights {
32
Simon Hunt743a8492015-08-25 16:18:19 -070033 private static final String EMPTY = "";
34 private static final String MIN = "min";
35 private static final String MAX = "max";
36
37 /**
38 * A notion of amount.
39 */
40 public enum Amount {
41 ZERO(EMPTY),
42 MINIMALLY(MIN),
43 MAXIMALLY(MAX);
44
45 private final String s;
46 Amount(String str) {
47 s = str;
48 }
49
50 @Override
51 public String toString() {
52 return s;
53 }
54 }
55
Simon Hunt94f7dae2015-08-26 17:40:59 -070056 private final Map<String, DeviceHighlight> devices = new HashMap<>();
57 private final Map<String, HostHighlight> hosts = new HashMap<>();
58 private final Map<String, LinkHighlight> links = new HashMap<>();
Simon Hunta17fa672015-08-19 18:42:22 -070059
Simon Hunt743a8492015-08-25 16:18:19 -070060 private Amount subdueLevel = Amount.ZERO;
Simon Hunta17fa672015-08-19 18:42:22 -070061
Simon Hunt743a8492015-08-25 16:18:19 -070062
63 /**
64 * Adds highlighting information for a device.
65 *
66 * @param dh device highlight
67 * @return self, for chaining
68 */
69 public Highlights add(DeviceHighlight dh) {
Simon Hunt94f7dae2015-08-26 17:40:59 -070070 devices.put(dh.elementId(), dh);
Simon Hunta17fa672015-08-19 18:42:22 -070071 return this;
72 }
73
Simon Hunt743a8492015-08-25 16:18:19 -070074 /**
75 * Adds highlighting information for a host.
76 *
77 * @param hh host highlight
78 * @return self, for chaining
79 */
80 public Highlights add(HostHighlight hh) {
Simon Hunt94f7dae2015-08-26 17:40:59 -070081 hosts.put(hh.elementId(), hh);
Simon Hunta17fa672015-08-19 18:42:22 -070082 return this;
83 }
84
Simon Hunt743a8492015-08-25 16:18:19 -070085 /**
86 * Adds highlighting information for a link.
87 *
88 * @param lh link highlight
89 * @return self, for chaining
90 */
Simon Hunta17fa672015-08-19 18:42:22 -070091 public Highlights add(LinkHighlight lh) {
Simon Hunt94f7dae2015-08-26 17:40:59 -070092 links.put(lh.elementId(), lh);
Simon Hunta17fa672015-08-19 18:42:22 -070093 return this;
94 }
95
Simon Hunt743a8492015-08-25 16:18:19 -070096 /**
97 * Marks the amount by which all other elements (devices, hosts, links)
98 * not explicitly referenced here will be "subdued" visually.
99 *
100 * @param amount amount to subdue other elements
101 * @return self, for chaining
102 */
103 public Highlights subdueAllElse(Amount amount) {
104 subdueLevel = checkNotNull(amount);
105 return this;
106 }
Simon Hunta17fa672015-08-19 18:42:22 -0700107
Simon Hunt743a8492015-08-25 16:18:19 -0700108 /**
Simon Hunt94f7dae2015-08-26 17:40:59 -0700109 * Returns the collection of device highlights.
Simon Hunt743a8492015-08-25 16:18:19 -0700110 *
111 * @return device highlights
112 */
Simon Hunt94f7dae2015-08-26 17:40:59 -0700113 public Collection<DeviceHighlight> devices() {
114 return Collections.unmodifiableCollection(devices.values());
Simon Hunta17fa672015-08-19 18:42:22 -0700115 }
116
Simon Hunt743a8492015-08-25 16:18:19 -0700117 /**
Simon Hunt94f7dae2015-08-26 17:40:59 -0700118 * Returns the collection of host highlights.
Simon Hunt743a8492015-08-25 16:18:19 -0700119 *
120 * @return host highlights
121 */
Simon Hunt94f7dae2015-08-26 17:40:59 -0700122 public Collection<HostHighlight> hosts() {
123 return Collections.unmodifiableCollection(hosts.values());
Simon Hunta17fa672015-08-19 18:42:22 -0700124 }
125
Simon Hunt743a8492015-08-25 16:18:19 -0700126 /**
Simon Hunt94f7dae2015-08-26 17:40:59 -0700127 * Returns the collection of link highlights.
Simon Hunt743a8492015-08-25 16:18:19 -0700128 *
129 * @return link highlights
130 */
Simon Hunt94f7dae2015-08-26 17:40:59 -0700131 public Collection<LinkHighlight> links() {
132 return Collections.unmodifiableCollection(links.values());
Simon Hunta17fa672015-08-19 18:42:22 -0700133 }
Simon Hunt743a8492015-08-25 16:18:19 -0700134
135 /**
136 * Returns the amount by which all other elements not explicitly
137 * referenced here should be "subdued".
138 *
139 * @return amount to subdue other elements
140 */
141 public Amount subdueLevel() {
142 return subdueLevel;
143 }
Simon Hunt94f7dae2015-08-26 17:40:59 -0700144
145 /**
146 * Returns the node highlight (device or host) for the given element
147 * identifier, or null if no match.
148 *
149 * @param id element identifier
150 * @return corresponding node highlight
151 */
152 public NodeHighlight getNode(String id) {
153 NodeHighlight nh = devices.get(id);
154 return nh != null ? nh : hosts.get(id);
155 }
156
157 /**
158 * Returns the device highlight for the given device identifier,
159 * or null if no match.
160 *
161 * @param id device identifier
162 * @return corresponding device highlight
163 */
164 public DeviceHighlight getDevice(String id) {
165 return devices.get(id);
166 }
167
168 /**
169 * Returns the host highlight for the given host identifier,
170 * or null if no match.
171 *
172 * @param id host identifier
173 * @return corresponding host highlight
174 */
175 public HostHighlight getHost(String id) {
176 return hosts.get(id);
177 }
178
179 /**
180 * Returns the link highlight for the given link identifier,
181 * or null if no match.
182 *
183 * @param id link identifier
184 * @return corresponding link highlight
185 */
186 public LinkHighlight getLink(String id) {
187 return links.get(id);
188 }
Simon Hunta17fa672015-08-19 18:42:22 -0700189}