blob: be59c26bf8e7be29dfbd2fbc746559259e6a6430 [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.
15 *
16 */
17
18package org.onosproject.ui.topo;
19
Simon Hunt94f7dae2015-08-26 17:40:59 -070020import java.util.Collection;
Simon Hunta17fa672015-08-19 18:42:22 -070021import java.util.Collections;
Simon Hunt94f7dae2015-08-26 17:40:59 -070022import java.util.HashMap;
23import java.util.Map;
Simon Hunta17fa672015-08-19 18:42:22 -070024
Simon Hunt743a8492015-08-25 16:18:19 -070025import static com.google.common.base.Preconditions.checkNotNull;
26
Simon Hunta17fa672015-08-19 18:42:22 -070027/**
28 * Encapsulates highlights to be applied to the topology view, such as
29 * highlighting links, displaying link labels, perhaps even decorating
30 * nodes with badges, etc.
31 */
32public class Highlights {
33
Simon Hunt743a8492015-08-25 16:18:19 -070034 private static final String EMPTY = "";
35 private static final String MIN = "min";
36 private static final String MAX = "max";
37
38 /**
39 * A notion of amount.
40 */
41 public enum Amount {
42 ZERO(EMPTY),
43 MINIMALLY(MIN),
44 MAXIMALLY(MAX);
45
46 private final String s;
47 Amount(String str) {
48 s = str;
49 }
50
51 @Override
52 public String toString() {
53 return s;
54 }
55 }
56
Simon Hunt94f7dae2015-08-26 17:40:59 -070057 private final Map<String, DeviceHighlight> devices = new HashMap<>();
58 private final Map<String, HostHighlight> hosts = new HashMap<>();
59 private final Map<String, LinkHighlight> links = new HashMap<>();
Simon Hunta17fa672015-08-19 18:42:22 -070060
Simon Hunt743a8492015-08-25 16:18:19 -070061 private Amount subdueLevel = Amount.ZERO;
Simon Hunta17fa672015-08-19 18:42:22 -070062
Simon Hunt743a8492015-08-25 16:18:19 -070063
64 /**
65 * Adds highlighting information for a device.
66 *
67 * @param dh device highlight
68 * @return self, for chaining
69 */
70 public Highlights add(DeviceHighlight dh) {
Simon Hunt94f7dae2015-08-26 17:40:59 -070071 devices.put(dh.elementId(), dh);
Simon Hunta17fa672015-08-19 18:42:22 -070072 return this;
73 }
74
Simon Hunt743a8492015-08-25 16:18:19 -070075 /**
76 * Adds highlighting information for a host.
77 *
78 * @param hh host highlight
79 * @return self, for chaining
80 */
81 public Highlights add(HostHighlight hh) {
Simon Hunt94f7dae2015-08-26 17:40:59 -070082 hosts.put(hh.elementId(), hh);
Simon Hunta17fa672015-08-19 18:42:22 -070083 return this;
84 }
85
Simon Hunt743a8492015-08-25 16:18:19 -070086 /**
87 * Adds highlighting information for a link.
88 *
89 * @param lh link highlight
90 * @return self, for chaining
91 */
Simon Hunta17fa672015-08-19 18:42:22 -070092 public Highlights add(LinkHighlight lh) {
Simon Hunt94f7dae2015-08-26 17:40:59 -070093 links.put(lh.elementId(), lh);
Simon Hunta17fa672015-08-19 18:42:22 -070094 return this;
95 }
96
Simon Hunt743a8492015-08-25 16:18:19 -070097 /**
98 * Marks the amount by which all other elements (devices, hosts, links)
99 * not explicitly referenced here will be "subdued" visually.
100 *
101 * @param amount amount to subdue other elements
102 * @return self, for chaining
103 */
104 public Highlights subdueAllElse(Amount amount) {
105 subdueLevel = checkNotNull(amount);
106 return this;
107 }
Simon Hunta17fa672015-08-19 18:42:22 -0700108
Simon Hunt743a8492015-08-25 16:18:19 -0700109 /**
Simon Hunt94f7dae2015-08-26 17:40:59 -0700110 * Returns the collection of device highlights.
Simon Hunt743a8492015-08-25 16:18:19 -0700111 *
112 * @return device highlights
113 */
Simon Hunt94f7dae2015-08-26 17:40:59 -0700114 public Collection<DeviceHighlight> devices() {
115 return Collections.unmodifiableCollection(devices.values());
Simon Hunta17fa672015-08-19 18:42:22 -0700116 }
117
Simon Hunt743a8492015-08-25 16:18:19 -0700118 /**
Simon Hunt94f7dae2015-08-26 17:40:59 -0700119 * Returns the collection of host highlights.
Simon Hunt743a8492015-08-25 16:18:19 -0700120 *
121 * @return host highlights
122 */
Simon Hunt94f7dae2015-08-26 17:40:59 -0700123 public Collection<HostHighlight> hosts() {
124 return Collections.unmodifiableCollection(hosts.values());
Simon Hunta17fa672015-08-19 18:42:22 -0700125 }
126
Simon Hunt743a8492015-08-25 16:18:19 -0700127 /**
Simon Hunt94f7dae2015-08-26 17:40:59 -0700128 * Returns the collection of link highlights.
Simon Hunt743a8492015-08-25 16:18:19 -0700129 *
130 * @return link highlights
131 */
Simon Hunt94f7dae2015-08-26 17:40:59 -0700132 public Collection<LinkHighlight> links() {
133 return Collections.unmodifiableCollection(links.values());
Simon Hunta17fa672015-08-19 18:42:22 -0700134 }
Simon Hunt743a8492015-08-25 16:18:19 -0700135
136 /**
137 * Returns the amount by which all other elements not explicitly
138 * referenced here should be "subdued".
139 *
140 * @return amount to subdue other elements
141 */
142 public Amount subdueLevel() {
143 return subdueLevel;
144 }
Simon Hunt94f7dae2015-08-26 17:40:59 -0700145
146 /**
147 * Returns the node highlight (device or host) for the given element
148 * identifier, or null if no match.
149 *
150 * @param id element identifier
151 * @return corresponding node highlight
152 */
153 public NodeHighlight getNode(String id) {
154 NodeHighlight nh = devices.get(id);
155 return nh != null ? nh : hosts.get(id);
156 }
157
158 /**
159 * Returns the device highlight for the given device identifier,
160 * or null if no match.
161 *
162 * @param id device identifier
163 * @return corresponding device highlight
164 */
165 public DeviceHighlight getDevice(String id) {
166 return devices.get(id);
167 }
168
169 /**
170 * Returns the host highlight for the given host identifier,
171 * or null if no match.
172 *
173 * @param id host identifier
174 * @return corresponding host highlight
175 */
176 public HostHighlight getHost(String id) {
177 return hosts.get(id);
178 }
179
180 /**
181 * Returns the link highlight for the given link identifier,
182 * or null if no match.
183 *
184 * @param id link identifier
185 * @return corresponding link highlight
186 */
187 public LinkHighlight getLink(String id) {
188 return links.get(id);
189 }
Simon Hunta17fa672015-08-19 18:42:22 -0700190}