Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 1 | /* |
| 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 Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Simon Hunt | 191c84a | 2015-08-21 08:24:48 -0700 | [diff] [blame] | 17 | package org.onosproject.ui.topo; |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 18 | |
| 19 | import org.onosproject.net.Link; |
| 20 | import org.onosproject.net.LinkKey; |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 21 | |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 22 | import static com.google.common.base.Preconditions.checkNotNull; |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 23 | |
| 24 | /** |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 25 | * Representation of a link and its inverse, as a partial implementation. |
| 26 | * <p> |
| 27 | * Subclasses will decide how to generate the link highlighting (coloring |
| 28 | * and labeling) for the topology view. |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 29 | */ |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 30 | public abstract class BiLink { |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 31 | |
| 32 | private final LinkKey key; |
| 33 | private final Link one; |
| 34 | private Link two; |
| 35 | |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 36 | /** |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 37 | * Constructs a bi-link for the given key and initial link. It is expected |
| 38 | * that the caller will have used {@link TopoUtils#canonicalLinkKey(Link)} |
| 39 | * to generate the key. |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 40 | * |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 41 | * @param key canonical key for this bi-link |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 42 | * @param link first link |
| 43 | */ |
| 44 | public BiLink(LinkKey key, Link link) { |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 45 | this.key = checkNotNull(key); |
| 46 | this.one = checkNotNull(link); |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /** |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 50 | * Sets the second link for this bi-link. |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 51 | * |
| 52 | * @param link second link |
| 53 | */ |
| 54 | public void setOther(Link link) { |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 55 | this.two = checkNotNull(link); |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /** |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 59 | * Returns the link identifier in the form expected on the Topology View |
| 60 | * in the web client. |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 61 | * |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 62 | * @return link identifier |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 63 | */ |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 64 | public String linkId() { |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 65 | return TopoUtils.compactLinkString(one); |
| 66 | } |
| 67 | |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 68 | /** |
| 69 | * Returns the key for this bi-link. |
| 70 | * |
| 71 | * @return the key |
| 72 | */ |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 73 | public LinkKey key() { |
| 74 | return key; |
| 75 | } |
| 76 | |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 77 | /** |
| 78 | * Returns the first link in this bi-link. |
| 79 | * |
| 80 | * @return the first link |
| 81 | */ |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 82 | public Link one() { |
| 83 | return one; |
| 84 | } |
| 85 | |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 86 | /** |
| 87 | * Returns the second link in this bi-link. |
| 88 | * |
| 89 | * @return the second link |
| 90 | */ |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 91 | public Link two() { |
| 92 | return two; |
| 93 | } |
| 94 | |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 95 | /** |
| 96 | * Returns the link highlighting to use, based on this bi-link's current |
| 97 | * state. |
| 98 | * |
| 99 | * @param type optional highlighting type parameter |
| 100 | * @return link highlighting model |
| 101 | */ |
| 102 | public abstract LinkHighlight highlight(Enum<?> type); |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 103 | } |